Skip to content

HDF5 endpoints

Two endpoints for HDF5 files (.h5, .hdf5).


POST /h5/inspect

Inspect an uploaded HDF5 file — returns the list of all datasets with their shapes and dtypes.

Request: multipart/form-data

Field Type Description
file file A .h5 or .hdf5 file

Response: application/json

{
  "filename": "experiment.h5",
  "format": "hdf5",
  "datasets": [
    {
      "path": "data/subject01/run1/bold",
      "shape": [64, 64, 30, 200],
      "dtype": "float32"
    },
    {
      "path": "data/subject02/run1/bold",
      "shape": [64, 64, 30, 198],
      "dtype": "float32"
    }
  ]
}

Example:

curl -X POST http://127.0.0.1:8000/h5/inspect \
  -F "file=@experiment.h5"
import httpx

with open("experiment.h5", "rb") as f:
    response = httpx.post(
        "http://127.0.0.1:8000/h5/inspect",
        files={"file": f},
    )

for ds in response.json()["datasets"]:
    print(ds["path"], ds["shape"])

POST /h5/slice

Generate a PNG slice preview from a dataset inside an uploaded HDF5 file.

Request: multipart/form-data + query parameters

Field Type Description
file file A .h5 or .hdf5 file
Query param Type Required Description
dataset_path string Yes Path to the dataset inside the file, e.g. data/subject01/run1/bold
axis integer Yes Axis to slice along (0, 1, or 2)
slice_index integer No Slice index; defaults to centre

Response: image/png

Example:

curl -X POST \
  "http://127.0.0.1:8000/h5/slice?dataset_path=data/subject01/run1/bold&axis=2&slice_index=10" \
  -F "file=@experiment.h5" \
  --output slice.png
import httpx

with open("experiment.h5", "rb") as f:
    response = httpx.post(
        "http://127.0.0.1:8000/h5/slice",
        params={
            "dataset_path": "data/subject01/run1/bold",
            "axis": 2,
            "slice_index": 10,
        },
        files={"file": f},
    )

with open("slice.png", "wb") as out:
    out.write(response.content)