# Zarr Python

Chunked N-D arrays for cloud storage.

- Repository: https://github.com/LeonChaoX/qinyan-academic-skills (996 stars)
- Category: Data and ML
- License: MIT license
- Last updated: 2026-07-20
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add LeonChaoX/qinyan-academic-skills --skill zarr-python -g -a claude-code -y`
Codex: `npx skills add LeonChaoX/qinyan-academic-skills --skill zarr-python -g -a codex -y`
Cursor: `npx skills add LeonChaoX/qinyan-academic-skills --skill zarr-python -g -a cursor -y`
Gemini CLI: `npx skills add LeonChaoX/qinyan-academic-skills --skill zarr-python -g -a gemini-cli -y`

## Description

Chunked N-D arrays for cloud storage. Compressed arrays, parallel I/O, S3/GCS integration, NumPy/Dask/Xarray compatible, for large-scale scientific computing pipelines.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# 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.

## Quick Start

### Installation

```bash
uv pip install zarr
```

Requires Python 3.11+. For cloud storage support, install additional packages:
```python
uv pip install s3fs  # For S3
uv pip install gcsfs  # For Google Cloud Storage
```

### Basic Array Creation

```python
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 Operations

### Creating Arrays

Zarr provides multiple convenience functions for array creation:

```python
# Create empty array
z = zarr.zeros(shape=(10000, 10000), chunks=(1000, 1000), dtype='f4',
               store='data.zarr')

# Create filled arrays
z = zarr.ones((5000, 5000), chunks=(500, 500))
z = zarr.full((1000, 1000), fill_value=42, chunks=(100, 100))

# Create from existing data
data = np.arange(10000).reshape(100, 100)
z = zarr.array(data, chunks=(10, 10), store='data.zarr')

# Create like another array
z2 = zarr.zeros_like(z)  # Matches shape, chunks, dtype of z
```

### Opening Existing Arrays

```python
# Open array (read/write mode by default)
z = zarr.open_array('data.zarr', mode='r+')

# Read-only mode
z = zarr.open_array('data.zarr', mode='r')

# The open() function auto-detects arrays vs groups
z = zarr.open('data.zarr')  # Returns Array or Group
```

### Reading and Writing Data

Zarr arrays support NumPy-like indexing:

```python
# Write entire array
z[:] = 42

# Write slices
z[0, :] = np.arange(100)
z[10:20, 50:60] = np.random.random((10, 10))

The rest: https://github.com/LeonChaoX/qinyan-academic-skills/blob/HEAD/skills/05-生物信息与基因组学/zarr-python/SKILL.md
