AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
Zarr-Python 3 provides a robust framework for managing large, chunked N-dimensional scientific arrays. This skill covers the implementation of Zarr-Python 3.4.0, focusing on array layout, efficient I/O, and integration with the broader scientific Python ecosystem including NumPy, Dask, and Xarray. It details the use of codecs, sharding, and cloud-based storage backends like S3 and GCS, while providing best practices for metadata management and format migration.
What it does
- Enables creation and manipulation of chunked N-D arrays with support for Zarr format 3.
- Supports integration with NumPy, Dask, and Xarray for scientific data workflows.
- Provides mechanisms for sharding to optimize I/O performance for large datasets.
- Facilitates storage in local filesystems or cloud object stores like S3 and GCS.
- Offers tools for metadata preservation and hierarchical group organization.
- Includes guidance on codec selection and compression strategies for scientific data.
When to use it
- When working with large, multi-dimensional scientific datasets that require chunked storage.
- When you need to perform partial reads or bounded I/O on large arrays to save memory.
- When migrating existing array data to the Zarr format 3 specification.
- When building data pipelines that require interoperability between NumPy, Dask, and Xarray.
- When optimizing storage layout for cloud-based scientific computing environments.
Advantages
- Supports efficient partial data access, reducing memory overhead for large arrays.
- Provides flexible chunking and sharding options to tune performance for specific access patterns.
- Native support for cloud object storage backends simplifies distributed data workflows.
- Maintains compatibility with standard scientific Python libraries.
- Allows for explicit control over compression and serialization codecs.
Usage examples
- “How do I create a new Zarr array with specific chunks and compression?”
- The agent provides a code snippet using zarr.create_array with defined shape, dtype, chunks, and a BloscCodec configuration.
- “Show me how to append data to an existing Zarr array.”
- The agent demonstrates the use of the .append() method on a Zarr array object, including necessary resizing steps.
- “How can I organize my scientific data into a hierarchy?”
- The agent explains how to use zarr.open_group to create a root group and nested arrays, including setting attributes for metadata.
- “What is the best way to read a subset of a large Zarr array?”
- The agent illustrates how to perform bounded slicing on a Zarr array, which materializes only the requested subset into memory.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/k-dense-ai/zarr-python/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip zarr-python.zip -d .agents/skills
Documentation by K-Dense Inc.
Zarr Python
When to use
Use for chunked scientific arrays, hierarchical stores, codecs, sharding, partial reads,
cloud object storage, and NumPy/Dask/Xarray interoperability. This community guide targets
Zarr-Python 3.4.0, released 2026-09-15, with Python 3.12+. The package version and
on-disk format are separate: this release reads/writes formats 2 and 3; new arrays default
to format 3. Keep downstream packages that require zarr<3 in their own environments.
Install
uv pip install "zarr==3.4.0" "numpy==2.5.3"
# Optional remote backends and migration CLI:
uv pip install "zarr[remote,cli]==3.4.0" "fsspec==2026.9.0" "s3fs==2026.9.0" "gcsfs==2026.8.1"Commit the project's resolved lockfile. Optional integration versions exercised here: Dask 2026.8.0, Xarray 2026.9.0, h5py 3.16.0, NumCodecs 0.17.0, obstore 0.11.1. Local examples below and in the references use tiny synthetic arrays; remote snippets are illustrative and require a real authorized store. This does not establish cloud permissions, production throughput, or compatibility of every downstream reader.
Workflow
Inspect shape, dtype, axis names, coordinates, units, missing-value convention, format, codec availability, and intended readers. Preserve sample IDs and axis order.
Choose chunks for actual selections and a memory budget. For sharding, choose shard dimensions that are multiples of chunk dimensions. Benchmark representative data.
Create a new destination (
overwrite=Falseormode="w-"). Usemode="r"for inspection;"a"can create a missing store and"w"destroys existing content.Write bounded blocks. Assign one writer per stored chunk, or per shard when sharded; serialize metadata, append, and resize operations.
Reopen read-only and compare values, dtype, shape, coordinates, units, masks and metadata. An unwritten or missing chunk normally reads as
fill_value; a successful open alone does not prove data completeness.For a completed group hierarchy, optionally consolidate metadata. Format-3 consolidation is experimental; refresh it after metadata changes and verify the actual consumers. Publish a completed store only after validation.
Basic array roundtrip
import numpy as np
import zarr
from zarr.codecs import BloscCodec
expected = np.arange(96, dtype="float32").reshape(12, 8)
z = zarr.create_array(
"array.zarr", shape=expected.shape, dtype=expected.dtype,
chunks=(4, 4), zarr_format=3,
compressors=BloscCodec(cname="zstd", clevel=5, shuffle="bitshuffle"),
dimension_names=("sample", "feature"),
attributes={"units": "arbitrary", "source": "synthetic example"},
)
for start in range(0, z.shape[0], 4):
z[start:start + 4] = expected[start:start + 4]
reopened = zarr.open_array("array.zarr", mode="r")
np.testing.assert_array_equal(reopened[:], expected)
assert reopened.dtype == expected.dtype
assert reopened.metadata.dimension_names == ("sample", "feature")
assert reopened.attrs["units"] == "arbitrary"
subset = reopened[2:6, 1:4] # Only this selection is materialized.create_array takes either data= or shape= plus dtype=; do not combine data=
with explicit shape/dtype. The format-3 numeric default is a bytes serializer followed
by ZstdCodec, not Blosc. Set a codec explicitly for reproducibility.
Creation and indexing
import numpy as np
import zarr
z = zarr.create_array(None, data=np.arange(80).reshape(10, 8), chunks=(2, 4))
zeros = zarr.zeros((10, 8), chunks=(2, 4), dtype="f4")
ones = zarr.ones((10, 8), chunks=(2, 4), dtype="f4")
filled = zarr.full((10, 8), fill_value=42, chunks=(2, 4), dtype="i4")
like = zarr.zeros_like(z)
np.testing.assert_array_equal(filled[:], np.full((10, 8), 42))
# Coordinate indexing pairs corresponding coordinates; orthogonal indexing is a product.
np.testing.assert_array_equal(z.vindex[[0, 5], [2, 7]], [2, 47])
np.testing.assert_array_equal(z.get_coordinate_selection(([0, 5], [2, 7])), [2, 47])
assert z.oindex[[0, 5], [2, 7]].shape == (2, 2)
assert z.blocks[0, 0].shape == (2, 4)
z[0, :] = np.arange(8)Negative-step slices are unsupported. Array reads return NumPy data in the default CPU
configuration. np.asarray(z), np.sum(z), z[:], or a Dask .compute() of a full array
can materialize the entire logical dataset; use bounded selections or lazy reductions.
Resize and append
import numpy as np
import zarr
series = zarr.create_array(None, shape=(0, 8), chunks=(2, 8), dtype="f4")
series.append(np.ones((2, 8), dtype="f4"), axis=0)
series.resize((4, 8)) # A tuple; append must match all non-appended dimensions.
assert series.shape == (4, 8)
np.testing.assert_array_equal(series[2:], np.zeros((2, 8)))Coordinate resize/append centrally. Shrinking removes chunks outside the new shape, but values in retained boundary chunks can reappear on re-expansion; resize is not secure erasure or a missingness policy. Record time/sample coordinates alongside data.
Groups and attributes
import numpy as np
import zarr
root = zarr.open_group("hierarchy.zarr", mode="w-", zarr_format=3)
temperature = root.create_group("temperature")
temp = temperature.create_array(
"t2m", data=np.full((3, 4, 6), 280, dtype="f4"), chunks=(1, 4, 6),
dimension_names=("time", "lat", "lon"), attributes={"units": "K"},
)
root.require_group("quality")
root.require_array("count", shape=(3,), chunks=(3,), dtype="i4")
root.attrs.update({"project": "synthetic climate example", "processing_version": "1.0"})
loaded = zarr.open_group("hierarchy.zarr", mode="r")
assert loaded["temperature/t2m"].attrs["units"] == "K"
assert loaded.attrs["processing_version"] == "1.0"
print(loaded.tree()) # Logical group/array tree, not physical metadata files.Use create_array / require_array; create_dataset / require_dataset are removed.
Attributes belong to the specific node on which they are set and must be JSON-compatible.
Names/units are declarations, not unit conversion or scientific validation.
require_array checks an existing array's compatibility; it does not rechunk it.
References
Chunking and compression: measured layout decisions, default codecs, sharding, experimental rectilinear grids.
Storage backends: local, memory, ZIP, ObjectStore, fsspec, S3/GCS/HTTP paths and credentials.
Integration: bounded NumPy/Dask operations, Xarray dimensions and masks, concurrent writes, consolidation.
Performance and patterns: storage sizing, appendable data, bounded HDF5/NumPy conversion, validation.
API reference: current callable forms and exceptions.
Migration: API versus format migration, metadata-only CLI behavior and a copied-store verification workflow.
Review evidence: release sources and execution boundaries.
Official sources: release notes, documentation, format specification, released source.
Citing Scientific Agent Skills
This skill is part of Scientific Agent Skills by K-Dense. If it materially contributed to a manuscript, report, presentation, or code release, add the paper to the references or software section and tell the user you did so:
Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065. https://doi.org/10.48550/arXiv.2609.00065
Always cite the current version. The DOI and https://arxiv.org/abs/2609.00065 resolve to the
latest arXiv version, so never append a version suffix such as v1. When network access is
available, fetch https://arxiv.org/abs/2609.00065 (or
http://export.arxiv.org/api/query?id_list=2609.00065) before writing the reference and take
the author list, year, and version from that record. If the record lists a journal reference
or publisher DOI, cite the published version instead.
Files
- ATTRIBUTION.mdAdded by AutoGineer980 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md8.7 KiB
- references/api_reference.md4.8 KiB
- references/chunking_and_compression.md4.6 KiB
- references/integration.md6.2 KiB
- references/performance_and_patterns.md6.4 KiB
- references/review.md2.5 KiB
- references/storage_backends.md5.4 KiB
- references/v3_migration.md3.9 KiB
references/integration.md
Integration, parallelism, and consolidated metadata
Tested with Zarr 3.4.0, NumPy 2.5.3, Dask 2026.8.0, and Xarray 2026.9.0.
NumPy and Dask
NumPy conversion is eager. Dask can read and reduce by chunks, but .compute() still
materializes its result; a full 100000-by-100000 float64 result needs about 80 GB.
Write large results directly to a new store. Align Dask task boundaries to whole stored
chunks/shards and budget all concurrent task/codec buffers.
import numpy as np
import zarr
import dask.array as da
expected = np.arange(96, dtype="f4").reshape(12, 8)
z = zarr.create_array("dask-input.zarr", data=expected, chunks=(4, 4))
lazy = da.from_zarr("dask-input.zarr")
np.testing.assert_allclose(lazy.mean(axis=0).compute(), expected.mean(axis=0))
da.to_zarr(lazy * 2, "dask-output.zarr", mode="w-", zarr_format=3)
np.testing.assert_array_equal(zarr.open_array("dask-output.zarr", mode="r")[:], expected * 2)Dask to_zarr defaults to mode="a"; choose "w-" for new outputs. Known regular chunk
sizes are required for this path. Rechunking may involve large intermediate transfers;
benchmark it separately and don't assume a lazy graph is memory-free.
Xarray: labeled data and missingness
xr.open_zarr opens a group with dimension metadata, not an arbitrary bare Zarr
array. Format 3 uses native dimension_names; format 2 conventionally uses the
_ARRAY_DIMENSIONS attribute. Prefer Xarray's writer to create a labeled dataset and
preserve coordinates, units, calendar and missing-value encodings together.
import numpy as np
import xarray as xr
values = np.arange(24, dtype="f4").reshape(3, 2, 4)
values[1, 0, 1] = np.nan
expected = xr.Dataset(
{"temperature": (("time", "lat", "lon"), values, {"units": "K"})},
coords={
"time": np.array(["2026-01-01", "2026-01-02", "2026-01-03"], dtype="datetime64[ns]"),
"lat": [30.0, 60.0], "lon": [0.0, 90.0, 180.0, 270.0],
},
attrs={"source": "synthetic example"},
)
expected.to_zarr(
"climate.zarr", mode="w-", zarr_format=3, consolidated=False,
encoding={"temperature": {"chunks": (1, 2, 4), "_FillValue": np.nan}},
)
with xr.open_zarr("climate.zarr", consolidated=False) as actual:
xr.testing.assert_identical(actual.compute(), expected)
subset = actual.sel(time="2026-01-02", lat=slice(30, 60)).compute()
assert subset.temperature.shape == (2, 4)Storage fill_value and scientific _FillValue are different concepts in format 3.
With default Xarray behavior, a format-3 storage fill of zero is not automatically
missing; _FillValue controls masking. Format 2 normally interprets storage fill as
missing. Check use_zarr_fill_value_as_mask, decoding and dtype when opening; never
silently convert valid zeros to NaNs. A missing chunk can look like valid fill data,
so validate written coverage independently. Ascending versus descending coordinate
order changes which slice bounds select data; calendars and longitude conventions must
be explicit. Labels alone do not make a CF-compliant climate product.
For append/region writes, validate coordinates and existing schema first. Xarray's
safe_chunks=True checks a subset of chunk alignment constraints; it does not provide
locks or a multi-array transaction. Do not disable it merely to silence a warning.
Parallel writes and concurrency
Concurrent reads of a stable store are supported; readers are not promised a snapshot
during writes. Assign disjoint stored objects to writers: chunks for unsharded arrays,
shards for sharded arrays. Independent inner chunks can share one shard. Serialize
append/resize/attribute changes and external publication. ZIP is not a concurrent store.
Zarr-Python 3 has no functioning ThreadSynchronizer or ProcessSynchronizer; an old
synchronizer= argument may warn and be ignored, not protect writes.
from concurrent.futures import ThreadPoolExecutor
import numpy as np
import zarr
z = zarr.create_array("parallel.zarr", shape=(16, 8), dtype="i4", chunks=(2, 4), shards=(8, 8))
def write_shard(start):
target = zarr.open_array("parallel.zarr", mode="r+")
target[start:start + 8, :] = start + 1
with zarr.config.set({"async.concurrency": 4, "threading.max_workers": 4}):
with ThreadPoolExecutor(max_workers=2) as pool:
list(pool.map(write_shard, [0, 8]))
read = zarr.open_array("parallel.zarr", mode="r")[:]
np.testing.assert_array_equal(read[:8], np.full((8, 8), 1))
np.testing.assert_array_equal(read[8:], np.full((8, 8), 9))This is a local two-writer smoke test, not a distributed failure-recovery guarantee. Dask worker threads multiply pressure on the store; tune internal concurrency alongside worker count, memory and backend rate limits. The 3.4 default async concurrency is 10.
Consolidation is group metadata caching
Format 2 writes .zmetadata; format 3 embeds consolidated metadata in the root group's
zarr.json and remains experimental. tree() shows logical nodes, not those files.
Do not consolidate a standalone array root or assume all later opens see fresh metadata.
import numpy as np
import zarr
root = zarr.open_group("consolidated.zarr", mode="w-", zarr_format=2)
root.create_array("a", data=np.arange(8), chunks=(4,))
zarr.consolidate_metadata(root.store)
read = zarr.open_consolidated(root.store, mode="r")
np.testing.assert_array_equal(read["a"][:], np.arange(8))
# When freshness matters, explicitly bypass cached hierarchy metadata:
fresh = zarr.open_group(root.store, mode="r", use_consolidated=False)
assert fresh["a"].shape == (8,)Consolidate only after metadata writers finish. Use use_consolidated=False for mutable
hierarchies and reconsolidate completed revisions. A cached hierarchy may omit newly
created children or stale array shapes/attributes; actual chunk data is not cached there.
Pass a configured FsspecStore for cloud consolidation: consolidate_metadata has no
storage_options argument. Reopen with the same backend authorization.
Sources: Dask writer, Xarray writer, Xarray reader, consolidated metadata.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Declares allowed tools, Needs network access, Needs Python, Needs Node.js
The author says: Requires Python 3.12+ and zarr 3.4.0 with NumPy 2+. Remote I/O needs network access, zarr[remote] and the protocol backend; private stores need provider credentials. CLI migration needs zarr[cli].
Security
What our scanner noticed· Low risk
- Instructions that use the network
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- K-Dense Inc.
- Publisher
- K-Dense (Community)
- Source
- K-Dense-AI/scientific-agent-skills · skills/zarr-python · commit a25cf9e
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE.md)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by K-Dense Inc. or K-Dense.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download zarr-python.zip