bundle.hdf5 =========== .. py:module:: bundle.hdf5 Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/bundle/hdf5/store/index Classes ------- .. autoapisummary:: bundle.hdf5.Store Package Contents ---------------- .. py:class:: Store(path: pathlib.Path | str, mode: str = 'r') Simple HDF5 store for reading and writing datasets and attributes. Usage:: with Store("data.h5", mode="w") as store: store.write_dataset("group/data", np.array([1, 2, 3])) store.write_attrs("group", {"version": "1.0"}) with Store("data.h5", mode="r") as store: arr = store.read_dataset("group/data") attrs = store.read_attrs("group") .. py:attribute:: path .. py:attribute:: mode :value: 'r' .. py:property:: file :type: h5py.File .. py:method:: write_dataset(name: str, data: numpy.ndarray, **kwargs) Write or overwrite a dataset at the given path. .. py:method:: read_dataset(name: str) -> numpy.ndarray Read a dataset and return as numpy array. .. py:method:: write_attrs(path: str, attrs: dict | bundle.core.data.Data) Write attributes to a group or dataset (creating a group if path doesn't exist). Accepts a plain dict or a ``bundle.core.data.Data`` instance (uses ``model_dump()``). Only scalar and string values are stored; complex nested objects are JSON-serialised. .. py:method:: read_attrs(path: str) -> dict Read all attributes from a group or dataset. .. py:method:: read_attrs_as(path: str, model: type[D]) -> D Read attributes and construct a ``Data`` (or any Pydantic model) instance. Values that were JSON-serialised on write are automatically deserialised. .. py:method:: list_datasets(group_path: str = '/') -> list[str] List all dataset names under a group. .. py:method:: list_groups(group_path: str = '/') -> list[str] List all group names under a group. .. py:method:: has(name: str) -> bool Check if a dataset or group exists.