zarr_metadata.v3.codec
zarr_metadata.v3.codec ¶
Zarr v3 codec spec types.
Each codec defined by the spec or by zarr-extensions has its own submodule
(blosc, bytes, cast_value, crc32c, gzip, scale_offset,
sharding_indexed, transpose, zstd).
The <X>CodecMetadata aliases re-exported here are the canonical type for
each codec's permitted JSON shapes (object form plus, where the spec allows,
a bare-string short-hand form). For the underlying <X>CodecObject,
<X>CodecConfiguration, etc., import directly from the leaf submodule.
For the field-level "any codec entry" alias (used in array metadata's
codecs list and in sharding's inner pipelines), import ZarrV3MetadataFieldJSON
from zarr_metadata.v3.
The kind submodule sorts the known codec names into the spec's three
pipeline kinds (array -> array, array -> bytes, bytes -> bytes).
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/index.html
zarr_metadata.v3.codec.blosc ¶
Blosc codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/blosc/index.html
BLOSC_CNAME
module-attribute
¶
BLOSC_CNAME: Final = (
"lz4",
"lz4hc",
"blosclz",
"snappy",
"zlib",
"zstd",
)
Tuple of permitted values for the cname field of the blosc codec.
BLOSC_CODEC_NAME
module-attribute
¶
BLOSC_CODEC_NAME: Final = 'blosc'
The name field value of the blosc codec.
BLOSC_NO_SHUFFLE
module-attribute
¶
BLOSC_NO_SHUFFLE: Final = 'noshuffle'
The shuffle value under which typesize carries no information.
The spec requires typesize "unless shuffle is "noshuffle", in which
case the value is ignored", so this is the one value that changes whether
another member is required.
BLOSC_SHUFFLE
module-attribute
¶
BLOSC_SHUFFLE: Final = (
"noshuffle",
"shuffle",
"bitshuffle",
)
Tuple of permitted values for the shuffle field of the blosc codec.
BloscCName
module-attribute
¶
BloscCName = Literal[
"lz4", "lz4hc", "blosclz", "snappy", "zlib", "zstd"
]
Literal type of blosc compressor identifiers.
BloscCodecMetadata
module-attribute
¶
BloscCodecMetadata = BloscCodecObject
Permitted JSON shape for blosc codec metadata.
The configuration has multiple required keys (cname, clevel, shuffle,
blocksize), so only the object form is valid; the short-hand-name form
is not permitted by the spec for this codec.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/blosc/index.rst#L57-L98 (configuration parameters)
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564 (short-hand names only "if no configuration metadata is required")
BloscCodecName
module-attribute
¶
BloscCodecName = Literal['blosc']
Literal type of the name field of the blosc codec.
BloscShuffle
module-attribute
¶
BloscShuffle = Literal["noshuffle", "shuffle", "bitshuffle"]
Literal type of blosc shuffle mode names.
__all__
module-attribute
¶
__all__ = [
"BLOSC_CNAME",
"BLOSC_CODEC_NAME",
"BLOSC_NO_SHUFFLE",
"BLOSC_SHUFFLE",
"BloscCName",
"BloscCodec",
"BloscCodecConfiguration",
"BloscCodecMetadata",
"BloscCodecName",
"BloscCodecObject",
"BloscShuffle",
"canonical_configuration",
]
BloscCodec
dataclass
¶
Bases: CodecEntity
The blosc codec, coerced from its metadata.
Everything blosc knows about itself: the shape its metadata takes, the values the spec allows in it, and the simplest spelling of an equivalent document.
Source code in src/zarr_metadata/v3/codec/blosc.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
configuration_required
class-attribute
¶
configuration_required: bool = True
Whether the bare-name spelling says too little for this entity.
The spec permits a bare name "if no configuration metadata is required", so this is true exactly when some member is required.
identifier
class-attribute
¶
identifier: str = BLOSC_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
member_types
class-attribute
¶
member_types: MemberTypes = {
"cname": (True, one_of(BLOSC_CNAME)),
"clevel": (True, is_int),
"shuffle": (True, one_of(BLOSC_SHUFFLE)),
"blocksize": (True, is_int),
"typesize": (False, is_int),
}
The configuration members, and the type each one takes.
The same keys as the configuration TypedDict, which is the same as the
constructor signature; tests/v3/test_entities.py holds the three
together.
must_understand
class-attribute
instance-attribute
¶
name
property
¶
name: str
The name this entity carries, as a document would write it.
Usually the identifier. They differ for the raw-bytes family,
whose identifier is invented and belongs in no message a reader
sees -- so anything user-facing wants this, and anything looking
something up wants identifier.
required_class_vars
class-attribute
¶
Every class variable a concrete entity of this kind must declare.
variable_size
class-attribute
¶
variable_size: bool = True
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read.
__init__ ¶
__init__(
cname: BloscCName = "zstd",
clevel: int = 5,
shuffle: BloscShuffle = "noshuffle",
blocksize: int = 0,
typesize: int | UNSET = UNSET,
*,
must_understand: bool = True,
) -> None
__init_subclass__ ¶
Refuse a subclass that forgot to say what it is.
identifier and the per-kind class variables carry no default,
so a subclass omitting one type-checks cleanly and then raises
AttributeError from whichever method is reached first. Saying so
here makes it an import-time error in the extension's own module.
base=True for a class that exists to add a class variable
rather than to be an entity -- CodecEntity, IntegerDataType.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
Without a typesize that noshuffle renders meaningless.
The spec says of that case that "the value is ignored", so two documents differing only there describe the same codec.
Source code in src/zarr_metadata/v3/codec/blosc.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one.
context is the scope this reading is happening in; most entities
have no use for it and ignore it.
Source code in src/zarr_metadata/v3/_entity.py
configuration ¶
This entity's configuration, as the document would write it.
Faithful to every member the entity holds: to_json is
serialization, not canonicalization, so nothing is simplified
here. Override only to render a member that is not already JSON,
such as a contained entity.
Absent optional members are left out, which is what makes the
bare-name spelling reachable. Absence is UNSET, never None:
this package holds None to mean a JSON null the document
actually wrote, and scale_offset is a real case where null
and absent are different documents.
Source code in src/zarr_metadata/v3/_entity.py
from_configuration
classmethod
¶
from_configuration(
**configuration: Unpack[BloscCodecConfiguration],
) -> Self
This codec from its configuration members.
The configuration TypedDict unpacked is this constructor's signature, so a caller with a well-typed configuration builds a well-typed codec, and a type checker says so at the call site.
Source code in src/zarr_metadata/v3/codec/blosc.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
Why this codec cannot be applied to the array that reaches it.
incoming is None once the chain can no longer say what reaches
here, and the default answer to that is nothing: declining beats
guessing. Locations are relative to this codec's configuration,
as problems' are; an empty one lands on the codec itself.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> tuple[ValidationProblem, ...]
The value constraints the spec places on a blosc configuration.
Source code in src/zarr_metadata/v3/codec/blosc.py
to_json ¶
to_json() -> BloscCodecObject
This entity as a document would write it.
Faithful to every member: read a document, write it back, and the
members come out as they went in. Ask canonical first if you
want the simplest equivalent spelling.
What is not preserved is the envelope's spelling, because the
entity does not model it: a bare name, {"name": x}, and
{"name": x, "configuration": {}} all mean the same and all read
to the same entity, so all three write back as the bare name.
must_understand is omitted when true, which is its default; an
explicit false is kept, because that one says something.
Subclasses narrow the return type to their own object TypedDict, which is the JSON form this dataclass models.
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
What the next codec in the chain sees, or None if undeterminable.
Only an array-to-array codec has anything to say: the two later kinds end shape propagation by construction, one by consuming the array and the other by never having had it.
The default is None, so a modelled codec that forgets to say how it transforms the array stops propagation rather than silently claiming to leave it alone. Failing closed here costs a judgment; failing open would invent one.
Source code in src/zarr_metadata/v3/_entity.py
BloscCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 blosc codec.
Source code in src/zarr_metadata/v3/codec/blosc.py
BloscCodecObject ¶
Bases: TypedDict
blosc codec metadata in object form.
Source code in src/zarr_metadata/v3/codec/blosc.py
canonical_configuration ¶
A blosc configuration in its simplest equivalent form.
Under shuffle: "noshuffle" the spec says of typesize that "the
value is ignored", so whatever it holds carries no meaning and two
documents differing only there describe the same codec. Dropping it
makes that equality visible.
Assumes a configuration the shape validator has already accepted.
Source code in src/zarr_metadata/v3/codec/blosc.py
zarr_metadata.v3.codec.bytes ¶
Bytes codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/bytes/index.html
BYTES_CODEC_NAME
module-attribute
¶
BYTES_CODEC_NAME: Final = 'bytes'
The name field value of the bytes codec.
BytesCodecMetadata
module-attribute
¶
BytesCodecMetadata = BytesCodecObject | BytesCodecName
Permitted JSON shapes for bytes codec metadata.
The configuration has no required keys (endian is conditionally required
at runtime based on data type), so the spec's short-hand-name form is
permitted in addition to the object form, and the object form may itself
omit configuration entirely.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/bytes/index.rst#L64-L69 ("endian: Required for data types for which endianness is applicable")
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564
BytesCodecName
module-attribute
¶
BytesCodecName = Literal['bytes']
Literal type of the name field of the bytes codec.
ENDIANNESS
module-attribute
¶
ENDIANNESS: Final = ('little', 'big')
Tuple of permitted values for the endian field of the bytes codec.
Endianness
module-attribute
¶
Endianness = Literal['little', 'big']
Literal type of byte order of multi-byte numeric data.
__all__
module-attribute
¶
__all__ = [
"BYTES_CODEC_NAME",
"ENDIANNESS",
"BytesCodec",
"BytesCodecConfiguration",
"BytesCodecMetadata",
"BytesCodecName",
"BytesCodecObject",
"Endianness",
]
BytesCodec
dataclass
¶
Bases: CodecEntity
The bytes codec, coerced from its metadata.
endian is optional and absent means something: a one-byte data type
has no byte order to state, and the spec lets such an array omit it.
Source code in src/zarr_metadata/v3/codec/bytes.py
configuration_required
class-attribute
¶
configuration_required: bool = False
Whether the bare-name spelling says too little for this entity.
The spec permits a bare name "if no configuration metadata is required", so this is true exactly when some member is required.
identifier
class-attribute
¶
identifier: str = BYTES_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
member_types
class-attribute
¶
member_types: MemberTypes = {
"endian": (False, one_of(ENDIANNESS))
}
The configuration members, and the type each one takes.
The same keys as the configuration TypedDict, which is the same as the
constructor signature; tests/v3/test_entities.py holds the three
together.
must_understand
class-attribute
instance-attribute
¶
name
property
¶
name: str
The name this entity carries, as a document would write it.
Usually the identifier. They differ for the raw-bytes family,
whose identifier is invented and belongs in no message a reader
sees -- so anything user-facing wants this, and anything looking
something up wants identifier.
required_class_vars
class-attribute
¶
Every class variable a concrete entity of this kind must declare.
variable_size
class-attribute
¶
variable_size: bool = False
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read.
__init_subclass__ ¶
Refuse a subclass that forgot to say what it is.
identifier and the per-kind class variables carry no default,
so a subclass omitting one type-checks cleanly and then raises
AttributeError from whichever method is reached first. Saying so
here makes it an import-time error in the extension's own module.
base=True for a class that exists to add a class variable
rather than to be an entity -- CodecEntity, IntegerDataType.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
Default: entities are already canonical. Override where two
spellings of a member mean the same -- a rectilinear dimension's
run-length encoding, a typesize that noshuffle ignores -- and
where a contained entity has its own canonical form.
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one.
context is the scope this reading is happening in; most entities
have no use for it and ignore it.
Source code in src/zarr_metadata/v3/_entity.py
configuration ¶
This entity's configuration, as the document would write it.
Faithful to every member the entity holds: to_json is
serialization, not canonicalization, so nothing is simplified
here. Override only to render a member that is not already JSON,
such as a contained entity.
Absent optional members are left out, which is what makes the
bare-name spelling reachable. Absence is UNSET, never None:
this package holds None to mean a JSON null the document
actually wrote, and scale_offset is a real case where null
and absent are different documents.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
The data type reaching here must have a raw byte representation.
A variable-length type has no fixed one, so this codec cannot
encode it. A multi-byte one has several orderings, so endian is
required -- and the message names the type, because inside a
shard's index_codecs the array is the shard index, whose
uint64 type appears nowhere in the document.
Source code in src/zarr_metadata/v3/codec/bytes.py
problems ¶
problems() -> tuple[ValidationProblem, ...]
Every value of this entity the spec disallows.
Locations are relative to the entity's configuration. Default:
an entity whose type admits only valid values has nothing to add.
Source code in src/zarr_metadata/v3/_entity.py
to_json ¶
to_json() -> BytesCodecObject | BytesCodecName
This entity as a document would write it.
Faithful to every member: read a document, write it back, and the
members come out as they went in. Ask canonical first if you
want the simplest equivalent spelling.
What is not preserved is the envelope's spelling, because the
entity does not model it: a bare name, {"name": x}, and
{"name": x, "configuration": {}} all mean the same and all read
to the same entity, so all three write back as the bare name.
must_understand is omitted when true, which is its default; an
explicit false is kept, because that one says something.
Subclasses narrow the return type to their own object TypedDict, which is the JSON form this dataclass models.
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
What the next codec in the chain sees, or None if undeterminable.
Only an array-to-array codec has anything to say: the two later kinds end shape propagation by construction, one by consuming the array and the other by never having had it.
The default is None, so a modelled codec that forgets to say how it transforms the array stops propagation rather than silently claiming to leave it alone. Failing closed here costs a judgment; failing open would invent one.
Source code in src/zarr_metadata/v3/_entity.py
BytesCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 bytes codec.
The endian field is required for multi-byte data types.
Source code in src/zarr_metadata/v3/codec/bytes.py
BytesCodecObject ¶
Bases: TypedDict
bytes codec metadata in object form.
configuration is itself optional — when no configuration fields are
set, the entire configuration key may be omitted. This matches the
bare-string short-hand form (BytesCodecName) at the canonical data
level; both encodings describe a bytes codec with default settings.
Source code in src/zarr_metadata/v3/codec/bytes.py
zarr_metadata.v3.codec.cast_value ¶
Cast-value codec types.
See https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/cast_value/README.md
CAST_OUT_OF_RANGE_MODE
module-attribute
¶
CAST_OUT_OF_RANGE_MODE: Final = ('clamp', 'wrap')
Tuple of permitted values for the out_of_range field of the cast_value codec.
CAST_ROUNDING_MODE
module-attribute
¶
CAST_ROUNDING_MODE: Final = (
"nearest-even",
"towards-zero",
"towards-positive",
"towards-negative",
"nearest-away",
)
Tuple of permitted values for the rounding field of the cast_value codec.
CAST_VALUE_CODEC_NAME
module-attribute
¶
CAST_VALUE_CODEC_NAME: Final = 'cast_value'
The name field value of the cast_value codec.
CastOutOfRangeMode
module-attribute
¶
CastOutOfRangeMode = Literal['clamp', 'wrap']
Literal type of permitted values for the out_of_range configuration field.
If absent, out-of-range values are an encoding/decoding error.
CastRoundingMode
module-attribute
¶
CastRoundingMode = Literal[
"nearest-even",
"towards-zero",
"towards-positive",
"towards-negative",
"nearest-away",
]
Literal type of permitted values for the rounding configuration field.
Defaults to "nearest-even" if absent.
CastValueCodecMetadata
module-attribute
¶
CastValueCodecMetadata = CastValueCodecObject
Permitted JSON shape for cast_value codec metadata.
configuration.data_type is required, so only the object form is valid;
the short-hand-name form is not permitted by the spec for this codec.
https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/cast_value/README.md#L33-L36 and #L46-L48 (required fields)
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564 (short-hand names only "if no configuration metadata is required")
CastValueCodecName
module-attribute
¶
CastValueCodecName = Literal['cast_value']
Literal type of the name field of the cast_value codec.
SCALAR_MAP_KEYS
module-attribute
¶
SCALAR_MAP_KEYS: Final = ('encode', 'decode')
The two directions a scalar_map can override, both optional.
ScalarMapEntry
module-attribute
¶
A single [input, output] mapping in a scalar_map direction.
Each scalar is JSON-encoded per its data type's fill-value rules (so
e.g. "NaN" and "+Infinity" are permitted).
__all__
module-attribute
¶
__all__ = [
"CAST_OUT_OF_RANGE_MODE",
"CAST_ROUNDING_MODE",
"CAST_VALUE_CODEC_NAME",
"SCALAR_MAP_KEYS",
"CastOutOfRangeMode",
"CastRoundingMode",
"CastValueCodec",
"CastValueCodecConfiguration",
"CastValueCodecMetadata",
"CastValueCodecName",
"CastValueCodecObject",
"ScalarMap",
"ScalarMapEntry",
]
CastValueCodec
dataclass
¶
Bases: CodecEntity
The cast_value codec, coerced from its metadata.
Holds the data type it casts to, so like sharding_indexed it is
read in a scope rather than on its own.
out_of_range: "wrap" is defined only for integral targets with a
two's complement representation, which is a fact each data type
states about itself.
Source code in src/zarr_metadata/v3/codec/cast_value.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
configuration_required
class-attribute
¶
configuration_required: bool = True
Whether the bare-name spelling says too little for this entity.
The spec permits a bare name "if no configuration metadata is required", so this is true exactly when some member is required.
identifier
class-attribute
¶
identifier: str = CAST_VALUE_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
member_types
class-attribute
¶
member_types: MemberTypes = {
"data_type": (True, _is_data_type_field),
"rounding": (False, one_of(CAST_ROUNDING_MODE)),
"out_of_range": (False, one_of(CAST_OUT_OF_RANGE_MODE)),
"scalar_map": (False, _is_scalar_map),
}
The configuration members, and the type each one takes.
The same keys as the configuration TypedDict, which is the same as the
constructor signature; tests/v3/test_entities.py holds the three
together.
must_understand
class-attribute
instance-attribute
¶
name
property
¶
name: str
The name this entity carries, as a document would write it.
Usually the identifier. They differ for the raw-bytes family,
whose identifier is invented and belongs in no message a reader
sees -- so anything user-facing wants this, and anything looking
something up wants identifier.
required_class_vars
class-attribute
¶
Every class variable a concrete entity of this kind must declare.
variable_size
class-attribute
¶
variable_size: bool = False
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read.
__init__ ¶
__init__(
data_type: DataTypeEntity | Opaque = _UNREAD,
rounding: CastRoundingMode | UNSET = UNSET,
out_of_range: CastOutOfRangeMode | UNSET = UNSET,
scalar_map: ScalarMap | UNSET = UNSET,
*,
must_understand: bool = True,
) -> None
__init_subclass__ ¶
Refuse a subclass that forgot to say what it is.
identifier and the per-kind class variables carry no default,
so a subclass omitting one type-checks cleanly and then raises
AttributeError from whichever method is reached first. Saying so
here makes it an import-time error in the extension's own module.
base=True for a class that exists to add a class variable
rather than to be an entity -- CodecEntity, IntegerDataType.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
coerce
classmethod
¶
value as this entity, or the reasons it is not one.
context is the scope this reading is happening in; most entities
have no use for it and ignore it.
Source code in src/zarr_metadata/v3/codec/cast_value.py
configuration ¶
The target data type in its canonical spelling.
Source code in src/zarr_metadata/v3/codec/cast_value.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
Why this codec cannot be applied to the array that reaches it.
incoming is None once the chain can no longer say what reaches
here, and the default answer to that is nothing: declining beats
guessing. Locations are relative to this codec's configuration,
as problems' are; an empty one lands on the codec itself.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> tuple[ValidationProblem, ...]
The target's own problems, and whether it can be wrapped.
Source code in src/zarr_metadata/v3/codec/cast_value.py
to_json ¶
to_json() -> CastValueCodecObject
This entity as a document would write it.
Faithful to every member: read a document, write it back, and the
members come out as they went in. Ask canonical first if you
want the simplest equivalent spelling.
What is not preserved is the envelope's spelling, because the
entity does not model it: a bare name, {"name": x}, and
{"name": x, "configuration": {}} all mean the same and all read
to the same entity, so all three write back as the bare name.
must_understand is omitted when true, which is its default; an
explicit false is kept, because that one says something.
Subclasses narrow the return type to their own object TypedDict, which is the JSON form this dataclass models.
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
The same parts, holding the type this codec casts to.
Source code in src/zarr_metadata/v3/codec/cast_value.py
CastValueCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 cast_value codec.
data_type is the target data type that input values are cast to. It
is the same shape as the top-level array data_type field: either a
bare-string primitive name or a {name, configuration} envelope.
Source code in src/zarr_metadata/v3/codec/cast_value.py
CastValueCodecObject ¶
Bases: TypedDict
cast_value codec metadata in object form.
Source code in src/zarr_metadata/v3/codec/cast_value.py
ScalarMap ¶
Bases: TypedDict
Optional encode/decode scalar overrides for the cast_value codec.
Source code in src/zarr_metadata/v3/codec/cast_value.py
zarr_metadata.v3.codec.crc32c ¶
CRC32C codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/crc32c/index.html
The CRC32C codec has no configuration fields, so the configuration
key is absent from the metadata.
CRC32C_CODEC_NAME
module-attribute
¶
CRC32C_CODEC_NAME: Final = 'crc32c'
The name field value of the crc32c codec.
Crc32cCodecMetadata
module-attribute
¶
Crc32cCodecMetadata = Crc32cCodecObject | Crc32cCodecName
Permitted JSON shapes for crc32c codec metadata.
The spec's Extension definition allows extensions with no required configuration to be encoded as a bare short-hand name. CRC32C has no configuration, so both forms are valid. https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564
Crc32cCodecName
module-attribute
¶
Crc32cCodecName = Literal['crc32c']
Literal type of the name field of the crc32c codec.
__all__
module-attribute
¶
__all__ = [
"CRC32C_CODEC_NAME",
"Crc32cCodec",
"Crc32cCodecMetadata",
"Crc32cCodecName",
"Crc32cCodecObject",
]
Crc32cCodec
dataclass
¶
Bases: CodecEntity
The crc32c codec, coerced from its metadata.
The name says everything: a checksum has nothing to configure.
Source code in src/zarr_metadata/v3/codec/crc32c.py
configuration_required
class-attribute
¶
configuration_required: bool = False
Whether the bare-name spelling says too little for this entity.
The spec permits a bare name "if no configuration metadata is required", so this is true exactly when some member is required.
identifier
class-attribute
¶
identifier: str = CRC32C_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
member_types
class-attribute
¶
member_types: MemberTypes = MappingProxyType({})
The configuration members, and the type each one takes.
The same keys as the configuration TypedDict, which is the same as the
constructor signature; tests/v3/test_entities.py holds the three
together.
must_understand
class-attribute
instance-attribute
¶
name
property
¶
name: str
The name this entity carries, as a document would write it.
Usually the identifier. They differ for the raw-bytes family,
whose identifier is invented and belongs in no message a reader
sees -- so anything user-facing wants this, and anything looking
something up wants identifier.
required_class_vars
class-attribute
¶
Every class variable a concrete entity of this kind must declare.
variable_size
class-attribute
¶
variable_size: bool = False
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read.
__init_subclass__ ¶
Refuse a subclass that forgot to say what it is.
identifier and the per-kind class variables carry no default,
so a subclass omitting one type-checks cleanly and then raises
AttributeError from whichever method is reached first. Saying so
here makes it an import-time error in the extension's own module.
base=True for a class that exists to add a class variable
rather than to be an entity -- CodecEntity, IntegerDataType.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
Default: entities are already canonical. Override where two
spellings of a member mean the same -- a rectilinear dimension's
run-length encoding, a typesize that noshuffle ignores -- and
where a contained entity has its own canonical form.
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one.
context is the scope this reading is happening in; most entities
have no use for it and ignore it.
Source code in src/zarr_metadata/v3/_entity.py
configuration ¶
This entity's configuration, as the document would write it.
Faithful to every member the entity holds: to_json is
serialization, not canonicalization, so nothing is simplified
here. Override only to render a member that is not already JSON,
such as a contained entity.
Absent optional members are left out, which is what makes the
bare-name spelling reachable. Absence is UNSET, never None:
this package holds None to mean a JSON null the document
actually wrote, and scale_offset is a real case where null
and absent are different documents.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
Why this codec cannot be applied to the array that reaches it.
incoming is None once the chain can no longer say what reaches
here, and the default answer to that is nothing: declining beats
guessing. Locations are relative to this codec's configuration,
as problems' are; an empty one lands on the codec itself.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> tuple[ValidationProblem, ...]
Every value of this entity the spec disallows.
Locations are relative to the entity's configuration. Default:
an entity whose type admits only valid values has nothing to add.
Source code in src/zarr_metadata/v3/_entity.py
to_json ¶
to_json() -> Crc32cCodecObject | Crc32cCodecName
This entity as a document would write it.
Faithful to every member: read a document, write it back, and the
members come out as they went in. Ask canonical first if you
want the simplest equivalent spelling.
What is not preserved is the envelope's spelling, because the
entity does not model it: a bare name, {"name": x}, and
{"name": x, "configuration": {}} all mean the same and all read
to the same entity, so all three write back as the bare name.
must_understand is omitted when true, which is its default; an
explicit false is kept, because that one says something.
Subclasses narrow the return type to their own object TypedDict, which is the JSON form this dataclass models.
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
What the next codec in the chain sees, or None if undeterminable.
Only an array-to-array codec has anything to say: the two later kinds end shape propagation by construction, one by consuming the array and the other by never having had it.
The default is None, so a modelled codec that forgets to say how it transforms the array stops propagation rather than silently claiming to leave it alone. Failing closed here costs a judgment; failing open would invent one.
Source code in src/zarr_metadata/v3/_entity.py
Crc32cCodecObject ¶
Bases: TypedDict
crc32c codec metadata in object form.
Per spec the codec has no configuration fields. configuration is
optional and, if present, should be an empty mapping.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/crc32c/index.rst#L63-L66
Source code in src/zarr_metadata/v3/codec/crc32c.py
zarr_metadata.v3.codec.gzip ¶
Gzip codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/gzip/index.html
GZIP_CODEC_NAME
module-attribute
¶
GZIP_CODEC_NAME: Final = 'gzip'
The name field value of the gzip codec.
GzipCodecMetadata
module-attribute
¶
GzipCodecMetadata = GzipCodecObject
Permitted JSON shape for gzip codec metadata.
configuration.level is required (it determines the codec's output bytes
and is therefore part of the metadata's reproducibility contract), so
only the object form is valid; the short-hand-name form is not permitted.
GzipCodecName
module-attribute
¶
GzipCodecName = Literal['gzip']
Literal type of the name field of the gzip codec.
__all__
module-attribute
¶
__all__ = [
"GZIP_CODEC_NAME",
"GzipCodec",
"GzipCodecConfiguration",
"GzipCodecMetadata",
"GzipCodecName",
"GzipCodecObject",
]
GzipCodec
dataclass
¶
Bases: CodecEntity
The gzip codec, coerced from its metadata.
Source code in src/zarr_metadata/v3/codec/gzip.py
configuration_required
class-attribute
¶
configuration_required: bool = True
Whether the bare-name spelling says too little for this entity.
The spec permits a bare name "if no configuration metadata is required", so this is true exactly when some member is required.
identifier
class-attribute
¶
identifier: str = GZIP_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
member_types
class-attribute
¶
member_types: MemberTypes = {'level': (True, is_int)}
The configuration members, and the type each one takes.
The same keys as the configuration TypedDict, which is the same as the
constructor signature; tests/v3/test_entities.py holds the three
together.
must_understand
class-attribute
instance-attribute
¶
name
property
¶
name: str
The name this entity carries, as a document would write it.
Usually the identifier. They differ for the raw-bytes family,
whose identifier is invented and belongs in no message a reader
sees -- so anything user-facing wants this, and anything looking
something up wants identifier.
required_class_vars
class-attribute
¶
Every class variable a concrete entity of this kind must declare.
variable_size
class-attribute
¶
variable_size: bool = True
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read.
__init_subclass__ ¶
Refuse a subclass that forgot to say what it is.
identifier and the per-kind class variables carry no default,
so a subclass omitting one type-checks cleanly and then raises
AttributeError from whichever method is reached first. Saying so
here makes it an import-time error in the extension's own module.
base=True for a class that exists to add a class variable
rather than to be an entity -- CodecEntity, IntegerDataType.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
Default: entities are already canonical. Override where two
spellings of a member mean the same -- a rectilinear dimension's
run-length encoding, a typesize that noshuffle ignores -- and
where a contained entity has its own canonical form.
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one.
context is the scope this reading is happening in; most entities
have no use for it and ignore it.
Source code in src/zarr_metadata/v3/_entity.py
configuration ¶
This entity's configuration, as the document would write it.
Faithful to every member the entity holds: to_json is
serialization, not canonicalization, so nothing is simplified
here. Override only to render a member that is not already JSON,
such as a contained entity.
Absent optional members are left out, which is what makes the
bare-name spelling reachable. Absence is UNSET, never None:
this package holds None to mean a JSON null the document
actually wrote, and scale_offset is a real case where null
and absent are different documents.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
Why this codec cannot be applied to the array that reaches it.
incoming is None once the chain can no longer say what reaches
here, and the default answer to that is nothing: declining beats
guessing. Locations are relative to this codec's configuration,
as problems' are; an empty one lands on the codec itself.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> tuple[ValidationProblem, ...]
gzip compression levels run 0 to 9.
Source code in src/zarr_metadata/v3/codec/gzip.py
to_json ¶
to_json() -> GzipCodecObject
This entity as a document would write it.
Faithful to every member: read a document, write it back, and the
members come out as they went in. Ask canonical first if you
want the simplest equivalent spelling.
What is not preserved is the envelope's spelling, because the
entity does not model it: a bare name, {"name": x}, and
{"name": x, "configuration": {}} all mean the same and all read
to the same entity, so all three write back as the bare name.
must_understand is omitted when true, which is its default; an
explicit false is kept, because that one says something.
Subclasses narrow the return type to their own object TypedDict, which is the JSON form this dataclass models.
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
What the next codec in the chain sees, or None if undeterminable.
Only an array-to-array codec has anything to say: the two later kinds end shape propagation by construction, one by consuming the array and the other by never having had it.
The default is None, so a modelled codec that forgets to say how it transforms the array stops propagation rather than silently claiming to leave it alone. Failing closed here costs a judgment; failing open would invent one.
Source code in src/zarr_metadata/v3/_entity.py
GzipCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 gzip codec.
level is an integer in the range 0-9; 0 disables compression and 9
is slowest with the best compression ratio. The codec's compressed
output depends on level, so metadata that omits it cannot
reproducibly identify the chunk bytes produced by a writer — level
is required for the metadata to fulfill its reproducibility role,
even though the spec text does not mark it required with RFC 2119
keywords.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/gzip/index.rst#L57-L66
Source code in src/zarr_metadata/v3/codec/gzip.py
GzipCodecObject ¶
Bases: TypedDict
gzip codec metadata in object form.
Source code in src/zarr_metadata/v3/codec/gzip.py
zarr_metadata.v3.codec.scale_offset ¶
Scale-offset codec types.
See https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/scale_offset/README.md
SCALE_OFFSET_CODEC_NAME
module-attribute
¶
SCALE_OFFSET_CODEC_NAME: Final = 'scale_offset'
The name field value of the scale_offset codec.
ScaleOffsetCodecMetadata
module-attribute
¶
ScaleOffsetCodecMetadata = (
ScaleOffsetCodecObject | ScaleOffsetCodecName
)
Permitted JSON shapes for scale_offset codec metadata.
The configuration has no required keys (both offset and scale are
optional, and the configuration itself is optional), so the short-hand-name
form is permitted in addition to the object form.
ScaleOffsetCodecName
module-attribute
¶
ScaleOffsetCodecName = Literal['scale_offset']
Literal type of the name field of the scale_offset codec.
__all__
module-attribute
¶
__all__ = [
"SCALE_OFFSET_CODEC_NAME",
"ScaleOffsetCodec",
"ScaleOffsetCodecConfiguration",
"ScaleOffsetCodecMetadata",
"ScaleOffsetCodecName",
"ScaleOffsetCodecObject",
]
ScaleOffsetCodec
dataclass
¶
Bases: CodecEntity
The scale_offset codec, coerced from its metadata.
Both members are optional and any JSON scalar is well-typed here; what a given value means depends on the data type it is applied to, which is a question for the rules layer.
Source code in src/zarr_metadata/v3/codec/scale_offset.py
configuration_required
class-attribute
¶
configuration_required: bool = False
Whether the bare-name spelling says too little for this entity.
The spec permits a bare name "if no configuration metadata is required", so this is true exactly when some member is required.
identifier
class-attribute
¶
identifier: str = SCALE_OFFSET_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
member_types
class-attribute
¶
member_types: MemberTypes = {
"offset": (False, is_json_value),
"scale": (False, is_json_value),
}
The configuration members, and the type each one takes.
The same keys as the configuration TypedDict, which is the same as the
constructor signature; tests/v3/test_entities.py holds the three
together.
must_understand
class-attribute
instance-attribute
¶
name
property
¶
name: str
The name this entity carries, as a document would write it.
Usually the identifier. They differ for the raw-bytes family,
whose identifier is invented and belongs in no message a reader
sees -- so anything user-facing wants this, and anything looking
something up wants identifier.
required_class_vars
class-attribute
¶
Every class variable a concrete entity of this kind must declare.
variable_size
class-attribute
¶
variable_size: bool = False
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read.
__init__ ¶
__init__(
offset: JSONValue | UNSET = UNSET,
scale: JSONValue | UNSET = UNSET,
*,
must_understand: bool = True,
) -> None
__init_subclass__ ¶
Refuse a subclass that forgot to say what it is.
identifier and the per-kind class variables carry no default,
so a subclass omitting one type-checks cleanly and then raises
AttributeError from whichever method is reached first. Saying so
here makes it an import-time error in the extension's own module.
base=True for a class that exists to add a class variable
rather than to be an entity -- CodecEntity, IntegerDataType.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
Default: entities are already canonical. Override where two
spellings of a member mean the same -- a rectilinear dimension's
run-length encoding, a typesize that noshuffle ignores -- and
where a contained entity has its own canonical form.
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one.
context is the scope this reading is happening in; most entities
have no use for it and ignore it.
Source code in src/zarr_metadata/v3/_entity.py
configuration ¶
This entity's configuration, as the document would write it.
Faithful to every member the entity holds: to_json is
serialization, not canonicalization, so nothing is simplified
here. Override only to render a member that is not already JSON,
such as a contained entity.
Absent optional members are left out, which is what makes the
bare-name spelling reachable. Absence is UNSET, never None:
this package holds None to mean a JSON null the document
actually wrote, and scale_offset is a real case where null
and absent are different documents.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
Why this codec cannot be applied to the array that reaches it.
incoming is None once the chain can no longer say what reaches
here, and the default answer to that is nothing: declining beats
guessing. Locations are relative to this codec's configuration,
as problems' are; an empty one lands on the codec itself.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> tuple[ValidationProblem, ...]
Each value is a scalar of the array's type, so neither is null.
The registry says each is "JSON-encoded per the input array's
fill-value rules", and no data type admits null as a fill value.
Which scalar it should be needs the data type, so that part is the
document's question, not this codec's.
Source code in src/zarr_metadata/v3/codec/scale_offset.py
to_json ¶
to_json() -> ScaleOffsetCodecObject | ScaleOffsetCodecName
This entity as a document would write it.
Faithful to every member: read a document, write it back, and the
members come out as they went in. Ask canonical first if you
want the simplest equivalent spelling.
What is not preserved is the envelope's spelling, because the
entity does not model it: a bare name, {"name": x}, and
{"name": x, "configuration": {}} all mean the same and all read
to the same entity, so all three write back as the bare name.
must_understand is omitted when true, which is its default; an
explicit false is kept, because that one says something.
Subclasses narrow the return type to their own object TypedDict, which is the JSON form this dataclass models.
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
The same array, element for element.
The registry entry removed the astype field, so this codec no
longer changes the element type -- only the values.
Source code in src/zarr_metadata/v3/codec/scale_offset.py
ScaleOffsetCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 scale_offset codec.
Both fields are optional. A missing offset is the additive identity
(e.g. 0 for numeric types); a missing scale is the multiplicative
identity (e.g. 1). Each scalar is JSON-encoded per the input array's
fill-value rules, so "NaN" and "+Infinity" style strings are
permitted in addition to numbers.
Source code in src/zarr_metadata/v3/codec/scale_offset.py
ScaleOffsetCodecObject ¶
Bases: TypedDict
scale_offset codec metadata in object form.
configuration is itself optional per spec — when both offset and
scale are at their identity defaults, the codec is a no-op and the
entire configuration field may be omitted.
https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/scale_offset/README.md#L18 and #L35
Source code in src/zarr_metadata/v3/codec/scale_offset.py
zarr_metadata.v3.codec.sharding_indexed ¶
Sharding-indexed codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/sharding-indexed/index.html
SHARDING_INDEXED_CODEC_NAME
module-attribute
¶
SHARDING_INDEXED_CODEC_NAME: Final = 'sharding_indexed'
The name field value of the sharding_indexed codec.
SHARDING_INDEX_LOCATION
module-attribute
¶
SHARDING_INDEX_LOCATION: Final = ('start', 'end')
Tuple of permitted values for the index_location field of the sharding_indexed codec.
ShardingIndexLocation
module-attribute
¶
ShardingIndexLocation = Literal['start', 'end']
Literal type of the position of the shard index within the encoded shard.
ShardingIndexedCodecMetadata
module-attribute
¶
ShardingIndexedCodecMetadata = ShardingIndexedCodecObject
Permitted JSON shape for sharding_indexed codec metadata.
The configuration has multiple required keys (chunk_shape, codecs,
index_codecs), so only the object form is valid; the short-hand-name
form is not permitted by the spec for this codec.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/sharding-indexed/index.rst#L141-L155 (required members)
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564 (short-hand names only "if no configuration metadata is required")
ShardingIndexedCodecName
module-attribute
¶
ShardingIndexedCodecName = Literal['sharding_indexed']
Literal type of the name field of the sharding_indexed codec.
__all__
module-attribute
¶
__all__ = [
"SHARDING_INDEXED_CODEC_NAME",
"SHARDING_INDEX_LOCATION",
"ShardingIndexLocation",
"ShardingIndexedCodec",
"ShardingIndexedCodecConfiguration",
"ShardingIndexedCodecMetadata",
"ShardingIndexedCodecName",
"ShardingIndexedCodecObject",
]
ShardingIndexedCodec
dataclass
¶
Bases: CodecEntity
The sharding_indexed codec, coerced from its metadata.
Holds two codec pipelines, so it is one of the few entities that needs the scope it is being read in: an entry of either pipeline is itself an entity, read the same way this one was.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
configuration_required
class-attribute
¶
configuration_required: bool = True
Whether the bare-name spelling says too little for this entity.
The spec permits a bare name "if no configuration metadata is required", so this is true exactly when some member is required.
identifier
class-attribute
¶
identifier: str = SHARDING_INDEXED_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
index_codecs
class-attribute
instance-attribute
¶
index_codecs: tuple[CodecEntity | Opaque, ...] = ()
index_location
class-attribute
instance-attribute
¶
index_location: ShardingIndexLocation | UNSET = UNSET
member_types
class-attribute
¶
member_types: MemberTypes = {
"chunk_shape": (True, sequence_of(is_int)),
"codecs": (True, _is_field_tuple),
"index_codecs": (True, _is_field_tuple),
"index_location": (
False,
one_of(SHARDING_INDEX_LOCATION),
),
}
The configuration members, and the type each one takes.
The same keys as the configuration TypedDict, which is the same as the
constructor signature; tests/v3/test_entities.py holds the three
together.
must_understand
class-attribute
instance-attribute
¶
name
property
¶
name: str
The name this entity carries, as a document would write it.
Usually the identifier. They differ for the raw-bytes family,
whose identifier is invented and belongs in no message a reader
sees -- so anything user-facing wants this, and anything looking
something up wants identifier.
required_class_vars
class-attribute
¶
Every class variable a concrete entity of this kind must declare.
variable_size
class-attribute
¶
variable_size: bool = True
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read.
__init__ ¶
__init__(
chunk_shape: tuple[int, ...] = (),
codecs: tuple[CodecEntity | Opaque, ...] = (),
index_codecs: tuple[CodecEntity | Opaque, ...] = (),
index_location: ShardingIndexLocation | UNSET = UNSET,
*,
must_understand: bool = True,
) -> None
__init_subclass__ ¶
Refuse a subclass that forgot to say what it is.
identifier and the per-kind class variables carry no default,
so a subclass omitting one type-checks cleanly and then raises
AttributeError from whichever method is reached first. Saying so
here makes it an import-time error in the extension's own module.
base=True for a class that exists to add a class variable
rather than to be an entity -- CodecEntity, IntegerDataType.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
coerce
classmethod
¶
value as this entity, or the reasons it is not one.
context is the scope this reading is happening in; most entities
have no use for it and ignore it.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
configuration ¶
The two pipelines in their canonical spelling, entry by entry.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
This shard against the array reaching it, and its two pipelines.
One sharding configuration encodes every chunk, so its inner shape has to divide all of them. Under a rectilinear grid an axis has several lengths and the inner extent must divide each; an axis whose lengths are unknown declines while the others are judged.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
problems ¶
problems() -> tuple[ValidationProblem, ...]
This shard's own values, and those of the codecs it holds.
Whether the two pipelines are well formed -- one array-to-bytes codec, in the right order -- spans the whole chain, so the rules layer asks that.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
to_json ¶
to_json() -> ShardingIndexedCodecObject
This entity as a document would write it.
Faithful to every member: read a document, write it back, and the
members come out as they went in. Ask canonical first if you
want the simplest equivalent spelling.
What is not preserved is the envelope's spelling, because the
entity does not model it: a bare name, {"name": x}, and
{"name": x, "configuration": {}} all mean the same and all read
to the same entity, so all three write back as the bare name.
must_understand is omitted when true, which is its default; an
explicit false is kept, because that one says something.
Subclasses narrow the return type to their own object TypedDict, which is the JSON form this dataclass models.
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
What the next codec in the chain sees, or None if undeterminable.
Only an array-to-array codec has anything to say: the two later kinds end shape propagation by construction, one by consuming the array and the other by never having had it.
The default is None, so a modelled codec that forgets to say how it transforms the array stops propagation rather than silently claiming to leave it alone. Failing closed here costs a judgment; failing open would invent one.
Source code in src/zarr_metadata/v3/_entity.py
ShardingIndexedCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 sharding_indexed codec.
chunk_shape is the shape of inner chunks along each dimension;
it must evenly divide the shard shape.
codecs is the codec pipeline applied to each inner chunk; exactly
one array-to-bytes codec is required.
index_codecs is the codec pipeline applied to the shard index;
it must be deterministic (no variable-size compression).
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/sharding-indexed/index.rst#L147-L155
index_location defaults to "end" per the spec.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/sharding-indexed/index.rst#L157-L161
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
ShardingIndexedCodecObject ¶
Bases: TypedDict
sharding_indexed codec metadata in object form.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
zarr_metadata.v3.codec.transpose ¶
Transpose codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/transpose/index.html
TRANSPOSE_CODEC_NAME
module-attribute
¶
TRANSPOSE_CODEC_NAME: Final = 'transpose'
The name field value of the transpose codec.
TransposeCodecMetadata
module-attribute
¶
TransposeCodecMetadata = TransposeCodecObject
Permitted JSON shape for transpose codec metadata.
order is required, so only the object form is valid; the short-hand-name
form is not permitted by the spec for this codec.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/transpose/index.rst#L60-L66 ("order: Required")
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564 (short-hand names only "if no configuration metadata is required")
TransposeCodecName
module-attribute
¶
TransposeCodecName = Literal['transpose']
Literal type of the name field of the transpose codec.
__all__
module-attribute
¶
__all__ = [
"TRANSPOSE_CODEC_NAME",
"TransposeCodec",
"TransposeCodecConfiguration",
"TransposeCodecMetadata",
"TransposeCodecName",
"TransposeCodecObject",
]
TransposeCodec
dataclass
¶
Bases: CodecEntity
The transpose codec, coerced from its metadata.
Source code in src/zarr_metadata/v3/codec/transpose.py
configuration_required
class-attribute
¶
configuration_required: bool = True
Whether the bare-name spelling says too little for this entity.
The spec permits a bare name "if no configuration metadata is required", so this is true exactly when some member is required.
identifier
class-attribute
¶
identifier: str = TRANSPOSE_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
member_types
class-attribute
¶
member_types: MemberTypes = {
"order": (True, sequence_of(is_int))
}
The configuration members, and the type each one takes.
The same keys as the configuration TypedDict, which is the same as the
constructor signature; tests/v3/test_entities.py holds the three
together.
must_understand
class-attribute
instance-attribute
¶
name
property
¶
name: str
The name this entity carries, as a document would write it.
Usually the identifier. They differ for the raw-bytes family,
whose identifier is invented and belongs in no message a reader
sees -- so anything user-facing wants this, and anything looking
something up wants identifier.
required_class_vars
class-attribute
¶
Every class variable a concrete entity of this kind must declare.
variable_size
class-attribute
¶
variable_size: bool = False
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read.
__init_subclass__ ¶
Refuse a subclass that forgot to say what it is.
identifier and the per-kind class variables carry no default,
so a subclass omitting one type-checks cleanly and then raises
AttributeError from whichever method is reached first. Saying so
here makes it an import-time error in the extension's own module.
base=True for a class that exists to add a class variable
rather than to be an entity -- CodecEntity, IntegerDataType.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
Default: entities are already canonical. Override where two
spellings of a member mean the same -- a rectilinear dimension's
run-length encoding, a typesize that noshuffle ignores -- and
where a contained entity has its own canonical form.
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one.
context is the scope this reading is happening in; most entities
have no use for it and ignore it.
Source code in src/zarr_metadata/v3/_entity.py
configuration ¶
This entity's configuration, as the document would write it.
Faithful to every member the entity holds: to_json is
serialization, not canonicalization, so nothing is simplified
here. Override only to render a member that is not already JSON,
such as a contained entity.
Absent optional members are left out, which is what makes the
bare-name spelling reachable. Absence is UNSET, never None:
this package holds None to mean a JSON null the document
actually wrote, and scale_offset is a real case where null
and absent are different documents.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
A transpose permutes the array it receives, so ranks must agree.
Judged against what actually reaches this codec: inside a shard that is the inner chunk, and after another transpose it is that transpose's output.
Source code in src/zarr_metadata/v3/codec/transpose.py
problems ¶
problems() -> tuple[ValidationProblem, ...]
order must permute its own axes.
Whether it permutes the array's axes is a different question -- it needs the array's rank -- and the rules layer asks that one.
Source code in src/zarr_metadata/v3/codec/transpose.py
to_json ¶
to_json() -> TransposeCodecObject
This entity as a document would write it.
Faithful to every member: read a document, write it back, and the
members come out as they went in. Ask canonical first if you
want the simplest equivalent spelling.
What is not preserved is the envelope's spelling, because the
entity does not model it: a bare name, {"name": x}, and
{"name": x, "configuration": {}} all mean the same and all read
to the same entity, so all three write back as the bare name.
must_understand is omitted when true, which is its default; an
explicit false is kept, because that one says something.
Subclasses narrow the return type to their own object TypedDict, which is the JSON form this dataclass models.
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
The same array with its axes reordered.
A transposed regular grid is still a regular grid, so the parts survive the trip; the grid metadata does not, because it is no longer the grid the document wrote.
Source code in src/zarr_metadata/v3/codec/transpose.py
TransposeCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 transpose codec.
order is a permutation of the dimension indices 0..n-1 that
specifies the dimension reordering applied during encoding.
Source code in src/zarr_metadata/v3/codec/transpose.py
TransposeCodecObject ¶
Bases: TypedDict
transpose codec metadata in object form.
Source code in src/zarr_metadata/v3/codec/transpose.py
zarr_metadata.v3.codec.zstd ¶
Zstandard codec types.
See https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/zstd/README.md (the zarr-extensions registry entry; zarr-specs PR #256, which first proposed the codec, was never merged).
ZSTD_CODEC_NAME
module-attribute
¶
ZSTD_CODEC_NAME: Final = 'zstd'
The name field value of the zstd codec.
ZSTD_MAX_LEVEL
module-attribute
¶
ZSTD_MAX_LEVEL: Final = 22
The highest level zstd accepts: ZSTD_maxCLevel().
ZSTD_MIN_LEVEL
module-attribute
¶
ZSTD_MIN_LEVEL: Final = -131072
The lowest level zstd accepts: ZSTD_minCLevel(), -(1 << 17).
ZstdCodecMetadata
module-attribute
¶
ZstdCodecMetadata = ZstdCodecObject
Permitted JSON shape for zstd codec metadata.
level is required, so only the object form is valid; the short-hand-name
form is not permitted by the spec for this codec.
https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/zstd/README.md#L9-L19
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564 (short-hand names only "if no configuration metadata is required")
ZstdCodecName
module-attribute
¶
ZstdCodecName = Literal['zstd']
Literal type of the name field of the zstd codec.
__all__
module-attribute
¶
__all__ = [
"ZSTD_CODEC_NAME",
"ZSTD_MAX_LEVEL",
"ZSTD_MIN_LEVEL",
"ZstdCodec",
"ZstdCodecConfiguration",
"ZstdCodecMetadata",
"ZstdCodecName",
"ZstdCodecObject",
]
ZstdCodec
dataclass
¶
Bases: CodecEntity
The zstd codec, coerced from its metadata.
Source code in src/zarr_metadata/v3/codec/zstd.py
configuration_required
class-attribute
¶
configuration_required: bool = True
Whether the bare-name spelling says too little for this entity.
The spec permits a bare name "if no configuration metadata is required", so this is true exactly when some member is required.
identifier
class-attribute
¶
identifier: str = ZSTD_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
member_types
class-attribute
¶
member_types: MemberTypes = {
"level": (True, is_int),
"checksum": (False, is_bool),
}
The configuration members, and the type each one takes.
The same keys as the configuration TypedDict, which is the same as the
constructor signature; tests/v3/test_entities.py holds the three
together.
must_understand
class-attribute
instance-attribute
¶
name
property
¶
name: str
The name this entity carries, as a document would write it.
Usually the identifier. They differ for the raw-bytes family,
whose identifier is invented and belongs in no message a reader
sees -- so anything user-facing wants this, and anything looking
something up wants identifier.
required_class_vars
class-attribute
¶
Every class variable a concrete entity of this kind must declare.
variable_size
class-attribute
¶
variable_size: bool = True
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read.
__init__ ¶
__init__(
level: int = 0,
checksum: bool | UNSET = UNSET,
*,
must_understand: bool = True,
) -> None
__init_subclass__ ¶
Refuse a subclass that forgot to say what it is.
identifier and the per-kind class variables carry no default,
so a subclass omitting one type-checks cleanly and then raises
AttributeError from whichever method is reached first. Saying so
here makes it an import-time error in the extension's own module.
base=True for a class that exists to add a class variable
rather than to be an entity -- CodecEntity, IntegerDataType.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
Default: entities are already canonical. Override where two
spellings of a member mean the same -- a rectilinear dimension's
run-length encoding, a typesize that noshuffle ignores -- and
where a contained entity has its own canonical form.
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one.
context is the scope this reading is happening in; most entities
have no use for it and ignore it.
Source code in src/zarr_metadata/v3/_entity.py
configuration ¶
This entity's configuration, as the document would write it.
Faithful to every member the entity holds: to_json is
serialization, not canonicalization, so nothing is simplified
here. Override only to render a member that is not already JSON,
such as a contained entity.
Absent optional members are left out, which is what makes the
bare-name spelling reachable. Absence is UNSET, never None:
this package holds None to mean a JSON null the document
actually wrote, and scale_offset is a real case where null
and absent are different documents.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
Why this codec cannot be applied to the array that reaches it.
incoming is None once the chain can no longer say what reaches
here, and the default answer to that is nothing: declining beats
guessing. Locations are relative to this codec's configuration,
as problems' are; an empty one lands on the codec itself.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> tuple[ValidationProblem, ...]
zstd compression levels run -131072 to 22.
Source code in src/zarr_metadata/v3/codec/zstd.py
to_json ¶
to_json() -> ZstdCodecObject
This entity as a document would write it.
Faithful to every member: read a document, write it back, and the
members come out as they went in. Ask canonical first if you
want the simplest equivalent spelling.
What is not preserved is the envelope's spelling, because the
entity does not model it: a bare name, {"name": x}, and
{"name": x, "configuration": {}} all mean the same and all read
to the same entity, so all three write back as the bare name.
must_understand is omitted when true, which is its default; an
explicit false is kept, because that one says something.
Subclasses narrow the return type to their own object TypedDict, which is the JSON form this dataclass models.
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
What the next codec in the chain sees, or None if undeterminable.
Only an array-to-array codec has anything to say: the two later kinds end shape propagation by construction, one by consuming the array and the other by never having had it.
The default is None, so a modelled codec that forgets to say how it transforms the array stops propagation rather than silently claiming to leave it alone. Failing closed here costs a judgment; failing open would invent one.
Source code in src/zarr_metadata/v3/_entity.py
ZstdCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 zstd codec.
level is required; checksum is optional ("Should be omitted if
false").
https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/zstd/README.md#L9-L19
Source code in src/zarr_metadata/v3/codec/zstd.py
ZstdCodecObject ¶
Bases: TypedDict
zstd codec metadata in object form.