h5pydantic

Submodules

Package Contents

Classes

H5Dataset

A pydantic.BaseModel representing a h5py.Dataset.

H5DatasetConfig

All of the dataset configuration options.

H5Group

A pydantic.BaseModel representing a h5py.Group.

H5Int32

Signed Integers, using 32 bits.

H5Int64

Signed Integers, using 64 bits.

Attributes

__version__

h5pydantic.__version__
exception h5pydantic.H5PartialDump(datasets)

Bases: Exception

Common base class for all non-exit exceptions.

Initialize self. See help(type(self)) for accurate signature.

Parameters:

datasets (list) –

class h5pydantic.H5Dataset(data_=None, **kwargs)

Bases: _H5Base

A pydantic.BaseModel representing a h5py.Dataset.

Parameters:
  • data – allows the value of the DataSet to be initialised to a numpy.Array. If this keyword is used, the data cannot be subsequently modified using the array assignment syntax.

  • data_ (Optional[numpy.ndarray]) –

class Config
arbitrary_types_allowed = True
_h5config: H5DatasetConfig
_data: numpy.ndarray | None
_dset: h5py.Dataset | None
_modified: bool
classmethod __init_subclass__(**kwargs)
_dump_container(h5file, prefix)

Dump the group/dataset container to the h5file.

Parameters:
  • h5file (h5py.File) –

  • prefix (pathlib.PurePosixPath) –

Return type:

typing_extensions.Self

classmethod _load_intrinsic(h5file, prefix)
Parameters:
  • h5file (h5py.File) –

  • prefix (pathlib.PurePosixPath) –

Return type:

dict

__getitem__(key)

Allow array like access to the underlying h5py Dataset.

__setitem__(index, value)

Allow aray like assignment to the underlying h5py Datset.

class h5pydantic.H5DatasetConfig

Bases: pydantic.BaseModel

All of the dataset configuration options.

shape: tuple[pydantic.StrictInt, Ellipsis]
dtype: typing_extensions.Type[str] | typing_extensions.Type[float] | typing_extensions.Type[h5pydantic.types.H5Type] | typing_extensions.Type[enum.Enum]
class h5pydantic.H5Group

Bases: _H5Base

A pydantic.BaseModel representing a h5py.Group.

This should be extended to model all your groups.

class Config
validate_assignment = True
_h5file: h5py.File
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() the filename at the end of the context block.

Parameters:

filename (pathlib.Path) – Path of HDF5 to load.

Returns:

The parsed H5Group model.

Return type:

typing_extensions.Self

close()

Close the underlying HDF5 file.

__enter__()
__exit__(exc_type, exc_value, traceback)
_dump_container(h5file, prefix)

Dump the group/dataset container to the h5file.

Parameters:
  • h5file (h5py.File) –

  • prefix (pathlib.PurePosixPath) –

Return type:

h5py.Group

_datasets(parent)
Parameters:

parent (str) –

_check_all_modified()
dump(filename, partial=False)

Dump the H5Group object tree into a file.

Parameters:
  • filename (pathlib.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 (pathlib.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

class h5pydantic.H5Int32

Bases: int, H5Type

Signed Integers, using 32 bits.

Initialize self. See help(type(self)) for accurate signature.

ge
le
h5pyid
numpy
class h5pydantic.H5Int64

Bases: int, H5Type

Signed Integers, using 64 bits.

Initialize self. See help(type(self)) for accurate signature.

ge
le
h5pyid
numpy