Skip to main content

zarr-metadata

Python types, models, and validators for Zarr v2 and v3 metadata.

Documentation: https://zarr-metadata.readthedocs.io/

What this is

Two layers and an optional integration:

  • Typed JSON shapes: TypedDict definitions and Literal aliases for the JSON documents specified by the Zarr v2 and Zarr v3 specifications, plus types for zarr-extensions and a few widely-used-but-unspecified entities (e.g. consolidated metadata).
  • Document models (zarr_metadata.model): canonical frozen-dataclass models of whole metadata documents, with structural validators, loc-aware parsers, and store-key (de)serialization. A document produced by to_json shares no mutable state with the model that produced it.
  • Optional Pydantic integration (zarr_metadata.pydantic, requires Pydantic 2.13 or newer): each model as a Pydantic field type that validates raw documents through the same strict parser.

What this is for

The public TypedDict definitions describe the static JSON shape of Zarr metadata. For strict, loc-aware validation of JSON loaded from disk, use the model parser:

import json
from zarr_metadata.model import ZarrV3ArrayMetadata

with open("zarr.json", "rb") as f:
    raw = json.load(f)

metadata = ZarrV3ArrayMetadata.from_json(raw)

The optional Pydantic integration delegates raw input to the same strict parser and returns the same normalized model class:

from pydantic import TypeAdapter
import zarr_metadata.pydantic as zmp

metadata = TypeAdapter(zmp.ZarrV3ArrayMetadata).validate_python(raw)
encoded = metadata.to_key_value()["zarr.json"]

A bare TypeAdapter over a public document TypedDict is a coercive shape adapter, not a Zarr conformance validator; it may coerce values or discard members that the strict model parser rejects.

Validation boundary

The model validators enforce the declared document structure and a small set of context-free consistency rules, including fixed format literals, finite JSON numbers, non-negative dimensions, non-empty v3 codec pipelines, and one dimension_names entry per array dimension. They do not interpret extension names or configurations, resolve codec pipelines, or decide whether a data type, chunk grid, codec, or storage transformer is supported. Those decisions belong to consumer implementations.

The Pydantic integration's generated JSON Schemas express independently checkable document structure and field constraints, but they are not a replacement for runtime model validation. Standard JSON Schema treats a mathematically integral number such as 1.0 as an integer, while the runtime boundary requires Python int values, and it cannot express arbitrary same-length relations such as dimension_names versus shape or v2 chunks versus shape. Consumers should run the model parser after schema validation.

Scope

At minimum, this library supports what Zarr-Python needs: the complete Zarr v2 and v3 specs, consolidated metadata, and a subset of the metadata defined in zarr-extensions. We are generally open to contributions that add types, models, or structural validation for Zarr metadata with a published spec.

Runtime array behavior is out of scope: nothing here encodes or decodes chunks, resolves codec or data type names to implementations, or performs store I/O. The models begin and end at the metadata documents themselves — from_key_value / to_key_value map documents to store keys and bytes, and everything past that belongs to consumer libraries.

Developing

Package-scoped development commands live in the justfile (requires just):

just test        # run the test suite (extra args go to pytest)
just lint        # ruff, same invocation as CI
just typecheck   # pyright, pinned to the version CI uses
just docs-check  # strict build of the docs site
just check       # all of the above
just docs-serve  # serve the docs site locally

Run them from this directory, or from anywhere in the repository as just packages/zarr-metadata/<recipe>.

Releasing

The package version is derived from git tags by hatch-vcs. Tags must match the pattern zarr_metadata-v<version> (e.g. zarr_metadata-v0.2.0) so they do not collide with the main zarr-python release tags.

To cut a release:

  1. Create and push a tag of the form zarr_metadata-v<version> on the commit you want to publish, e.g.:
    git tag zarr_metadata-v0.2.0 <commit>
    git push origin zarr_metadata-v0.2.0
    
  2. Pushing the tag fires the zarr-metadata release workflow, which builds the wheel/sdist (version resolved from the tag), runs an install smoke test, and publishes to PyPI via OIDC trusted publishing.

We intentionally do not create a GitHub Release for zarr-metadata versions — GitHub Releases live at the repo level, and a zarr-metadata release would surface in the zarr-python repo's Releases UI as if it were a zarr-python release.

To dry-run a build against TestPyPI, dispatch the workflow manually (Actionszarr-metadata releaseRun workflow). Manual dispatches build from the current commit; with no recent tag the version will look like 0.1.devN, which is fine for TestPyPI.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zarr_metadata-0.4.0.tar.gz (149.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zarr_metadata-0.4.0-py3-none-any.whl (69.8 kB view details)

Uploaded Python 3

File details

Details for the file zarr_metadata-0.4.0.tar.gz.

File metadata

  • Download URL: zarr_metadata-0.4.0.tar.gz
  • Upload date:
  • Size: 149.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for zarr_metadata-0.4.0.tar.gz
Algorithm Hash digest
SHA256 56788af0b86ec653176410fd57e0f4815331ac61d61e562dfd020198e98ce3eb
MD5 9d54322c5baa0e4b637c722e6e75daba
BLAKE2b-256 0476ca9334554b9a875c2c68203e2ce8b0a3febe1c3e9efba00a57e9a12c4e40

See more details on using hashes here.

Provenance

The following attestation bundles were made for zarr_metadata-0.4.0.tar.gz:

Publisher: zarr-metadata-release.yml on zarr-developers/zarr-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zarr_metadata-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: zarr_metadata-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 69.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for zarr_metadata-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 642106291b881284d08222973d0970dd950d254b2286f36fcc269b0b1a1f4be2
MD5 8891e9f49733369c8954dfe7212e4c46
BLAKE2b-256 cb8bf8594d9160f0eaae3f988eb2969bafc9db96bf3e224b8199b1bb80fa1f7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for zarr_metadata-0.4.0-py3-none-any.whl:

Publisher: zarr-metadata-release.yml on zarr-developers/zarr-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page