h5.formats.register_class

h5.formats.register_class(cls, doc=None, read_fun=None, hdf5_format=None)[source]

Register a Python class so it can be written to and read back from an archive.

The class is stored in the module-level registry keyed by its HDF5 format string, which defaults to cls._hdf5_format_ (if defined) or the class name.

Parameters:
clstype

The class to register.

docstr or dict, optional

Documentation for the format. Defaults to cls._hdf5_format_doc_ if defined, otherwise an empty dict.

read_funcallable, optional

Custom read function read_fun(group, key) used to reconstruct the object instead of cls.__factory_from_dict__.

hdf5_formatstr, optional

Explicit format string to register under. Defaults to cls._hdf5_format_ or cls.__name__.

Raises:
AssertionError

If a class is already registered under the same format string.

Examples

>>> from h5.formats import register_class
>>> register_class(GfImFreq, doc=doc_if_different_from_cls._hdf5_format_doc_)