Skill Tracer
Skills › Scientific Agent Skills › zarr-python › storage_backends.md

storage_backends.md

113 lines · skills/zarr-python/references/storage_backends.md at 5f2bc03

Open on GitHub
1# Storage backends
2
3Targets Zarr-Python 3.4.0. `zarr.storage` provides asynchronous store I/O behind the
4synchronous array API. A store is not a plain v2 `MutableMapping`.
5

Storage backends

Targets Zarr-Python 3.4.0. zarr.storage provides asynchronous store I/O behind the synchronous array API. A store is not a plain v2 MutableMapping.

Raw lines 1 to 5
6## Local and memory stores
7
8```python
9import numpy as np
10import zarr
11from zarr.storage import LocalStore, MemoryStore
13for store in [LocalStore("local.zarr"), MemoryStore()]:
14 z = zarr.create_array(store, data=np.arange(12), chunks=(4,))
15 np.testing.assert_array_equal(zarr.open_array(store, mode="r")[:], np.arange(12))
16```
18A path creates a LocalStore automatically. MemoryStore data persists only as long as the
19backing in-memory objects remain. Choose explicit read-only store/array modes for reads.

Local and memory stores

import numpy as np
import zarr
from zarr.storage import LocalStore, MemoryStore

for store in [LocalStore("local.zarr"), MemoryStore()]:
    z = zarr.create_array(store, data=np.arange(12), chunks=(4,))
    np.testing.assert_array_equal(zarr.open_array(store, mode="r")[:], np.arange(12))

A path creates a LocalStore automatically. MemoryStore data persists only as long as the backing in-memory objects remain. Choose explicit read-only store/array modes for reads.

Raw lines 6 to 20
21## ZIP archives
23```python
24import numpy as np
25import zarr
26from zarr.storage import ZipStore
28with ZipStore("array.zip", mode="w") as store:
29 z = zarr.create_array(store, data=np.arange(12), chunks=(4,))
30with ZipStore("array.zip", mode="r") as store:
31 np.testing.assert_array_equal(zarr.open_array(store, mode="r")[:], np.arange(12))
32```
34Close ZIP stores (the context manager does this). Write each chunk/metadata entry once;
35ZIP lacks deletion and repeated updates create duplicate archive entries. Stage changing
36data in a directory store, then archive the completed store. Do not share a writable ZIP
37between independent processes.

ZIP archives

import numpy as np
import zarr
from zarr.storage import ZipStore

with ZipStore("array.zip", mode="w") as store:
    z = zarr.create_array(store, data=np.arange(12), chunks=(4,))
with ZipStore("array.zip", mode="r") as store:
    np.testing.assert_array_equal(zarr.open_array(store, mode="r")[:], np.arange(12))

Close ZIP stores (the context manager does this). Write each chunk/metadata entry once; ZIP lacks deletion and repeated updates create duplicate archive entries. Stage changing data in a directory store, then archive the completed store. Do not share a writable ZIP between independent processes.

Raw lines 21 to 38
39## Fsspec and ObjectStore
41`FsspecStore.from_url(url, storage_options=..., read_only=...)` resolves the protocol and
42wraps supported synchronous filesystems when needed. Supplying an explicit filesystem
43to `FsspecStore` requires its async-compatible form. This native memory-protocol example
44checks the adapter without making a network request:
46```python
47import numpy as np
48import zarr
49from zarr.storage import FsspecStore
51store = FsspecStore.from_url("memory://zarr-skill-example")
52z = zarr.create_array(store, data=np.arange(12), chunks=(4,))
53np.testing.assert_array_equal(zarr.open_array(store, mode="r")[:], np.arange(12))
54```
56ObjectStore is a separate obstore-backed adapter. Optional `obstore==0.11.1` was exercised
57locally; its provider credential configuration differs from fsspec.
59```python
60import numpy as np
61import zarr
62from obstore.store import MemoryStore as ObMemoryStore
63from zarr.storage import ObjectStore
65store = ObjectStore(ObMemoryStore())
66z = zarr.create_array(store, data=np.arange(6), chunks=(3,))
67np.testing.assert_array_equal(zarr.open_array(store, mode="r")[:], np.arange(6))
68```

Fsspec and ObjectStore

FsspecStore.from_url(url, storage_options=..., read_only=...) resolves the protocol and wraps supported synchronous filesystems when needed. Supplying an explicit filesystem to FsspecStore requires its async-compatible form. This native memory-protocol example checks the adapter without making a network request:

import numpy as np
import zarr
from zarr.storage import FsspecStore

store = FsspecStore.from_url("memory://zarr-skill-example")
z = zarr.create_array(store, data=np.arange(12), chunks=(4,))
np.testing.assert_array_equal(zarr.open_array(store, mode="r")[:], np.arange(12))

ObjectStore is a separate obstore-backed adapter. Optional obstore==0.11.1 was exercised locally; its provider credential configuration differs from fsspec.

import numpy as np
import zarr
from obstore.store import MemoryStore as ObMemoryStore
from zarr.storage import ObjectStore

