Skip to content

types

Protocol roughly formalizing the overlap of h5py.File and IH5Record API.

We build the MetadorContainer interface assuming only these methods.

OpenMode module-attribute

OpenMode = Literal['r', 'r+', 'a', 'w', 'w-', 'x']

User open modes that can be passed during initialization.

H5NodeLike

Bases: Protocol

HDF5 Files, Groups and Datasets are all Nodes.

Source code in src/metador_core/util/types.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
@runtime_checkable
class H5NodeLike(Protocol):  # pragma: no cover
    """HDF5 Files, Groups and Datasets are all Nodes."""

    @property
    def name(self) -> str:
        """Absolute path of the node."""

    @property
    def attrs(self) -> MutableMapping:
        """Attached HDF5 attributes."""

    @property
    def parent(self) -> H5GroupLike:
        """Parent group."""

    @property
    def file(self) -> H5FileLike:
        """Original file-like object this node belongs to."""

name property

name: str

Absolute path of the node.

attrs property

attrs: MutableMapping

Attached HDF5 attributes.

parent property

parent: H5GroupLike

Parent group.

file property

file: H5FileLike

Original file-like object this node belongs to.

H5DatasetLike

Bases: H5NodeLike, Protocol

Datasets provide numpy-style indexing into data.

Metador containers use it for storing bytes, and for getting bytes out again using [()].

Source code in src/metador_core/util/types.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@runtime_checkable
class H5DatasetLike(H5NodeLike, Protocol):  # pragma: no cover
    """Datasets provide numpy-style indexing into data.

    Metador containers use it for storing bytes,
    and for getting bytes out again using [()].
    """

    def __getitem__(self, key: Any) -> Any:
        ...

    def __setitem__(self, key: Any, value) -> None:
        ...

    # needed to distinguish from other types:
    @property
    def ndim(self) -> int:
        """Numpy-style dimensionality."""

ndim property

ndim: int

Numpy-style dimensionality.

H5FileLike

Bases: H5GroupLike, Protocol

A HDF5 File acts like the root group and has some extra features.

Source code in src/metador_core/util/types.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
@runtime_checkable
class H5FileLike(H5GroupLike, Protocol):  # pragma: no cover
    """A HDF5 File acts like the root group and has some extra features."""

    @property
    def mode(self) -> Literal["r", "r+"]:
        """Return 'r' if container is immutable, otherwise 'r+'."""

    def close(self) -> None:
        ...

    # context manager (`with` notation)

    def __enter__(self) -> H5FileLike:
        ...

    def __exit__(self, ex_type, ex_value, ex_traceback) -> None:
        ...

mode property

mode: Literal['r', 'r+']

Return 'r' if container is immutable, otherwise 'r+'.