diff --git a/doc/user-guide/io.rst b/doc/user-guide/io.rst index 84cd1d97323..55fbbac7873 100644 --- a/doc/user-guide/io.rst +++ b/doc/user-guide/io.rst @@ -1105,6 +1105,13 @@ For example: compressor = BloscCodec(cname="zstd", clevel=3, shuffle="shuffle") ds.to_zarr(zarr_filename, consolidated=False, encoding={"foo": {"compressors": [compressor]}}) +For Zarr v3, xarray forwards codec configuration in each variable's +``encoding`` dictionary to zarr-python. Use ``compressors`` for bytes-to-bytes +codecs and ``serializer`` for array-to-bytes codecs, with codec objects and +configuration following zarr-python. Other Zarr v3 metadata options accepted by +xarray include ``filters``, ``shards``, ``fill_value``, and +``chunk_key_encoding``. + .. note:: Not all native zarr compression and filtering options have been tested with diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index a046c5d0f9e..75a6dc1c163 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -2263,6 +2263,10 @@ def to_zarr( Nested dictionary with variable names as keys and dictionaries of variable specific encodings as values, e.g., ``{"my_variable": {"dtype": "int16", "scale_factor": 0.1,}, ...}`` + Zarr-specific options such as ``chunks``, ``compressor``, + ``compressors``, ``filters``, ``serializer``, ``shards``, and + ``chunk_key_encoding`` may also be provided. See the Zarr encoding + section in the I/O user guide for details. compute : bool, default: True If True write array data immediately, otherwise return a ``dask.delayed.Delayed`` object that can be computed to write