Codec¶
Zarr v3 codecs for array-to-array, array-to-bytes, and bytes-to-bytes transforms.
ArrayToArrayCodec ¶
A Zarr v3 array-to-array codec.
decode ¶
decode(
value: ArrayBytes,
/,
shape: list[int],
data_type: DataType,
fill_value: FillValue,
) -> ArrayBytes
Decode chunk bytes with this codec.
Parameters:
-
value(ArrayBytes) –The encoded chunk bytes.
-
shape(list[int]) –The shape of the encoded chunk, in elements along each dimension.
-
data_type(DataType) –The data type of the encoded chunk.
-
fill_value(FillValue) –The fill value of the encoded chunk.
Returns:
-
ArrayBytes–The decoded chunk bytes.
Raises:
-
CodecError–If
valuedoes not agree withshapeanddata_type, or if the codec cannot decode the chunk.
decoded_shape ¶
encode ¶
encode(
value: ArrayBytes,
/,
shape: list[int],
data_type: DataType,
fill_value: FillValue,
) -> ArrayBytes
Encode chunk bytes with this codec.
Parameters:
-
value(ArrayBytes) –The decoded chunk bytes.
-
shape(list[int]) –The shape of the decoded chunk, in elements along each dimension.
-
data_type(DataType) –The data type of the decoded chunk.
-
fill_value(FillValue) –The fill value of the decoded chunk.
Returns:
-
ArrayBytes–The encoded chunk bytes.
Raises:
-
CodecError–If
valuedoes not agree withshapeanddata_type, or if the codec cannot encode the chunk.
encoded_data_type ¶
encoded_fill_value ¶
encoded_shape ¶
Return the chunk shape that this codec produces when it encodes.
Parameters:
Returns:
Raises:
-
CodecError–If
decoded_shapehas a number of dimensions that the codec does not support.
from_config
staticmethod
¶
from_config(metadata: JSONValue) -> ArrayToArrayCodec
Construct a codec from its Zarr v3 metadata.
Parameters:
-
metadata(JSONValue) –The Zarr v3 metadata of the codec, for example
{"name": "transpose", "configuration": {"order": [1, 0]}}.
Returns:
-
ArrayToArrayCodec–The new codec.
Raises:
-
PluginCreateError–If the metadata names an unsupported codec, or if the configuration is not valid for that codec.
ArrayToBytesCodec ¶
A Zarr v3 array-to-bytes codec (the "serializer").
name
property
¶
name: str | None
The codec's Zarr v3 name (e.g. "bytes", "sharding_indexed"), if any.
from_config
staticmethod
¶
from_config(metadata: JSONValue) -> ArrayToBytesCodec
Construct a codec from its Zarr v3 metadata.
Parameters:
-
metadata(JSONValue) –The Zarr v3 metadata of the codec, for example
{"name": "bytes", "configuration": {"endian": "little"}}.
Returns:
-
ArrayToBytesCodec–The new codec.
Raises:
-
PluginCreateError–If the metadata names an unsupported codec, or if the configuration is not valid for that codec.
BytesToBytesCodec ¶
A Zarr v3 bytes-to-bytes codec.
encode ¶
from_config
staticmethod
¶
from_config(metadata: JSONValue) -> BytesToBytesCodec
Construct a codec from its Zarr v3 metadata.
Parameters:
-
metadata(JSONValue) –The Zarr v3 metadata of the codec, for example
{"name": "gzip", "configuration": {"level": 5}}.
Returns:
-
BytesToBytesCodec–The new codec.
Raises:
-
PluginCreateError–If the metadata names an unsupported codec, or if the configuration is not valid for that codec.
CodecChain ¶
A full Zarr v3 codec pipeline.
A codec chain holds:
- the array-to-array codecs ("filters")
- one array-to-bytes codec ("serializer")
- the bytes-to-bytes codecs ("compressors")
The chain applies them in that order to encode, and in the reverse order to decode.
An array carries the codec chain that encodes its chunks. To decode chunk
bytes with it, use EncodedChunk, which holds the
bytes and the chain together.
compressors
property
¶
compressors: list[BytesToBytesCodec]
The bytes-to-bytes codecs ("compressors").
serializer
property
¶
serializer: ArrayToBytesCodec
The array-to-bytes codec ("serializer").
For a sharded array, this is the sharding_indexed codec.
bitround ¶
bitround(keepbits: int) -> ArrayToArrayCodec
Construct a bit-rounding codec that keeps keepbits mantissa bits.
Parameters:
-
keepbits(int) –The number of mantissa bits to keep.
Returns:
-
ArrayToArrayCodec–The new codec.
Raises:
-
OverflowError–If
keepbitsis negative.
blosc ¶
blosc(
cname: BloscCompressor,
clevel: int,
shuffle_mode: BloscShuffle,
*,
blocksize: int | None = None,
typesize: int | None = None
) -> BytesToBytesCodec
Construct a blosc codec from its parameters.
Parameters:
-
cname(BloscCompressor) –The name of the internal compressor.
-
clevel(int) –The compression level, from 0 (no compression) to 9 (most compression).
-
shuffle_mode(BloscShuffle) –The shuffle mode to apply before compression.
Keyword Arguments:
-
blocksize(int | None) –The block size in bytes. Give
Noneor0to let blosc choose the block size. -
typesize(int | None) –The size of one element in bytes. This must be a positive integer if
shuffle_modeis not"noshuffle".
Returns:
-
BytesToBytesCodec–The new codec.
Raises:
-
ValueError–If
cnameis not a known compressor, or ifclevelis outside the range 0 to 9. -
PluginCreateError–If
shuffle_modeis not"noshuffle"andtypesizeisNoneor0.
crc32c ¶
crc32c() -> BytesToBytesCodec
Construct a crc32c codec.
The codec appends a CRC32C checksum to the encoded bytestream.
Returns:
-
BytesToBytesCodec–The new codec.
gzip ¶
gzip(level: int) -> BytesToBytesCodec
Construct a gzip codec.
Parameters:
-
level(int) –The compression level, from 0 (no compression) to 9 (most compression).
Returns:
-
BytesToBytesCodec–The new codec.
Raises:
-
ValueError–If
levelis more than 9. -
OverflowError–If
levelis negative.
transpose ¶
transpose(order: list[int]) -> ArrayToArrayCodec
Construct a transpose codec with the given axis order.
Parameters:
-
order(list[int]) –The new order of the axes. This must be a permutation of the axis indices, from 0 to one less than the number of dimensions.
Returns:
-
ArrayToArrayCodec–The new codec.
Raises:
-
TransposeOrderError–If
orderis not a permutation of the axis indices.
zstd ¶
zstd(level: int, checksum: bool) -> BytesToBytesCodec
Construct a zstd codec.
Parameters:
-
level(int) –The compression level. The codec does not check the range, and zstd clamps the value to the range that it supports.
-
checksum(bool) –Whether to write a checksum to the encoded bytestream. The codec verifies this checksum when it decodes the bytestream.
Returns:
-
BytesToBytesCodec–The new codec.
zarrista.codec.CodecOptions ¶
Bases: TypedDict
Per-operation codec options for encoding and decoding.
These control runtime behaviour such as concurrency limits and checksum
validation. They are passed as keyword arguments to the array read/write
methods, e.g. arr.retrieve_chunk([0, 0], validate_checksums=False). All
keys are optional; omitted keys fall back to the defaults noted below.
Not importable at runtime
To use this type hint in your code, import it within a TYPE_CHECKING
block:
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from zarrista.codec import CodecOptions
chunk_concurrent_minimum
instance-attribute
¶
chunk_concurrent_minimum: int
Preferred minimum chunk concurrency for multi-chunk operations. The
concurrency of internal codecs is adjusted to accommodate the chunk
concurrency in accordance with concurrent_target. Defaults to 4.
concurrent_target
instance-attribute
¶
concurrent_target: int
Preferred number of concurrent operations. Defaults to the number of threads in the Rust thread pool.
experimental_partial_encoding
instance-attribute
¶
experimental_partial_encoding: bool
Whether to use experimental partial encoding. Defaults to False.
Codec configuration types¶
zarrista.codec._bytes_to_bytes._blosc.BloscCompressor
module-attribute
¶
A blosc compressor name.