bagofholding.h5.context module

class bagofholding.h5.context.HasH5FileContext[source]

Bases: object

A mixin class for context management with an h5py.File object.

Supports addressing a group inside an HDF5 file by extending the filepath past a recognized file extension (e.g., folder/file.h5/group/sub refers to the group /group/sub inside folder/file.h5). This allows storing multiple bags in a single HDF5 file. The set of recognized extensions is controlled by file_extensions.

close() None[source]
property file: Group

The bag’s working root group.

When the bag’s filepath has no interior group component, this is the HDF5 file’s root group (i.e., the h5py.File itself, which is an h5py.Group). When the bag is rooted at an interior path, this is the corresponding sub-group.

file_extensions: ClassVar[tuple[str, ...]] = ('.h5', '.hdf5')
filepath: Path
property h5_file_path: Path

The filesystem path to the underlying HDF5 file.

property h5_group_path: str

The interior group path inside the HDF5 file.

Returns "/" when the bag is rooted at the file root.

property is_subpath: bool

Whether the filepath points inside an HDF5 file rather than at its root.

libver_str: ClassVar[str] = 'latest'
static maybe_decode(attr: str | bytes) str[source]
open(mode: Literal['r', 'r+', 'w', 'w-', 'x', 'a']) Group[source]