H5Grove
h5grove is a Python library providing core utilities to serve HDF5 file contents over a REST API. It allows users to browse and extract data from HDF5 files via HTTP requests, with support for various web frameworks like FastAPI, Flask, and Tornado. The library is actively maintained, with a current version of 4.0.0, and releases new versions regularly, often including breaking changes to improve the API or underlying structure.
Common errors
-
ModuleNotFoundError: No module named 'h5grove'
cause The h5grove package has not been installed in your current Python environment.fixRun `pip install h5grove` to install the core library, or `pip install h5grove[fastapi]` (or other backend) for full functionality. -
404 Not Found when accessing /attr/ or /data/
cause From v3.0.0 onwards, h5grove endpoints no longer use trailing slashes.fixUpdate your API client requests to remove trailing slashes from all h5grove endpoints (e.g., change `/attr/` to `/attr`, `/data/` to `/data`). -
TypeError: 'dict' object is not subscriptable when parsing compound dataset metadata for 'members'
cause You are using h5grove v4.0.0+ but your client expects the 'members' key for compound dataset metadata to be an object, not an array.fixAdjust your client-side code to parse the `members` key as an array rather than an object when requesting `/meta` for compound datasets from a v4.0.0+ h5grove server. -
RuntimeError: Python version 3.9 is not supported by h5grove version 3.0.0. Minimal version is 3.10.
cause Your Python environment does not meet the minimum version requirement for the installed h5grove package.fixUpgrade your Python environment to version 3.10 or newer. Alternatively, downgrade h5grove to a version compatible with your current Python version (e.g., `pip install 'h5grove<3.0.0'` for Python 3.8/3.9 or `h5grove<2.0.0` for Python 3.7).
Warnings
- breaking In v4.0.0, the `/meta` endpoint response schema for compound datasets changed. The `members` key is now an array instead of an object to ensure correct field ordering.
- breaking In v3.0.0, trailing slashes were removed from all endpoints (e.g., `/attr/` is now `/attr`).
- breaking Starting from v3.0.0, Python 3.10 or newer is required.
- breaking In v2.0.0, the `type` field in all entities' metadata was renamed to `kind`, and the `dtype` field for dataset/attribute metadata was replaced with a richer `type` object (e.g., `{dtype: '<f8'}` became `{type: {'class': 1, 'dtype': '<f8', 'size': 8, 'order': 0}}`).
Install
-
pip install h5grove -
pip install h5grove[fastapi] uvicorn
Imports
- create_app
from h5grove.backends.fastapi import create_app
from h5grove.app import create_app
- H5GroveConfig
from h5grove.config import H5GroveConfig
Quickstart
import os
from fastapi import FastAPI
from h5grove.app import create_app
from h5grove.config import H5GroveConfig
# Configure the base directory for HDF5 files.
# Replace with a path where your .h5 files are located.
# For a runnable example, ensure a '.h5' file exists here.
H5GroveConfig.hdf5_dir = os.environ.get('H5GROVE_HDF5_DIR', '.')
app = FastAPI()
app.mount("/h5grove", create_app())
# To run this app (requires uvicorn):
# 1. pip install h5grove[fastapi] uvicorn
# 2. Save this code as 'main.py'
# 3. Run from terminal: uvicorn main:app --reload --port 8000
# 4. Access API: http://127.0.0.1:8000/h5grove/