Zarr Python
Overview
Zarr is a Python library for storing large N-dimensional arrays with chunking and compression. Apply this skill for efficient parallel I/O, cloud-native workflows, and seamless integration with NumPy, Dask, and Xarray. The guidance targets zarr-python 3.x (current 3.4.0), which writes the Zarr v3 format by default.
When to Use This Skill
Use this skill when the user wants to:
- Create, open, or write chunked and compressed N-D arrays (
zarr.create_array, groups, attributes).
- Choose chunk shapes, sharding, and codecs (Zstandard, Blosc, Gzip) for an access pattern.
- Put arrays on S3/GCS or other object stores and read slices remotely (consolidated metadata, sharding).
- Convert HDF5/NumPy/NetCDF data to Zarr, or migrate Zarr v2-era code (
compressor=, synchronizer=, create_dataset) to v3.
Does NOT Trigger
| Scenario |
Use Instead |
| Parallel or distributed computation over arrays already stored in Zarr (scheduling, out-of-core math) |
alterlab-dask |
| Exploring an unknown data file and writing a structure/quality report |
alterlab-eda |
Single-cell AnnData objects stored as .h5ad or AnnData-on-zarr |
alterlab-anndata |
| Tabular analytics on large CSV/Parquet files |
alterlab-polars |
Hand-off rule. When the request matches a row above, open your answer by naming that skill by its exact id (for example alterlab-dask) and saying in one line why it fits better, then stop applying this skill's procedure. Name it even when you also need to ask for missing input. If only part of the request is out of scope, name the skill for that part and do only the in-scope part. A brief general pointer is fine; the named skill does the work.
Quick Start
Installation
uv run --python ">=3.12" --with "zarr>=3" python store.py # no install step
Zarr v3 (zarr>=3); zarr 3.2+ requires Python 3.12+ and NumPy 2 (the 3.1.x line still supports
Python 3.11). For cloud storage support, install the matching fsspec backend:
uv run --python ">=3.12" --with "zarr>=3" --with s3fs python store.py # For S3
uv run --python ">=3.12" --with "zarr>=3" --with gcsfs python store.py # For Google Cloud Storage
Basic Array Creation
import zarr
import numpy as np
# Create a 2D array with chunking and compression
z = zarr.create_array(
store="data/my_array.zarr",
shape=(10000, 10000),
chunks=(1000, 1000),
dtype="f4"
)
# Write data using NumPy-style indexing
z[:, :] = np.random.random((10000, 10000))
# Read data
data = z[0:100, 0:100] # Returns NumPy array
Core Workflow
- Create or open an array/group, picking a store appropriate to the environment (local, in-memory, ZIP, S3/GCS).
- Choose chunking aligned to your access pattern (aim for 1-10 MB chunks; rows-first → chunks span columns, and vice versa). This is the single biggest performance lever.
- Pick compression via
compressors= based on workload — Zstandard (the default), Blosc+LZ4 (fast), Gzip (max ratio); compressors=None to disable. Pass Blosc options as strings (shuffle="shuffle", cname="zstd"); the BloscShuffle/BloscCname enums are deprecated since 3.1.
- Read/write with NumPy-style indexing; resize/append as data grows.
- Scale out with Dask (lazy, out-of-core, parallel) or label with Xarray for climate/geospatial data.
- For cloud and many-array stores, consolidate metadata and consider sharding to cut object/file count. Consolidated metadata is a zarr-python convention, not yet part of the v3 spec (zarr warns), so other readers may ignore it.
# Minimal end-to-end
import zarr, numpy as np
z = zarr.create_array(store="data/my_array.zarr", shape=(10000, 10000),
chunks=(1000, 1000), dtype="f4")
z[:, :] = np.random.random((10000, 10000))
sub = z[0:100, 0:100] # returns a NumPy array
Routing — where to look
| You need… |
Go to |
| Array create/open, read/write, resize/append, attributes, groups & hierarchies, consolidated metadata |
references/array_operations.md |
| Chunk-size guidelines, aligning chunks to access patterns, sharding, compression codecs & tips |
references/chunking_compression.md |
| Local / in-memory / ZIP / S3 / GCS stores and cloud best practices |
references/storage_backends.md |
| NumPy / Dask / Xarray integration, thread- and process-safe parallel writes |
references/integration.md |
| Performance checklist, profiling, common patterns (time series, large matrices, cloud-native, format conversion), troubleshooting |
references/patterns_performance.md |
| Full API surface |
references/api_reference.md |
Additional Resources
Part of the AlterLab Academic Skills suite.
1---2name: alterlab-zarr3description: Chunked, compressed N-dimensional arrays for cloud storage with Zarr — parallel I/O, S3/GCS integration, and NumPy/Dask/Xarray compatibility. Use when storing or reading large N-D scientific arrays, streaming chunked data to/from cloud object stores, or building large-scale scientific computing pipelines. Part of the AlterLab Academic Skills suite.4license: MIT5allowed-tools: Read Write Edit Bash(python:*) Bash(uv:*)6compatibility: No API key required. Runs locally via `uv run --python ">=3.12" --with "zarr>=3" python script.py` (no install step; the interpreter pin matters because an older default Python resolves older releases); requires zarr >= 3 (current 3.4 as of 2026-09; zarr >= 3.2 needs Python >= 3.12 and NumPy >= 2). Cloud credentials only needed for S3/GCS object stores.7metadata:8 source: https://skillmd.com/skills/alterlab-ieu/alterlab-zarr9 skill-author: AlterLab10 version: "1.1.0"11 last_updated: "2026-09-23"12---1314# Zarr Python1516## Overview1718Zarr is a Python library for storing large N-dimensional arrays with chunking and compression. Apply this skill for efficient parallel I/O, cloud-native workflows, and seamless integration with NumPy, Dask, and Xarray. The guidance targets zarr-python 3.x (current 3.4.0), which writes the Zarr v3 format by default.1920## When to Use This Skill2122Use this skill when the user wants to:23- Create, open, or write chunked and compressed N-D arrays (`zarr.create_array`, groups, attributes).24- Choose chunk shapes, sharding, and codecs (Zstandard, Blosc, Gzip) for an access pattern.25- Put arrays on S3/GCS or other object stores and read slices remotely (consolidated metadata, sharding).26- Convert HDF5/NumPy/NetCDF data to Zarr, or migrate Zarr v2-era code (`compressor=`, `synchronizer=`, `create_dataset`) to v3.2728### Does NOT Trigger2930| Scenario | Use Instead |31|----------|-------------|32| Parallel or distributed computation over arrays already stored in Zarr (scheduling, out-of-core math) | `alterlab-dask` |33| Exploring an unknown data file and writing a structure/quality report | `alterlab-eda` |34| Single-cell AnnData objects stored as `.h5ad` or AnnData-on-zarr | `alterlab-anndata` |35| Tabular analytics on large CSV/Parquet files | `alterlab-polars` |3637**Hand-off rule.** When the request matches a row above, open your answer by naming that skill by its exact id (for example `alterlab-dask`) and saying in one line why it fits better, then stop applying this skill's procedure. Name it even when you also need to ask for missing input. If only part of the request is out of scope, name the skill for that part and do only the in-scope part. A brief general pointer is fine; the named skill does the work.3839## Quick Start4041### Installation4243```bash44uv run --python ">=3.12" --with "zarr>=3" python store.py # no install step45```4647Zarr v3 (`zarr>=3`); zarr 3.2+ requires Python 3.12+ and NumPy 2 (the 3.1.x line still supports48Python 3.11). For cloud storage support, install the matching fsspec backend:49```bash50uv run --python ">=3.12" --with "zarr>=3" --with s3fs python store.py # For S351uv run --python ">=3.12" --with "zarr>=3" --with gcsfs python store.py # For Google Cloud Storage52```5354### Basic Array Creation5556```python57import zarr58import numpy as np5960# Create a 2D array with chunking and compression61z = zarr.create_array(62 store="data/my_array.zarr",63 shape=(10000, 10000),64 chunks=(1000, 1000),65 dtype="f4"66)6768# Write data using NumPy-style indexing69z[:, :] = np.random.random((10000, 10000))7071# Read data72data = z[0:100, 0:100] # Returns NumPy array73```7475## Core Workflow76771. **Create or open** an array/group, picking a store appropriate to the environment (local, in-memory, ZIP, S3/GCS).782. **Choose chunking** aligned to your access pattern (aim for 1-10 MB chunks; rows-first → chunks span columns, and vice versa). This is the single biggest performance lever.793. **Pick compression** via `compressors=` based on workload — Zstandard (the default), Blosc+LZ4 (fast), Gzip (max ratio); `compressors=None` to disable. Pass Blosc options as strings (`shuffle="shuffle"`, `cname="zstd"`); the `BloscShuffle`/`BloscCname` enums are deprecated since 3.1.804. **Read/write** with NumPy-style indexing; resize/append as data grows.815. **Scale out** with Dask (lazy, out-of-core, parallel) or label with Xarray for climate/geospatial data.826. **For cloud and many-array stores**, consolidate metadata and consider sharding to cut object/file count. Consolidated metadata is a zarr-python convention, not yet part of the v3 spec (zarr warns), so other readers may ignore it.8384```python85# Minimal end-to-end86import zarr, numpy as np87z = zarr.create_array(store="data/my_array.zarr", shape=(10000, 10000),88 chunks=(1000, 1000), dtype="f4")89z[:, :] = np.random.random((10000, 10000))90sub = z[0:100, 0:100] # returns a NumPy array91```9293## Routing — where to look9495| You need… | Go to |96|-----------|-------|97| Array create/open, read/write, resize/append, attributes, groups & hierarchies, consolidated metadata | `references/array_operations.md` |98| Chunk-size guidelines, aligning chunks to access patterns, sharding, compression codecs & tips | `references/chunking_compression.md` |99| Local / in-memory / ZIP / S3 / GCS stores and cloud best practices | `references/storage_backends.md` |100| NumPy / Dask / Xarray integration, thread- and process-safe parallel writes | `references/integration.md` |101| Performance checklist, profiling, common patterns (time series, large matrices, cloud-native, format conversion), troubleshooting | `references/patterns_performance.md` |102| Full API surface | `references/api_reference.md` |103104## Additional Resources105106- **Official Documentation**: https://zarr.readthedocs.io/107- **Zarr Specifications**: https://zarr-specs.readthedocs.io/108- **GitHub Repository**: https://github.com/zarr-developers/zarr-python109- **Related**: Xarray (labeled arrays), Dask (parallel computing), NumCodecs (compression codecs)110111Part of the AlterLab Academic Skills suite.112