-
-
Notifications
You must be signed in to change notification settings - Fork 331
docs: add docs on extending zarr 3 #2597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2bf2069
docs: add docs on extending zarr 3
jhamman 0f2405f
Apply suggestions from code review
normanrz 134cd41
move note up
normanrz 2998561
remove test.py (#2612)
d-v-b 44fbcef
Merge branch 'docs/3.0-user-guide' into docs/3.0-extending
dstansby b9699f5
Note that whole directories can be deleted in LocalStore (#2606)
dstansby 2535503
fix: run-coverage command now tracks src directory (#2615)
jhamman 8441baa
Merge branch 'docs/3.0-user-guide' into docs/3.0-extending
normanrz 72501b6
Merge remote-tracking branch 'origin/main' into docs/3.0-extending
normanrz 029c23e
fix doc build
normanrz 8b7da42
Update docs/user-guide/extending.rst
d-v-b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
Extending Zarr | ||
============== | ||
|
||
Zarr-Python 3 was designed to be extensible. This means that you can extend | ||
the library by writing custom classes and plugins. Currently, Zarr can be extended | ||
in the following ways: | ||
|
||
Custom codecs | ||
------------- | ||
|
||
.. note:: | ||
This section explains how custom codecs can be created for Zarr version 3 data. For Zarr | ||
version 2, codecs should subclass the | ||
`numcodecs.abc.Codec <https://numcodecs.readthedocs.io/en/stable/abc.html#numcodecs.abc.Codec>`_ | ||
base class and register through | ||
`numcodecs.registry.register_codec <https://numcodecs.readthedocs.io/en/stable/registry.html#numcodecs.registry.register_codec>`_. | ||
|
||
There are three types of codecs in Zarr: | ||
- array-to-array | ||
- array-to-bytes | ||
- bytes-to-bytes | ||
|
||
Array-to-array codecs are used to transform the array data before serializing | ||
to bytes. Examples include delta encoding or scaling codecs. Array-to-bytes codecs are used | ||
for serializing the array data to bytes. In Zarr, the main codec to use for numeric arrays | ||
is the :class:`zarr.codecs.BytesCodec`. Bytes-to-bytes codecs transform the serialized bytestreams | ||
of the array data. Examples include compression codecs, such as | ||
:class:`zarr.codecs.GzipCodec`, :class:`zarr.codecs.BloscCodec` or | ||
:class:`zarr.codecs.ZstdCodec`, and codecs that add a checksum to the bytestream, such as | ||
:class:`zarr.codecs.Crc32cCodec`. | ||
|
||
Custom codecs for Zarr are implemented by subclassing the relevant base class, see | ||
:class:`zarr.abc.codec.ArrayArrayCodec`, :class:`zarr.abc.codec.ArrayBytesCodec` and | ||
:class:`zarr.abc.codec.BytesBytesCodec`. Most custom codecs should implemented the | ||
``_encode_single`` and ``_decode_single`` methods. These methods operate on single chunks | ||
of the array data. Alternatively, custom codecs can implement the ``encode`` and ``decode`` | ||
methods, which operate on batches of chunks, in case the codec is intended to implement | ||
its own batch processing. | ||
|
||
Custom codecs should also implement the following methods: | ||
|
||
- ``compute_encoded_size``, which returns the byte size of the encoded data given the byte | ||
size of the original data. It should raise ``NotImplementedError`` for codecs with | ||
variable-sized outputs, such as compression codecs. | ||
- ``validate`` (optional), which can be used to check that the codec metadata is compatible with the | ||
array metadata. It should raise errors if not. | ||
- ``resolve_metadata`` (optional), which is important for codecs that change the shape, | ||
dtype or fill value of a chunk. | ||
- ``evolve_from_array_spec`` (optional), which can be useful for automatically filling in | ||
codec configuration metadata from the array metadata. | ||
|
||
To use custom codecs in Zarr, they need to be registered using the | ||
`entrypoint mechanism <https://packaging.python.org/en/latest/specifications/entry-points/>`_. | ||
Commonly, entrypoints are declared in the ``pyproject.toml`` of your package under the | ||
``[project.entry-points."zarr.codecs"]`` section. Zarr will automatically discover and | ||
load all codecs registered with the entrypoint mechanism from imported modules. | ||
|
||
.. code-block:: toml | ||
|
||
[project.entry-points."zarr.codecs"] | ||
"custompackage.fancy_codec" = "custompackage:FancyCodec" | ||
|
||
New codecs need to have their own unique identifier. To avoid naming collisions, it is | ||
strongly recommended to prefix the codec identifier with a unique name. For example, | ||
the codecs from ``numcodecs`` are prefixed with ``numcodecs.``, e.g. ``numcodecs.delta``. | ||
|
||
.. note:: | ||
Note that the extension mechanism for the Zarr version 3 is still under development. | ||
Requirements for custom codecs including the choice of codec identifiers might | ||
change in the future. | ||
|
||
It is also possible to register codecs as replacements for existing codecs. This might be | ||
useful for providing specialized implementations, such as GPU-based codecs. In case of | ||
multiple codecs, the :mod:`zarr.core.config` mechanism can be used to select the preferred | ||
implementation. | ||
|
||
Custom stores | ||
------------- | ||
|
||
Coming soon. | ||
|
||
Custom array buffers | ||
-------------------- | ||
|
||
Coming soon. | ||
|
||
Other extensions | ||
---------------- | ||
|
||
In the future, Zarr will support writing custom custom data types and chunk grids. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,8 @@ Advanced Topics | |
|
||
performance | ||
consolidated_metadata | ||
extending | ||
|
||
|
||
.. Coming soon | ||
async | ||
extending |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.