Skip to content

zarr-developers/pydantic-zarr

pydantic-zarr

PyPI

Pydantic models for Zarr.

⚠️ Disclaimer ⚠️

This project is under flux -- I want to add zarr version 3 support to this project, but the reference python implementation doesn't support version 3 yet. As the ecosystem evolves things will break so be advised!

Installation

pip install -U pydantic-zarr

Getting help

  • Docs: see the documentation for detailed information about this project.
  • Chat: We use Zulip for project-related chat.

Example

import zarr
from pydantic_zarr import GroupSpec

group = zarr.group(path='foo')
array = zarr.create(store = group.store, path='foo/bar', shape=10, dtype='uint8')
array.attrs.put({'metadata': 'hello'})

# this is a pydantic model
spec = GroupSpec.from_zarr(group)
print(spec.model_dump())
"""
{
    'zarr_version': 2,
    'attributes': {},
    'members': {
        'bar': {
            'zarr_version': 2,
            'attributes': {'metadata': 'hello'},
            'shape': (10,),
            'chunks': (10,),
            'dtype': '|u1',
            'fill_value': 0,
            'order': 'C',
            'filters': None,
            'dimension_separator': '.',
            'compressor': {
                'id': 'blosc',
                'cname': 'lz4',
                'clevel': 5,
                'shuffle': 1,
                'blocksize': 0,
            },
        }
    },
}
"""

History

This project was developed at HHMI / Janelia Research Campus. It was originally written by Davis Bennett to solve problems he encountered while working on the Cellmap Project team. In December of 2024 this project was migrated from the janelia-cellmap github organization to zarr-developers organization.