Skip to content
Skillpedia
Databases51k · #2003

zarr-python

Helps your agent store and query large scientific datasets. It's useful for organizing information and ensuring quick access.

What it does

Zarr-Python is a tool for organizing and accessing large scientific datasets in chunks. It allows you to work with data that doesn't fit entirely in memory, storing it efficiently and enabling you to read only the necessary parts.

When to use it

  • ✓When you have scientific data too large to fit into memory.
  • ✓To read or write specific parts of a dataset without loading everything.
  • ✓For storing data in the cloud like Amazon S3 or Google Cloud Storage.

Example of what to ask your AI

“How can I save a giant NumPy array in chunks and read only a small section of it?”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/zarr-python/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/zarr-python/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

It divides your data into smaller blocks (chunks) and can use compression. This allows you to access only the data blocks you need, saving time and memory.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add K-Dense-AI/scientific-agent-skills --skill zarr-python

Or download just the file:

curl -L https://raw.githubusercontent.com/K-Dense-AI/scientific-agent-skills/main/skills/zarr-python/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

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

  1. Inspect shape, dtype, axis names, coordinates, units, missing-value convention, format, codec availability, and intended readers. Preserve sample IDs and axis order.
  2. Choose chunks for actual selections and a memory budget. For sharding, choose shard dimensions that are multiples of chunk dimensions. Benchmark representative data.
  3. Create a new destination (overwrite=False or mode="w-"). Use mode="r" for inspection; "a" can create a missing store and "w" destroys existing content.
  4. Write bounded blocks. Assign one writer per stored chunk, or per shard when sharded; serialize metadata, append, and resize operations.
  5. 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.
  6. 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


…
FAQ

What are 'chunks'?

Chunks are small pieces or blocks into which your data is divided for easier management and access.

Can I use this with cloud data?

Yes, Zarr-Python supports storage on cloud services like Amazon S3 and Google Cloud Storage.

What Python libraries does it use?

It integrates well with popular libraries like NumPy, Dask, and Xarray, which are common in scientific computing.

Details

Original description by the author

Stores and queries chunked N-D scientific arrays with Zarr-Python 3, including codecs, sharding, S3/GCS storage, and NumPy/Dask/Xarray integration. Use for array layout, bounded I/O, format migration, or scientific metadata preservation.

repo: K-Dense-AI/scientific-agent-skills

Popularity

GitHub stars
51k
Ranking position
#2003
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills