h5grove reference

content module

Create a content object

h5grove provides the create_content that is a h5py wrapper to get a desired h5py entity. The function handles support link resolution and dataset decompression using hdf5plugin

h5grove.content.create_content(h5file, path, resolve_links=LinkResolution.ONLY_VALID)

Factory function to get entity content from a HDF5 file. This handles external/soft link resolution and dataset decompression.

Parameters:
  • h5file (File) – An open HDF5 file containing the entity

  • path (str | None) – Path to the entity in the file.

  • resolve_links (LinkResolution) – Tells which external and soft links should be resolved. Defaults to resolving only valid links.

Raises:
  • h5grove.utils.PathError – If the path cannot be found in the file

  • h5grove.utils.LinkError – If a link cannot be resolved when resolve_links is set to LinkResolution.ALL.

  • TypeError – If encountering an unsupported h5py entity

Content object reference

The Content objects returned by create_content hold information to design endpoints.

The Content objects returned by create_content expose the relevant information of the entity through methods:

  • attributes: Only for non-link entities. The dict of attributes.

  • metadata: For all entities. Information on the entities. Includes attribute metadata for non-link entities.

  • data: Only for datasets. Data contained in a dataset or a slice of dataset.

  • data_stats: Only for datasets. Statistics computed on the data of the dataset or a slice of it.

These methods are directly plugged to the endpoints from the example implementations so you can take a look at the endpoints API for more information.

class h5grove.content.ExternalLinkContent(path, link)
Parameters:
  • path (str) –

  • link (ExternalLink) –

kind = 'external_link'
metadata(depth=None)

External link metadata

Returns:

{“name”: str, “target_file”: str, “target_path”: str, “kind”: str}

property name: str

Entity name. Last member of the path.

property path: str

Path in the file.

property target_file: str

The target file of the link

property target_path: str

The target path of the link (in the target file)

class h5grove.content.SoftLinkContent(path, link)
Parameters:
  • path (str) –

  • link (SoftLink) –

kind = 'soft_link'
metadata(depth=None)
Returns:

{“name”: str, “target_path”: str, “kind”: str}

property name: str

Entity name. Last member of the path.

property path: str

Path in the file.

property target_path: str

The target path of the link

class h5grove.content.DatasetContent(path, h5py_entity)
attributes(attr_keys=None)

Attributes of the h5py entity. Can be filtered by keys.

Parameters:

attr_keys (Sequence[str] | None) –

data(selection=None, flatten=False, dtype='origin')

Dataset data.

Parameters:
data_stats(selection=None)

Statistics on the data. Providing a selection will compute stats only on the selected slice.

Parameters:

selection (str | int | slice | Tuple[slice | int, ...] | None) – NumPy-like indexing to define a selection as a slice

Returns:

{“strict_positive_min”: number | None, “positive_min”: number | None, “min”: number | None, “max”: number | None, “mean”: number | None, “std”: number | None}

Return type:

Dict[str, float | int | None]

kind = 'dataset'
metadata(depth=None)
Returns:

{“attributes”: AttributeMetadata, chunks”: tuple, “filters”: tuple, “kind”: str, “name”: str, “shape”: tuple, “type”: TypeMetadata}

property name: str

Entity name. Last member of the path.

property path: str

Path in the file.

class h5grove.content.GroupContent(path, h5py_entity, h5file)
attributes(attr_keys=None)

Attributes of the h5py entity. Can be filtered by keys.

Parameters:

attr_keys (Sequence[str] | None) –

kind = 'group'
metadata(depth=1)

Metadata of the group. Recursively includes child metadata if depth > 0.

Parameters:
  • depth (int) – The level of child metadata resolution.

  • depth

Returns:

{“attributes”: AttributeMetadata, “children”: ChildMetadata, “name”: str, “kind”: str}

property name: str

Entity name. Last member of the path.

property path: str

Path in the file.

encoders module

The encoders module contain functions that encode data and provide the appropriate headers to build request responses. The module provides a JSON encoder using orjson, a binary encoder for NumPy arrays and other encoders to serve NumPy arrays as downloadable files.

General

h5grove.encoders.encode(content, encoding='json')

Encode content in given encoding.

Warning: Not all encodings supports all types of content.

Parameters:
  • content (Any) – Content to encode

  • encoding (str | None) –

    • json (default)

    • bin: nD array/scalars in bytes

    • csv: nD arrays in downloadable csv files

    • npy: nD arrays in downloadable npy files

    • tiff: 2D arrays in downloadable TIFF files

Returns:

A Response object containing content and headers

Raises:

QueryArgumentError – If encoding is not among the ones above.

Return type:

Response

class h5grove.encoders.Response(content, headers)
Parameters:
  • content (bytes) –

  • headers (Dict[str, str]) –

content: bytes

Encoded content as bytes

headers: Dict[str, str]

Associated headers

General

h5grove.encoders.orjson_default(o)

Converts Python objects to JSON-serializable objects.

Raises:

TypeError – if the object is not supported.

Parameters:

o (Any) –

Return type:

list | float | str | None

h5grove.encoders.orjson_encode(content, default=None)

Encode in JSON using orjson.

Param:

content: Content to encode

Parameters:
Return type:

bytes

Binary

h5grove.encoders.bin_encode(array)

Convert array to bytes.

Parameters:

array (ndarray) – Data to convert

Return type:

bytes

File formats

h5grove.encoders.csv_encode(data)

Encodes a NumPy array in CSV.

Param:

data: NumPy array to encode

Parameters:

data (ndarray) –

Return type:

bytes

h5grove.encoders.npy_encode(data)

Encodes a NumPy array in NPY.

Param:

data: NumPy array to encode

Parameters:

data (ndarray) –

Return type:

bytes

h5grove.encoders.tiff_encode(data)

Encodes a NumPy array in TIFF. The data should be 2D.

Param:

data: NumPy array to encode

Parameters:

data (ndarray) –

Return type:

bytes