store = ObjectStore(ObMemoryStore())
z = zarr.create_array(store, data=np.arange(6), chunks=(3,))
np.testing.assert_array_equal(zarr.open_array(store, mode="r")[:], np.arange(6))
Raw lines 39 to 69
70## S3, GCS and HTTP
72The following **illustrative remote examples** are source/API reviewed, not authenticated
73cloud tests. Replace placeholders only with the intended authorized bucket and prefix.
74Prefer read-only opens first; never put keys/tokens in notebooks, logs or attributes.
76```python
77# Illustrative remote: needs authorized existing stores and network access.
78import zarr
79from zarr.storage import FsspecStore
81s3_store = FsspecStore.from_url(
82 "s3://my-bucket/path/data.zarr", storage_options={"anon": False}, read_only=True,
84s3_group = zarr.open_group(s3_store, mode="r", use_consolidated=False)
85gcs_array = zarr.open_array(
86 "gs://my-bucket/path/array.zarr", mode="r",
87 storage_options={"project": "my-project", "token": "google_default"},
89# Known array path: HTTP directory listing is not required for this bounded read.
90http_array = zarr.open_array("https://example.org/array.zarr", mode="r")
91subset = http_array[:10]
92```
94| Backend | URI/options and authentication | I/O contract |
95|---|---|---|
96| S3 / s3fs 2026.9.0 | `s3://bucket/key`; `anon=False` uses SDK credentials (roles/profiles preferred), `anon=True` for public buckets. Optional `endpoint_url` is an explicitly supplied S3-compatible endpoint, not a bucket path. | SDK GetObject byte/range reads, PutObject writes, HeadObject metadata, ListObjectsV2 pagination. Signed requests use the backend's region/credential configuration. |
97| GCS / gcsfs 2026.8.1 | `gs://bucket/key` or `gcs://`; `token="google_default"` selects application-default credentials, `token="anon"` public access. `project` identifies the project, not authorization. | Backend object metadata/list/media requests; listing follows `nextPageToken`/`pageToken`. Writes may use multipart/resumable upload. |
98| HTTP(S) / fsspec | Existing array or consolidated hierarchy URL; install remote dependencies. Server must support the required object and byte-range access. | Read-only HTTP GET/HEAD; no generic directory listing or write API is implied. Servers ignoring Range may force full-object reads or fail. |
100Zarr has no universal hosted REST service, API key, pagination parameter or JSON query
101endpoint. The backend handles object requests and pagination; metadata JSON and encoded
102chunk bytes are distinct payloads. FsspecStore maps missing objects to missing chunks;
103authentication/network failures must not be interpreted as scientific missing values.
104Source review covers these backend contracts; no public example bucket, credentials,
105remote write, permission policy, or object-version snapshot was validated here.
107Use immutable/versioned prefixes for completed outputs when consistency matters. Listing,
108metadata consolidation, append and multi-object writes do not form a transaction.
109Consolidation requires a **group**, not an array root; see [integration](integration.md).
111Sources: [Zarr stores](https://zarr.readthedocs.io/en/stable/user-guide/storage/),
112[s3fs](https://s3fs.readthedocs.io/en/latest/), [gcsfs](https://gcsfs.readthedocs.io/en/latest/),
113[fsspec HTTP](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.implementations.http.HTTPFileSystem).

S3, GCS and HTTP

The following illustrative remote examples are source/API reviewed, not authenticated cloud tests. Replace placeholders only with the intended authorized bucket and prefix. Prefer read-only opens first; never put keys/tokens in notebooks, logs or attributes.

# Illustrative remote: needs authorized existing stores and network access.
import zarr
from zarr.storage import FsspecStore

s3_store = FsspecStore.from_url(
    "s3://my-bucket/path/data.zarr", storage_options={"anon": False}, read_only=True,
)
s3_group = zarr.open_group(s3_store, mode="r", use_consolidated=False)
gcs_array = zarr.open_array(
    "gs://my-bucket/path/array.zarr", mode="r",
    storage_options={"project": "my-project", "token": "google_default"},
)
# Known array path: HTTP directory listing is not required for this bounded read.
http_array = zarr.open_array("https://example.org/array.zarr", mode="r")
subset = http_array[:10]
BackendURI/options and authenticationI/O contract
S3 / s3fs 2026.9.0s3://bucket/key; anon=False uses SDK credentials (roles/profiles preferred), anon=True for public buckets. Optional endpoint_url is an explicitly supplied S3-compatible endpoint, not a bucket path.SDK GetObject byte/range reads, PutObject writes, HeadObject metadata, ListObjectsV2 pagination. Signed requests use the backend's region/credential configuration.
GCS / gcsfs 2026.8.1gs://bucket/key or gcs://; token="google_default" selects application-default credentials, token="anon" public access. project identifies the project, not authorization.Backend object metadata/list/media requests; listing follows nextPageToken/pageToken. Writes may use multipart/resumable upload.
HTTP(S) / fsspecExisting array or consolidated hierarchy URL; install remote dependencies. Server must support the required object and byte-range access.Read-only HTTP GET/HEAD; no generic directory listing or write API is implied. Servers ignoring Range may force full-object reads or fail.

Zarr has no universal hosted REST service, API key, pagination parameter or JSON query endpoint. The backend handles object requests and pagination; metadata JSON and encoded chunk bytes are distinct payloads. FsspecStore maps missing objects to missing chunks; authentication/network failures must not be interpreted as scientific missing values. Source review covers these backend contracts; no public example bucket, credentials, remote write, permission policy, or object-version snapshot was validated here.

Use immutable/versioned prefixes for completed outputs when consistency matters. Listing, metadata consolidation, append and multi-object writes do not form a transaction. Consolidation requires a group, not an array root; see integration.

Sources: Zarr stores, s3fs, gcsfs, fsspec HTTP.

Raw lines 70 to 113