diff --git a/docs/user-guide/extending.rst b/docs/user-guide/extending.rst index 637981b84..230a8eca2 100644 --- a/docs/user-guide/extending.rst +++ b/docs/user-guide/extending.rst @@ -68,8 +68,6 @@ useful for providing specialized implementations, such as GPU-based codecs. In c multiple codecs, the :mod:`zarr.core.config` mechanism can be used to select the preferred implementation. -TODO: Link to documentation of :mod:`zarr.core.config` - .. note:: This sections explains how custom codecs can be created for Zarr version 3. For Zarr version 2, codecs should subclass the diff --git a/docs/user-guide/v3_migration.rst b/docs/user-guide/v3_migration.rst index 3cf98564a..d353ae239 100644 --- a/docs/user-guide/v3_migration.rst +++ b/docs/user-guide/v3_migration.rst @@ -138,7 +138,7 @@ Configuration ~~~~~~~~~~~~~ There is a new configuration system based on `donfig `_, -which can be accessed via :data:`zarr.config`. +which can be accessed via :mod:`zarr.core.config`. Configuration values can be set using code like the following: .. code-block:: python diff --git a/src/zarr/core/config.py b/src/zarr/core/config.py index 29f5e139f..ecda9af7e 100644 --- a/src/zarr/core/config.py +++ b/src/zarr/core/config.py @@ -1,3 +1,64 @@ +""" +The config module is responsible for managing the configuration of zarr +and is based on the `donfig `_ Python library. + +Configuration values can be set using code like the following: + +.. code-block:: python + + import zarr + zarr.config.set({"array.order": "F"}) + +Alternatively, configuration values can be set using environment variables, e.g. +``ZARR_ARRAY__ORDER=F``. + +The configuration can also be read from a YAML file in standard locations. +For more information, see the +`donfig documentation `_. + +Configuration options include the following: + +- Default Zarr format ``default_zarr_version`` +- Default array order in memory ``array.order`` +- Async and threading options, e.g. ``async.concurrency`` and ``threading.max_workers`` +- Selections of implementations of codecs, codec pipelines and buffers + +For selecting custom implementations of codecs, pipelines, buffers and ndbuffers, +first register the implementations in the registry and then select them in the config. +For example, an implementation of the bytes codec in a class "custompackage.NewBytesCodec", +requires the value of ``codecs.bytes.name`` to be "custompackage.NewBytesCodec". + +This is the current default configuration: + +.. code-block:: python + + { + "default_zarr_version": 3, + "array": {"order": "C"}, + "async": {"concurrency": 10, "timeout": None}, + "threading": {"max_workers": None}, + "json_indent": 2, + "codec_pipeline": { + "path": "zarr.core.codec_pipeline.BatchedCodecPipeline", + "batch_size": 1, + }, + "codecs": { + "blosc": "zarr.codecs.blosc.BloscCodec", + "gzip": "zarr.codecs.gzip.GzipCodec", + "zstd": "zarr.codecs.zstd.ZstdCodec", + "bytes": "zarr.codecs.bytes.BytesCodec", + "endian": "zarr.codecs.bytes.BytesCodec", + "crc32c": "zarr.codecs.crc32c_.Crc32cCodec", + "sharding_indexed": "zarr.codecs.sharding.ShardingCodec", + "transpose": "zarr.codecs.transpose.TransposeCodec", + "vlen-utf8": "zarr.codecs.vlen_utf8.VLenUTF8Codec", + "vlen-bytes": "zarr.codecs.vlen_utf8.VLenBytesCodec", + }, + "buffer": "zarr.core.buffer.cpu.Buffer", + "ndbuffer": "zarr.core.buffer.cpu.NDBuffer", + } +""" + from __future__ import annotations from typing import Any, Literal, cast