# obspy.core.event.base._event_type_class_factory

`_event_type_class_factory`(class_name, class_attributes=, []class_contains=[])

  Class factory to unify the creation of all the types needed for the event handling in ObsPy.

  The types oftentimes share attributes and setting them manually every time is cumbersome, error-prone and hard to do consistently. The classes created with this method will inherit from `AttribDict`.

  Usage to create a new class type:

  The created class will assure that any given (key, type) attribute pairs will always be of the given type and will attempt to convert any given value to the correct type and raise an error otherwise. This happens to values given during initialization as well as values set when the object has already been created. A useful type is Enum if you want to restrict the acceptable values.

      >>> from obspy.core.util import Enum
      >>> MyEnum = Enum(["a", "b", "c"])
      >>> class_attributes = [                 ("resource_id", ResourceIdentifier),                 ("creation_info", CreationInfo),                 ("some_letters", MyEnum),                 ("some_error_quantity", float, ATTRIBUTE_HAS_ERRORS),                 ("description", str)]

  Furthermore the class can contain lists of other objects. There is not much to it so far. Giving the name of the created class is mandatory.

      >>> class_contains = ["comments"]
      >>> TestEventClass = _event_type_class_factory("TestEventClass",                 class_attributes=class_attributes,                 class_contains=class_contains)
      >>> assert(TestEventClass.__name__ == "TestEventClass")

  Now the new class type can be used.

      >>> test_event = TestEventClass(resource_id="event/123456",                 creation_info={"author": "obspy.org", "version": "0.1"})

  All given arguments will be converted to the right type upon setting them.

      >>> test_event.resource_id
      ResourceIdentifier(id="event/123456")
      >>> print(test_event.creation_info)
      CreationInfo(author='obspy.org', version='0.1')

  All others will be set to None.

      >>> assert(test_event.description is None)
      >>> assert(test_event.some_letters is None)

  If the resource_id attribute of the created class type is set, the object the ResourceIdentifier refers to will be the class instance.

      >>> assert(id(test_event) ==             id(test_event.resource_id.get_referred_object()))

  They can be set later and will be converted to the appropriate type if possible.

      >>> test_event.description = 1
      >>> assert(test_event.description == "1")

  Trying to set with an inappropriate value will raise an error.

      >>> test_event.some_letters = "d"
      Traceback (most recent call last):
          ...
      ValueError: Setting attribute "some_letters" failed. ...

  If you pass `ATTRIBUTE_HAS_ERRORS` as the third tuple item for the class_attributes, a error (type `QuantityError`) will be be created that will be named like the attribute with “_errors” appended.

      >>> assert(hasattr(test_event, "some_error_quantity_errors"))
      >>> test_event.some_error_quantity_errors
      QuantityError(...)

### Thank you!

We would like to thank our contributors, whose efforts make this software what it is. These people have helped by writing code and documentation, and by testing. They have created and maintained this product, its associated libraries and applications, our build tools and our web sites.

#### Contributors

- Ackerley, Nick
- Allgeyer, Sebastien
- Ammon, Charles J.
- Antunes, Emanuel
- Arnarsson, Ólafur St.
- Bank, Markus
- Barsch, Robert
- Behr, Yannik
- Bernardi, Fabrizio
- Bernauer, Felix
- Bes de Berc, Maxime
- Beyreuther, Moritz
- Boltz, Shawn
- Bonaimé, Sébastien
- Carothers, Lloyd
- Chamberlain, Calum
- Chambers, Derrick
- Chen, Zhao
- Clark, Adam
- Danecek, Peter
- Egdorf, Sven
- Engels, Fabian
- Ermert, Laura
- Eulenfeld, Tom

- Fabbri, Tommaso
- Falco, Nicholas
- Fee, Jeremy
- Grellier, Clément
- Grunberg, Marc
- Hammer, Conny
- Heimann, Sebastian
- Heiniger, Lukas
- Hope, Gaute
- Igel, Heiner
- Inza, Adolfo
- Isken, Marius
- Ketchum, David
- Koymans, Mathijs
- Kremers, Simon
- Kress, Victor
- Krieger, Lars
- Krischer, Lion
- Kula, Damian
- Käufl, Paul
- Köhler, Andreas
- Lecocq, Thomas
- Leeman, John
- Legovini, Paride

- Lesage, Philippe
- Li, Yulin
- Lomax, Anthony
- Lopes, Rui L.
- MacCarthy, Jonathan
- Maggi, Alessia
- Martin, Henri
- Medlin, Andrew
- Megies, Tobias
- Meschede, Matthias
- Michelini, Alberto
- Miller, Nathaniel C.
- Morgenstern, Bernhard
- Nof, Ran Novitsky
- Panning, Mark P.
- Parker, Tom
- Pestourie, Romain
- Rapagnani, Giovanni
- Reyes, Celso
- Ringler, Adam
- Rothenhäusler, Nicolas
- Russo, Emiliano
- Sales de Andrade, Elliott

- Satriano, Claudio
- Saul, Joachim
- Scheingraber, Chris
- Schneider, Simon
- Sippl, Christian
- Snoke, Arthur
- Stange, Stefan
- Stähler, Simon C.
- Sullivan, Benjamin
- Tian, Dongdong
- Trabant, Chad
- Trani, Luca
- Uieda, Leonardo
- Walker, Andrew
- Walther, Marcus
- Wassermann, Joachim
- Williams, Mark C.
- Winkelman, Andrew
- Zaccarelli, Riccardo
- Zad, Seyed Kasra Hosseini
- Zhu, Lijun
- van Driel, Martin
- van Wijk, Kasper

#### Funds

ObsPy was partially funded by the

- German Science Foundation (DFG) via grant DFG IG 16/9-1
- German Ministry for Education and Research (BMBF), GEOTECHNOLOGIEN grant 03G0646H.
- NERA project (Network of European Research Infrastructures for Earthquake Risk Assessment and Mitigation) under the European Community's Seventh Framework Programme (FP7/2007-2013) grant agreement n° 262330
- Leibniz Institute for Applied Geophysics (LIAG)
- VERCE EU-FP7 project (no. 283543)