API Reference
h5pydantic
Modelling
For the most part, h5pydantic attempts to leave modelling to pydantic, there are, of course, areas where the interaction is not seamless.
Optional
It is possible to type a field (which could be a Group, a Dataset, an attribute, or a list) as typing.Optional. pydantic requires that that this be done by assigning None to the field. I strongly suggest using typing.Optional as well, for readability.
At this point, only typing.Optional Groups and Attributes are supported. An Optional list[] does not make much sense, just leave the list empty. Optional Datasets should be supported in future.
Lists
h5pydantic will take a list[] type to mean a zero counted group. An empty list is the only supported default value.
Instances
- class h5pydantic.H5Group
A
pydantic.BaseModelrepresenting ah5py.Group.This should be extended to model all your groups.
- close()
Close the underlying HDF5 file.
- dump(filename, partial=False)
Dump the H5Group object tree into a file.
- Parameters:
filename (Path) – Path to dump the HDF5Group object tree to.
partial – If False, will raise an error if any H5Dataset is not written to.
Returns: None
- dumper(filename, partial=False)
Context manager to dump the H5Group object tree into a file.
Inside the context manager, Datasets can be assigned to, which will write that data to the file.
At the cleanup stage, if partial is False, this context manager will ensure all Datasets have been written to.
- Parameters:
filename (Path) – Path to dump the HDF5Group object tree to.
partial – If False, will raise an error if any H5Dataset is not written to.
Returns: None
- classmethod load(filename)
Load a file into a tree of H5Group models.
Can be used as context manager, which allows dataset access in the body of the context manager, and will
close()thefilenameat the end of the context block.- Parameters:
filename (Path) – Path of HDF5 to load.
- Returns:
The parsed H5Group model.
- Return type:
Self
Types
- class h5pydantic.types.H5Type
All subclasses must be able to save all their possible values to HDF5 without error.