Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/zarr-storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ jobs:
- name: Run ruff
run: just lint

mypy:
name: mypy
typecheck:
name: mypy and pyright
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -107,7 +107,7 @@ jobs:
with:
repo: casey/just
version: 1.58.0
- name: Run mypy
- name: Run mypy and pyright
run: just typecheck

legacy-in-sync:
Expand Down Expand Up @@ -158,7 +158,7 @@ jobs:

zarr-storage-complete:
name: zarr-storage complete
needs: [test, ruff, mypy, legacy-in-sync, docs]
needs: [test, ruff, typecheck, legacy-in-sync, docs]
if: always()
runs-on: ubuntu-latest
steps:
Expand Down
478 changes: 478 additions & 0 deletions packages/zarr-storage/DESIGN.md

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions packages/zarr-storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ store API is developed
memory, local files, zip files, fsspec and obstore. The module `zarr.X` is
`zarr_storage.legacy.X`. The package does not depend on `zarr`.

`zarr_storage.experimental` is the API meant to succeed it: sync and async stores
over memory, local-filesystem and object-store backends, with conditional writes,
byte-range reads, batches, and a conformance suite any backend can run. Any
release may change it. [`DESIGN.md`](https://github.com/zarr-developers/zarr-python/blob/main/packages/zarr-storage/DESIGN.md)
describes it.

Use `zarr.storage` with `zarr` for now. Until `zarr` depends on this package,
`zarr_storage.legacy` is a copy with classes of its own, and `zarr` does not
accept its stores. It reads zarr's entry-point groups, so a URL pipeline adapter or
Expand All @@ -17,8 +23,9 @@ buffer class written for `zarr` doesn't work with it yet either.
pip install zarr-storage
```

The `remote` extra adds fsspec and obstore, and the `testing` extra adds what the
store conformance suite needs.
The `remote` extra adds fsspec and obstore for the legacy stores, the `obstore`
extra adds the newer obstore that the experimental API needs, and the `testing`
extra adds what the conformance suites need.

- Documentation: https://zarr-storage.readthedocs.io/
- Changelog: [`CHANGELOG.md`](https://github.com/zarr-developers/zarr-python/blob/main/packages/zarr-storage/CHANGELOG.md)
Expand Down
1 change: 1 addition & 0 deletions packages/zarr-storage/changes/491.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `zarr_storage.experimental`, the store API meant to succeed `zarr_storage.legacy`: `Store` and `AsyncStore` views over memory, local-filesystem and obstore backends, with the same operations as sync methods and as coroutines, conditional reads and writes, byte-range reads, reads into caller buffers, batches, and contexts that hold thread pools and limits. `zarr_storage.experimental.testing` has a conformance suite that any backend can run. Any release may change this API.
5 changes: 5 additions & 0 deletions packages/zarr-storage/docs/api/experimental.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: experimental
---

::: zarr_storage.experimental
5 changes: 5 additions & 0 deletions packages/zarr-storage/docs/api/experimental_backends.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: experimental.backends
---

::: zarr_storage.experimental.backends
5 changes: 5 additions & 0 deletions packages/zarr-storage/docs/api/experimental_testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: experimental.testing
---

::: zarr_storage.experimental.testing
8 changes: 8 additions & 0 deletions packages/zarr-storage/docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ title: API reference
its stores.
- [`zarr_storage.legacy.testing`](legacy_testing.md): the conformance suite a
store implementation runs (needs the `testing` extra).
- [`zarr_storage.experimental`](experimental.md): `Store` and `AsyncStore`, the
result types, byte-range requests, errors, the capability protocols a backend
implements, and `Context` with its resources.
- [`zarr_storage.experimental.backends`](experimental_backends.md):
`MemoryBackend`, `LocalBackend`, and `ObjectStoreBackend` (needs the `obstore`
extra).
- [`zarr_storage.experimental.testing`](experimental_testing.md): the conformance
suite a backend runs (needs the `testing` extra).
4 changes: 4 additions & 0 deletions packages/zarr-storage/docs/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- DESIGN.md at the package root is the single source of truth for the
design; this page includes it so the docs site renders it. -->

--8<-- "DESIGN.md"
60 changes: 60 additions & 0 deletions packages/zarr-storage/docs/experimental.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# The experimental API

`zarr_storage.experimental` is a key-value storage layer that knows nothing about
the Zarr format: it stores and lists values under `/`-separated keys, and leaves
arrays, groups and metadata documents to the Zarr implementation built on it. It
is meant to succeed `zarr_storage.legacy`.

!!! warning "Experimental"
Any release may change this API. `zarr` doesn't use it yet.

The `obstore` extra adds `ObjectStoreBackend` (S3, GCS, Azure, HTTP and more,
through [obstore](https://developmentseed.org/obstore/)), and the `testing`
extra adds the conformance suite.

## Quickstart

A `Store` is a view of a backend at a root directory. Results are small frozen
types, one per outcome, so a `match` handles each:

```python
from zarr_storage.experimental import Found, Missing, Store
from zarr_storage.experimental.backends import MemoryBackend

store = Store(MemoryBackend())
store.put("data/a", b"hello")
match store.get("data/a"):
case Found(value=value):
print(bytes(value)) # b'hello'
case Missing():
print("absent")

sub = store / "data" # a view on the same backend
print(list(sub.list())) # ['a']
```

Conditional operations are separate methods that report a refusal instead of
raising:

```python
found = store.get("data/a")
store.put_if_absent("data/a", b"again") # Rejected(...)
store.put_if_match("data/a", b"new", found.generation) # Written(...)
```

`AsyncStore` has the same methods as coroutines, and `store.as_async()` is an
`AsyncStore` view on the same backend:

```python
astore = store.as_async()
await astore.put("x", b"1")
print(await astore.get("x"))
```

The store that was constructed owns its backend: `store.close()` (or a `with`
block) closes it, and closing a view such as `sub` or `astore` does nothing.

## Where to go next

- [Design](design.md): the contract every backend and store meets.
- [API reference](api/index.md).
7 changes: 5 additions & 2 deletions packages/zarr-storage/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ pip install zarr-storage
```

The `remote` extra adds fsspec and obstore, for `FsspecStore` and `ObjectStore`.
The `testing` extra adds what the store conformance suite needs.
The `obstore` extra adds the newer obstore that the experimental API needs. The
`testing` extra adds what the conformance suites need.

## Use

Expand All @@ -43,4 +44,6 @@ async def main() -> None:
asyncio.run(main())
```

See the [API reference](api/index.md).
The next store API is being developed in
[`zarr_storage.experimental`](experimental.md). See also the
[API reference](api/index.md).
3 changes: 2 additions & 1 deletion packages/zarr-storage/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ test-versions *args:
lint:
uvx ruff@{{ ruff_version }} check .

# Type-check the package sources
# Type-check the package: the legacy code with mypy, as zarr does, the rest with pyright
typecheck:
uv run --python 3.12 --group test --with mypy=={{ mypy_version }} mypy
uv run --python 3.12 --group test --with pyright pyright

# Copy the store code of `src/zarr` to `zarr_storage.legacy`; with --check, only report differences
sync-legacy *args:
Expand Down
5 changes: 5 additions & 0 deletions packages/zarr-storage/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ validation:

nav:
- index.md
- The experimental API: experimental.md
- Design: design.md
- API Reference:
- api/index.md
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_storage.legacy</code>': api/legacy.md
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_storage.legacy.testing</code>': api/legacy_testing.md
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_storage.experimental</code>': api/experimental.md
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_storage.experimental.backends</code>': api/experimental_backends.md
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_storage.experimental.testing</code>': api/experimental_testing.md
- Release notes: release-notes.md
# This site is a Read the Docs subproject of zarr-python; give readers a way
# back to the parent docs, which list every companion package.
Expand Down
47 changes: 41 additions & 6 deletions packages/zarr-storage/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ dependencies = [
[project.optional-dependencies]
# `FsspecStore` and `ObjectStore`, with zarr's floors.
remote = ["fsspec>=2023.10.0", "obstore>=0.5.1"]
# The `zarr_storage.legacy.testing` conformance suite.
# `zarr_storage.experimental.backends.ObjectStoreBackend`.
obstore = ["obstore>=0.12"]
# The conformance suites in `zarr_storage.legacy.testing` and `zarr_storage.experimental.testing`.
testing = ["pytest>=9", "pytest-asyncio>=1.0", "hypothesis>=6.160"]

[project.entry-points.pytest11]
Expand All @@ -59,7 +61,7 @@ test = [
"pytest>=9",
"pytest-asyncio>=1.0",
"fsspec>=2023.10.0",
"obstore>=0.5.1",
"obstore>=0.12",
"universal-pathlib",
"hypothesis>=6.160",
# `FsspecStore` against a mock S3 server.
Expand Down Expand Up @@ -102,6 +104,7 @@ include = [
"/mkdocs.yml",
"/justfile",
"/CHANGELOG.md",
"/DESIGN.md",
]
# The shared docs config and header script are symlinks out of the package
# directory in the repository; ship the files they point at, since a link out
Expand All @@ -116,15 +119,26 @@ exclude = ["/mkdocs-base.yml", "/docs/_static/source-version.js"]
extend = "../../pyproject.toml"
target-version = "py312"

# As zarr's own tests, which these are copies of.
[tool.ruff.lint]
# Use `object` for "any value"; a genuinely dynamic annotation needs a noqa
# saying why. The legacy code is zarr's, which doesn't have this rule.
extend-select = ["ANN401"]

[tool.ruff.lint.extend-per-file-ignores]
"tests/legacy/**" = ["ANN001", "ANN201", "E402", "SIM117"]
"src/zarr_storage/legacy/**" = ["ANN401"]
# Written with `TypeVar`s: `Store` is covariant in its backend, and its methods' `self` types share
# the variables.
"src/zarr_storage/experimental/**" = ["UP046", "UP047"]
# As zarr's own tests, which these are copies of.
"tests/legacy/**" = ["ANN001", "ANN201", "ANN401", "E402", "SIM117"]

[tool.pytest.ini_options]
minversion = "9"
testpaths = ["tests"]
strict = true
addopts = ["-ra", "--import-mode=importlib"]
# So processes that tests spawn can import the test modules.
pythonpath = ["."]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
faulthandler_timeout = 600
Expand All @@ -145,9 +159,30 @@ markers = [
"s3: mark a test as requiring a (mock) S3 backend via moto",
]

# The root configuration: the code is zarr's, checked there with mypy.
# Pyright checks the experimental API. The legacy code is zarr's, and is checked with mypy, as it
# is there.
[tool.pyright]
include = ["src/zarr_storage/experimental", "tests/experimental"]
enableTypeIgnoreComments = false
reportUnnecessaryTypeIgnoreComment = "error"
extraPaths = ["."]
typeCheckingMode = "strict"
pythonVersion = "3.12"

[[tool.pyright.executionEnvironments]]
root = "tests"
reportMissingTypeArgument = false
reportPrivateUsage = false
reportUnknownArgumentType = false
reportUnknownLambdaType = false
reportUnknownMemberType = false
reportUnknownParameterType = false
reportUnknownVariableType = false
reportUnusedFunction = false

# The root configuration.
[tool.mypy]
files = ["src"]
files = ["src/zarr_storage/__init__.py", "src/zarr_storage/_pytest_plugin.py", "src/zarr_storage/legacy"]
python_version = "3.12"
ignore_missing_imports = true
namespace_packages = false
Expand Down
1 change: 1 addition & 0 deletions packages/zarr-storage/src/zarr_storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Storage for Zarr implementations.

`zarr_storage.legacy` holds the store API of zarr-python 3 and its stores.
`zarr_storage.experimental` holds the API meant to succeed it; it may change in any release.
"""

from importlib.metadata import version
Expand Down
Loading