Skip to main content

FileLoader HDF5

h5py-backed HDF5 file loader for the vcti-fileloader framework

Overview

vcti-fileloader-hdf5 is the HDF5 plugin for the vcti-fileloader framework. It implements the Loader protocol: populate(handle, tree, parent) walks the HDF5 hierarchy once via h5py.File.visit() and attaches the file's groups and datasets as a subtree under parent in any LockableTree. The returned subtree is structure-locked and payload-locked.

Groups become DataNode payloads; datasets become LazyDataNode payloads whose shape and dtype are filled in up front, so a caller can browse the file without reading any array. A dataset with a null dataspace (a dtype and no values) becomes a TypeOnlyDataNode. Every node's file_attributes is the HDF5 object's own obj.attrs, verbatim: the loader adds no keys of its own. Anything else a caller wants on the nodes (the file path, tags, derived metadata) is written from the before_lock hook on populate.

Installation

pip install "vcti-fileloader-hdf5>=6.0.0"

In pyproject.toml dependencies

dependencies = [
    "vcti-fileloader-hdf5>=6.0.0",
]

Quick Start

from pathlib import Path

import h5py
import numpy as np
from vcti.fileloader.core import DataNode, LazyDataNode, materialise_subtree, prepare_loader
from vcti.fileloader.hdf5 import H5pyLoader
from vcti.tree.core import DictTree, descendants

# A small file to load.
path = Path("data.h5")
with h5py.File(path, "w") as h5:
    results = h5.create_group("results")
    stress = results.create_dataset("stress", data=np.array([1.0, 2.0, 3.0]))
    stress.attrs["units"] = "MPa"
    h5.create_dataset("ids", data=np.array([10, 20, 30]))

loader = H5pyLoader()
prepare_loader(loader)  # once, before first use; raises ValidationError / SetupError
tree: DictTree[DataNode] = DictTree(DataNode())

handle = loader.load(path)
try:
    subtree_root = loader.populate(handle, tree, tree.root_handle)

    # Datasets are lazy: name, shape, dtype and attributes without a read.
    for node_handle in descendants(tree, subtree_root):
        node = tree.payload(node_handle)
        if isinstance(node, LazyDataNode):
            print(node.name, node.shape, node.dtype, dict(node.file_attributes))
            # ids (3,) int64 {}
            # stress (3,) float64 {'units': 'MPa'}

    # Read every dataset, so the tree stays usable after the file closes.
    materialise_subtree(tree, subtree_root)
finally:
    loader.unload(handle)

Eager loading

lazy=False reads every dataset during populate, so the handle can close straight away. loader.open() loads and unloads around the block:

tree = DictTree(DataNode())
with loader.open(path) as handle:
    subtree_root = loader.populate(handle, tree, tree.root_handle, lazy=False)

With a before_lock hook

The hook runs after the subtree is built and before it is locked. A typical use is to attach the file path, which the loader does not do:

def stamp_file_path(tree, root):
    tree.payload(root).enricher_attributes["file_path"] = str(path)

tree = DictTree(DataNode())
with loader.open(path) as handle:
    root = loader.populate(
        handle, tree, tree.root_handle, lazy=False, before_lock=stamp_file_path
    )

print(tree.payload(root).attributes["file_path"])   # data.h5

Through a registry

from vcti.fileloader.core import LoaderRegistry
from vcti.fileloader.hdf5 import get_loader_descriptor

registry = LoaderRegistry()
registry.register(get_loader_descriptor())
loader = registry.get("hdf5-h5py-loader").loader

Key API

H5pyLoader

Method Description
load(path, **options) Open the HDF5 file read-only and return an h5py.File handle. Options go to h5py.File; a mode other than 'r' raises ValueError
open(path, **options) Context manager — load and auto-unload
populate(handle, tree, parent, *, before_lock=None, lazy=True, **options) Attach the file's content as a locked subtree; return the subtree root handle
unload(handle) Close the file handle (idempotent)
can_load(path) Check extension (.h5, .hdf5)

Helpers

Description
get_loader_descriptor() Create a LoaderDescriptor for a LoaderRegistry
H5pyValidator Verify that h5py is importable
H5pySetup No-op setup

Lazy Datasets and the File Handle

With lazy=True (the default), each dataset's data is None until its .load() is called, and that call reads from handle. Once loader.unload(handle) has run, .load() on a node that was never read raises LazyLoadError. Three ways to stay clear of that:

  1. Keep the handle open for as long as the tree is in use.
  2. Call materialise_subtree(tree, subtree_root) (from vcti.fileloader.core) before unloading, as the Quick Start does.
  3. Pass lazy=False to populate.

Error Handling

from vcti.fileloader.core import (
    LazyLoadError,
    LoadError,
    TreeAttachmentError,
    UnloadError,
    UnsupportedFormatError,
)

try:
    with loader.open(path) as handle:
        subtree_root = loader.populate(handle, tree, tree.root_handle)
except FileNotFoundError:
    ...
except UnsupportedFormatError:
    # the file has no HDF5 signature
    ...
except LazyLoadError:
    # a lazy dataset was read after its file handle was closed
    ...
except LoadError:
    # the file could not be opened (permissions, locking, I/O, or a
    # truncated or corrupt HDF5 file), or reading it failed during populate
    ...
except UnloadError:
    # closing the file failed
    ...
except TreeAttachmentError:
    # parent is missing, deleted, or structure-locked in `tree`
    ...
except ValueError:
    # populate() was called on a closed handle, or load() was given a
    # mode other than 'r'
    ...

If populate fails partway, the partial subtree is removed before the exception propagates — callers never see a half-built subtree. A failure to read the file surfaces as LoadError with the original exception on __cause__; an exception raised by before_lock propagates unchanged.


Dependencies

  • h5py (>=3.0)
  • numpy (>=1.24)
  • vcti-fileloader (>=7.1.0, <8) — Loader protocol, SubtreeBuilder, DataNode, LazyDataNode, TypeOnlyDataNode, materialise_subtree (import from vcti.fileloader.core)
  • vcti-tree (>=3.0.0, <4) — LockableTree protocol

Documentation

If you want to… Read
Get started using the package Quick Start above
Understand what the loader writes onto each node, how null-dataspace datasets and links are handled, failure semantics, the handle lifetime, and what the loader leaves out docs/design.md

Metadata

Release files for vcti-fileloader-hdf5 6.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vcti-fileloader-hdf5 6.0.0
File Size Uploaded Provenance Actions
vcti_fileloader_hdf5-6.0.0.tar.gz 25.3 kB With provenance Details for vcti_fileloader_hdf5-6.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vcti-fileloader-hdf5 6.0.0
File Interpreter ABI Platform Actions
vcti_fileloader_hdf5-6.0.0-py3-none-any.whl Python 3 none any Details for vcti_fileloader_hdf5-6.0.0-py3-none-any.whl

Total release size: 35.6 kB

Release files / vcti_fileloader_hdf5-6.0.0.tar.gz

Download URL vcti_fileloader_hdf5-6.0.0.tar.gz
Size 25.3 kB
Tags Source
SHA-256 checksum
How to use checksums
862eb65eb0ac820c8891c5d90318635a4b6bdbcfd871d2c0aa6b5693052d0336
BLAKE2b-256 checksum
How to use checksums
b2c36e860be53dd3b3ea29d79696c33763959aa53e20265a5c448e050db0a621
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / vcti_fileloader_hdf5-6.0.0-py3-none-any.whl

Download URL vcti_fileloader_hdf5-6.0.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c0a5318e35f0fc2b7bf3806728185883e39585196172136ac8f7779b33d93c2
BLAKE2b-256 checksum
How to use checksums
1d99461df6c14e468cd32a1625fa749bfa6879d84b84095105c6d6ca4e800e74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for vcti-fileloader-hdf5 6.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for vcti_fileloader_hdf5-6.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page