zarr_metadata.model
zarr_metadata.model ¶
In-memory models for Zarr metadata documents.
Models are frozen dataclasses that hold a canonical, semantically lossless
representation of the JSON documents; they never interpret extension points
(codecs, chunk grids, data types). Validators check JSON structure, not domain validity.
Each document concept gets a validate_* function returning every problem
found (a list[ValidationProblem], each with a machine-readable kind), an
is_* type guard, and a parse_* function that narrows or raises
MetadataValidationError. Model from_json / from_key_value constructors
raise MetadataValidationError for every ingestion failure, including
missing store keys and undecodable bytes.
ARRAY_METADATA_OPTIONAL_KEYS_V3
module-attribute
¶
ARRAY_METADATA_OPTIONAL_KEYS_V3: Final[frozenset[str]] = (
frozenset(ZarrV3ArrayMetadataJSON.__optional_keys__)
)
ARRAY_METADATA_REQUIRED_KEYS_V2
module-attribute
¶
ARRAY_METADATA_REQUIRED_KEYS_V2: Final[frozenset[str]] = (
frozenset(ZarrV2ArrayMetadataJSON.__required_keys__)
)
ARRAY_METADATA_REQUIRED_KEYS_V3
module-attribute
¶
ARRAY_METADATA_REQUIRED_KEYS_V3: Final[frozenset[str]] = (
frozenset(ZarrV3ArrayMetadataJSON.__required_keys__)
)
ARRAY_METADATA_STANDARD_KEYS_V3
module-attribute
¶
ARRAY_METADATA_STANDARD_KEYS_V3: Final[frozenset[str]] = (
ARRAY_METADATA_REQUIRED_KEYS_V3
| ARRAY_METADATA_OPTIONAL_KEYS_V3
)
GROUP_METADATA_OPTIONAL_KEYS_V3
module-attribute
¶
GROUP_METADATA_OPTIONAL_KEYS_V3: Final[frozenset[str]] = (
frozenset(ZarrV3GroupMetadataJSON.__optional_keys__)
)
GROUP_METADATA_REQUIRED_KEYS_V2
module-attribute
¶
GROUP_METADATA_REQUIRED_KEYS_V2: Final[frozenset[str]] = (
frozenset(ZarrV2GroupMetadataJSON.__required_keys__)
)
GROUP_METADATA_REQUIRED_KEYS_V3
module-attribute
¶
GROUP_METADATA_REQUIRED_KEYS_V3: Final[frozenset[str]] = (
frozenset(ZarrV3GroupMetadataJSON.__required_keys__)
)
GROUP_METADATA_STANDARD_KEYS_V3
module-attribute
¶
GROUP_METADATA_STANDARD_KEYS_V3: Final[frozenset[str]] = (
GROUP_METADATA_REQUIRED_KEYS_V3
| GROUP_METADATA_OPTIONAL_KEYS_V3
)
ProblemKind
module-attribute
¶
ProblemKind = Literal[
"missing_key",
"invalid_type",
"invalid_value",
"invalid_json",
]
Machine-readable classification of a ValidationProblem.
missing_key: a required key (document key or store key) is absent.invalid_type: a value has the wrong structural type (e.g. a string where a mapping is required, a non-JSON-serializable object).invalid_value: a value has an acceptable type but an invalid content (e.g.zarr_format: 2in a v3 document,order: "Q").invalid_json: bytes that do not decode as JSON.
UNSET
module-attribute
¶
Marks a metadata-document key as absent (PEP 661 sentinel; usable directly
in type expressions, e.g. tuple[str, ...] | UNSET). Test with is UNSET.
ZARR_V2_ARRAY_METADATA_STORE_KEY
module-attribute
¶
ZARR_V2_ARRAY_METADATA_STORE_KEY: Final[
ZarrV2ArrayMetadataStoreKey
] = ".zarray"
The store key a v2 array's metadata document is persisted under.
ZARR_V2_ATTRIBUTES_STORE_KEY
module-attribute
¶
ZARR_V2_ATTRIBUTES_STORE_KEY: Final[
ZarrV2AttributesStoreKey
] = ".zattrs"
The store key a v2 node's user attributes are persisted under.
Shared by arrays and groups: both node types keep their attributes in a
sibling .zattrs file.
ZARR_V2_CONSOLIDATED_METADATA_STORE_KEY
module-attribute
¶
ZARR_V2_CONSOLIDATED_METADATA_STORE_KEY: Final[
ZarrV2ConsolidatedMetadataStoreKey
] = ".zmetadata"
The store key a v2 hierarchy's consolidated metadata is persisted under.
Like the document it names, this is a reference-implementation convention rather than a spec artifact; see the module docstring.
ZARR_V2_GROUP_METADATA_STORE_KEY
module-attribute
¶
ZARR_V2_GROUP_METADATA_STORE_KEY: Final[
ZarrV2GroupMetadataStoreKey
] = ".zgroup"
The store key a v2 group's metadata document is persisted under.
ZARR_V3_ARRAY_METADATA_STORE_KEY
module-attribute
¶
ZARR_V3_ARRAY_METADATA_STORE_KEY: Final[
ZarrV3ArrayMetadataStoreKey
] = "zarr.json"
The store key a v3 array's metadata document is persisted under.
v3 uses one key for both node types; the document's node_type field
distinguishes an array from a group.
ZARR_V3_CONSOLIDATED_METADATA_KEY
module-attribute
¶
ZARR_V3_CONSOLIDATED_METADATA_KEY: Final = (
"consolidated_metadata"
)
The key under which consolidated metadata is embedded in a v3 group document.
Unlike the v2 .zmetadata file, this is not a store key: consolidated metadata
is carried as an extension field inside the group's own zarr.json. Like its v2
counterpart it is a reference-implementation convention, not a spec artifact.
ZARR_V3_GROUP_METADATA_STORE_KEY
module-attribute
¶
ZARR_V3_GROUP_METADATA_STORE_KEY: Final[
ZarrV3GroupMetadataStoreKey
] = "zarr.json"
The store key a v3 group's metadata document is persisted under.
v3 uses one key for both node types; the document's node_type field
distinguishes a group from an array.
ZarrV2ArrayMetadataStoreKey
module-attribute
¶
ZarrV2ArrayMetadataStoreKey = Literal['.zarray']
Literal type of the store key holding a v2 array's metadata document.
ZarrV2AttributesStoreKey
module-attribute
¶
ZarrV2AttributesStoreKey = Literal['.zattrs']
Literal type of the store key holding a v2 node's user attributes.
ZarrV2ConsolidatedMetadataStoreKey
module-attribute
¶
ZarrV2ConsolidatedMetadataStoreKey = Literal['.zmetadata']
Literal type of the store key holding a v2 hierarchy's consolidated metadata.
ZarrV2GroupMetadataStoreKey
module-attribute
¶
ZarrV2GroupMetadataStoreKey = Literal['.zgroup']
Literal type of the store key holding a v2 group's metadata document.
ZarrV3ArrayMetadataStoreKey
module-attribute
¶
ZarrV3ArrayMetadataStoreKey = Literal['zarr.json']
Literal type of the store key holding a v3 array's metadata document.
ZarrV3GroupMetadataStoreKey
module-attribute
¶
ZarrV3GroupMetadataStoreKey = Literal['zarr.json']
Literal type of the store key holding a v3 group's metadata document.
ZarrV3MetadataField
module-attribute
¶
ZarrV3MetadataField: TypeAlias = ZarrV3NamedConfig
The in-memory model of one field of a v3 metadata document.
This is the role-named alias for annotation positions: model fields and
consumer signatures should say ZarrV3MetadataField (the logical meaning)
rather than ZarrV3NamedConfig (the serialized form the field currently
takes). Today every metadata field normalizes to a named configuration plus
its reader obligation, so the alias is exactly ZarrV3NamedConfig; if a future
spec revision adds a field form that cannot be normalized to those values,
this alias widens to a union and annotation sites do not change. Mirrors the
raw-layer split between ZarrV3NamedConfigJSON (shape) and
ZarrV3MetadataFieldJSON (field union).
__all__
module-attribute
¶
__all__ = [
"ARRAY_METADATA_OPTIONAL_KEYS_V3",
"ARRAY_METADATA_REQUIRED_KEYS_V2",
"ARRAY_METADATA_REQUIRED_KEYS_V3",
"ARRAY_METADATA_STANDARD_KEYS_V3",
"GROUP_METADATA_OPTIONAL_KEYS_V3",
"GROUP_METADATA_REQUIRED_KEYS_V2",
"GROUP_METADATA_REQUIRED_KEYS_V3",
"GROUP_METADATA_STANDARD_KEYS_V3",
"UNSET",
"ZARR_V2_ARRAY_METADATA_STORE_KEY",
"ZARR_V2_ATTRIBUTES_STORE_KEY",
"ZARR_V2_CONSOLIDATED_METADATA_STORE_KEY",
"ZARR_V2_GROUP_METADATA_STORE_KEY",
"ZARR_V3_ARRAY_METADATA_STORE_KEY",
"ZARR_V3_CONSOLIDATED_METADATA_KEY",
"ZARR_V3_GROUP_METADATA_STORE_KEY",
"MetadataValidationError",
"ProblemKind",
"ValidationProblem",
"ZarrV2ArrayMetadata",
"ZarrV2ArrayMetadataPartial",
"ZarrV2ArrayMetadataStoreKey",
"ZarrV2AttributesStoreKey",
"ZarrV2ConsolidatedMetadata",
"ZarrV2ConsolidatedMetadataStoreKey",
"ZarrV2GroupMetadata",
"ZarrV2GroupMetadataPartial",
"ZarrV2GroupMetadataStoreKey",
"ZarrV3ArrayMetadata",
"ZarrV3ArrayMetadataPartial",
"ZarrV3ArrayMetadataStoreKey",
"ZarrV3ConsolidatedMetadata",
"ZarrV3GroupMetadata",
"ZarrV3GroupMetadataPartial",
"ZarrV3GroupMetadataStoreKey",
"ZarrV3MetadataField",
"ZarrV3NamedConfig",
"is_array_metadata_v2",
"is_array_metadata_v3",
"is_group_metadata_v2",
"is_group_metadata_v3",
"is_json",
"is_metadata_field_v3",
"parse_array_metadata_v2",
"parse_array_metadata_v3",
"parse_group_metadata_v2",
"parse_group_metadata_v3",
"parse_json",
"parse_metadata_field_v3",
"validate_array_metadata_v2",
"validate_array_metadata_v3",
"validate_group_metadata_v2",
"validate_group_metadata_v3",
"validate_json",
"validate_metadata_field_v3",
]
MetadataValidationError ¶
Bases: ValueError
Raised when a value fails structural metadata validation.
Carries every problem found (not just the first) in .problems.
Source code in src/zarr_metadata/model/_validation.py
ValidationProblem
dataclass
¶
A single structural problem found while validating a metadata document.
loc is the path from the document root to the offending value, e.g.
("codecs", 0, "name"). An empty loc refers to the document as a whole.
kind classifies the failure mode for programmatic dispatch; message
is the human-readable description.
Source code in src/zarr_metadata/model/_validation.py
ZarrV2ArrayMetadata
dataclass
¶
In-memory model of a v2 array metadata document.
A canonical, lossless representation of the .zarray content plus the
sibling .zattrs attributes. dtype, compressor, and filters are
held in their raw JSON forms and are never interpreted; fill_value is
held verbatim in its JSON form. attributes is UNSET when no
.zattrs file (or merged attributes key) exists — distinct from an
explicit empty .zattrs, which is {} and round-trips as a file. One
spelling normalization: a .zarray that omits dimension_separator
means "." by the v2 convention, and the model holds and re-emits that
value explicitly.
Source code in src/zarr_metadata/model/_array.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
dimension_separator
class-attribute
instance-attribute
¶
dimension_separator: ZarrV2ArrayDimensionSeparator = field(
default="."
)
zarr_format
class-attribute
instance-attribute
¶
__init__ ¶
__init__(
*,
shape: tuple[int, ...],
dtype: ZarrV2DataTypeMetadata,
chunks: tuple[int, ...],
fill_value: JSONValue,
order: ZarrV2ArrayOrder,
compressor: ZarrV2CodecMetadata | None,
filters: tuple[ZarrV2CodecMetadata, ...] | None,
dimension_separator: ZarrV2ArrayDimensionSeparator = ".",
attributes: dict[str, JSONValue] | UNSET,
) -> None
create_default
classmethod
¶
create_default(
**overrides: Unpack[ZarrV2ArrayMetadataPartial],
) -> ZarrV2ArrayMetadata
Create a default (empty) v2 array metadata model, with optional overrides.
The default is a structurally-valid scalar uint8 ("|u1") array — the
array analog of list() returning []. Any field can be overridden by
keyword (the same fields accepted by update). Overriding shape
without chunks derives chunks equal to shape (one chunk covering
the array).
The derivation is deliberately one-way, matching the v3 model:
overriding chunks without shape keeps the scalar default
shape=(), and consistency between the two is the caller's
responsibility.
Source code in src/zarr_metadata/model/_array.py
from_json
classmethod
¶
from_json(data: object) -> ZarrV2ArrayMetadata
Source code in src/zarr_metadata/model/_array.py
from_key_value
classmethod
¶
from_key_value(
mapping: Mapping[str, bytes],
) -> ZarrV2ArrayMetadata
Source code in src/zarr_metadata/model/_array.py
to_json ¶
to_json() -> ZarrV2ArrayMetadataJSON
Return the merged in-memory document form.
attributes is included when set (even empty). This is not the
on-disk .zarray content: a conforming .zarray must exclude
attributes (they live in the sibling .zattrs file). Use
to_key_value to produce the spec-conforming split for storage.
Source code in src/zarr_metadata/model/_array.py
to_key_value ¶
to_key_value(
*, indent: int | str | None = None
) -> Mapping[
ZarrV2ArrayMetadataStoreKey | ZarrV2AttributesStoreKey,
bytes,
]
Source code in src/zarr_metadata/model/_array.py
update ¶
update(
**kwargs: Unpack[ZarrV2ArrayMetadataPartial],
) -> ZarrV2ArrayMetadata
Return a new ZarrV2ArrayMetadata with the given fields updated.
Only the constructor-settable fields listed in
ZarrV2ArrayMetadataPartial can be updated; the fixed zarr_format is
rejected at the type level. Each given field fully replaces its previous
value.
Source code in src/zarr_metadata/model/_array.py
ZarrV2ArrayMetadataPartial ¶
Bases: TypedDict
Partial form of the constructor-settable fields of ZarrV2ArrayMetadata.
Every key is optional and typed with the model's own value types, so it
describes valid keyword arguments to ZarrV2ArrayMetadata.update and
create_default. The init=False field zarr_format is intentionally
excluded, since it cannot be passed to dataclasses.replace.
Drift between this type and the model's settable fields is prevented by
tests/model/test_array.py::test_v2_partial_keys_match_settable_model_fields.
Source code in src/zarr_metadata/model/_array.py
ZarrV2ConsolidatedMetadata
dataclass
¶
In-memory model of a v2 .zmetadata document.
The metadata map holds the flat file-keyed entries ("path/.zarray",
"path/.zattrs", ...) verbatim, preserving the normalized JSON tree.
Entries are deliberately NOT merged into per-node models: which nodes had
a .zattrs file at all is information the canonical representation must
keep. Interpreting entries into node models is consumer work.
Source code in src/zarr_metadata/model/_group.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
zarr_consolidated_format
class-attribute
instance-attribute
¶
from_json
classmethod
¶
from_json(data: object) -> ZarrV2ConsolidatedMetadata
Source code in src/zarr_metadata/model/_group.py
from_key_value
classmethod
¶
from_key_value(
mapping: Mapping[str, bytes],
) -> ZarrV2ConsolidatedMetadata
to_json ¶
ZarrV2GroupMetadata
dataclass
¶
In-memory model of a v2 group metadata document.
A canonical, lossless representation of the .zgroup content plus the
sibling .zattrs attributes, folded into a single in-memory value
(mirroring the merged ZarrV2GroupMetadataJSON document form). attributes is
UNSET when no .zattrs file (or merged attributes key) exists —
distinct from an explicit empty .zattrs, which is {} and round-trips
as a file.
Source code in src/zarr_metadata/model/_group.py
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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
zarr_format
class-attribute
instance-attribute
¶
create_default
classmethod
¶
create_default(
**overrides: Unpack[ZarrV2GroupMetadataPartial],
) -> ZarrV2GroupMetadata
Create a default (empty) v2 group metadata model, with optional overrides.
The default is a structurally-valid group with no attributes — the group
analog of list() returning []. Any field can be overridden by keyword
(the same fields accepted by update).
Source code in src/zarr_metadata/model/_group.py
from_json
classmethod
¶
from_json(data: object) -> ZarrV2GroupMetadata
from_key_value
classmethod
¶
from_key_value(
mapping: Mapping[str, bytes],
) -> ZarrV2GroupMetadata
Source code in src/zarr_metadata/model/_group.py
to_json ¶
to_json() -> ZarrV2GroupMetadataJSON
Return the merged in-memory document form.
attributes is included when set (even empty). This is not the
on-disk .zgroup content: a conforming .zgroup must exclude
attributes (they live in the sibling .zattrs file). Use
to_key_value to produce the spec-conforming split for storage.
Source code in src/zarr_metadata/model/_group.py
to_key_value ¶
to_key_value(
*, indent: int | str | None = None
) -> Mapping[
ZarrV2GroupMetadataStoreKey | ZarrV2AttributesStoreKey,
bytes,
]
Source code in src/zarr_metadata/model/_group.py
update ¶
update(
**kwargs: Unpack[ZarrV2GroupMetadataPartial],
) -> ZarrV2GroupMetadata
Return a new ZarrV2GroupMetadata with the given fields updated.
Only the constructor-settable fields listed in
ZarrV2GroupMetadataPartial can be updated; the fixed zarr_format
is rejected at the type level. Each given field fully replaces its
previous value.
Source code in src/zarr_metadata/model/_group.py
ZarrV2GroupMetadataPartial ¶
Bases: TypedDict
Partial form of the constructor-settable fields of ZarrV2GroupMetadata.
Every key is optional and typed with the model's own value types, so it
describes valid keyword arguments to ZarrV2GroupMetadata.update and
create_default. The init=False field zarr_format is intentionally
excluded, since it cannot be passed to dataclasses.replace.
Drift between this type and the model's settable fields is prevented by
tests/model/test_group.py::test_group_partial_keys_match_settable_model_fields.
Source code in src/zarr_metadata/model/_group.py
ZarrV3ArrayMetadata
dataclass
¶
In-memory model of a v3 array metadata document.
A canonical, semantically lossless representation of the zarr.json
content for an array. Extension points (data_type, chunk_grid,
chunk_key_encoding, codecs, storage_transformers) are held as
ZarrV3MetadataField values (currently ZarrV3NamedConfig name,
configuration, and obligation records) and are never interpreted;
fill_value is held verbatim in its JSON form. Equivalent extension
spellings normalize to shorthand strings when configuration is empty and
understanding is required.
Source code in src/zarr_metadata/model/_array.py
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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
must_understand_fields
property
¶
must_understand_fields: dict[str, ZarrV3ExtensionField]
Extra fields the reader is obligated to understand.
Everything in extra_fields not explicitly waived with
must_understand: false (the spec's implicit-true rule). A compliant
reader MUST fail to open the array if this contains any field it does
not recognize; the model layer only partitions by obligation, since
recognition is reader-specific.
node_type
class-attribute
instance-attribute
¶
zarr_format
class-attribute
instance-attribute
¶
__init__ ¶
__init__(
*,
shape: tuple[int, ...],
fill_value: JSONValue,
data_type: ZarrV3MetadataField,
chunk_grid: ZarrV3MetadataField,
codecs: tuple[ZarrV3MetadataField, ...],
chunk_key_encoding: ZarrV3MetadataField,
dimension_names: tuple[str | None, ...] | UNSET,
attributes: dict[str, JSONValue],
storage_transformers: tuple[ZarrV3MetadataField, ...],
extra_fields: dict[str, ZarrV3ExtensionField],
) -> None
__post_init__ ¶
Source code in src/zarr_metadata/model/_array.py
create_default
classmethod
¶
create_default(
**overrides: Unpack[ZarrV3ArrayMetadataPartial],
) -> ZarrV3ArrayMetadata
Create a default (empty) v3 array metadata model, with optional overrides.
The default is a structurally-valid scalar uint8 array — the array
analog of list() returning []. Any field can be overridden by keyword
(the same fields accepted by update). Overriding shape without
chunk_grid derives a consistent default grid: one regular chunk
covering the array (chunk_shape equal to shape).
The derivation is deliberately one-way. A user-supplied chunk_grid
is an extension point and is taken verbatim — deriving shape from
it would require interpreting the grid's configuration, which this
layer never does (and cannot do for unrecognized grid names). So
overriding chunk_grid without shape keeps the scalar default
shape=(), and consistency between the two is the caller's
responsibility.
Source code in src/zarr_metadata/model/_array.py
from_json
classmethod
¶
from_json(data: object) -> ZarrV3ArrayMetadata
Source code in src/zarr_metadata/model/_array.py
from_key_value
classmethod
¶
from_key_value(
mapping: Mapping[str, bytes],
) -> ZarrV3ArrayMetadata
to_json ¶
to_json() -> ZarrV3ArrayMetadataJSON
Source code in src/zarr_metadata/model/_array.py
to_key_value ¶
to_key_value(
*, indent: int | str | None = None
) -> Mapping[ZarrV3ArrayMetadataStoreKey, bytes]
update ¶
update(
**kwargs: Unpack[ZarrV3ArrayMetadataPartial],
) -> ZarrV3ArrayMetadata
Return a new ZarrV3ArrayMetadata with the given fields updated.
Only the constructor-settable fields listed in
ZarrV3ArrayMetadataPartial can be updated; any attempt to update
other fields (including the fixed zarr_format / node_type) is
rejected at the type level. Each given field fully replaces its
previous value, including extra_fields.
This is useful for test fixtures that want to override a few fields of a base template without having to re-specify the entire document.
No re-validation is performed (update is dataclasses.replace), so
a repair or edit can produce an invalid document; validity is checked
on from_json, not on field replacement.
Source code in src/zarr_metadata/model/_array.py
ZarrV3ArrayMetadataPartial ¶
Bases: TypedDict
Partial form of the constructor-settable fields of ZarrV3ArrayMetadata.
Every key is optional and typed with the model's own (not serialized)
value types, so it describes valid keyword arguments to
ZarrV3ArrayMetadata.update. The init=False fields zarr_format and
node_type are intentionally excluded, since they cannot be passed to
dataclasses.replace.
Drift between this type and the model's settable fields is prevented by
tests/model/test_array.py::test_partial_keys_match_settable_model_fields.
Source code in src/zarr_metadata/model/_array.py
ZarrV3ConsolidatedMetadata
dataclass
¶
In-memory model of v3 inline consolidated metadata.
Models the reference-implementation convention where consolidated metadata
is embedded as an extension field on a group's zarr.json. Each entry in
metadata is a complete child document, held as a thin array or group
model. must_understand is typed permissively as bool to mirror the
document shape, but only False is valid; this is enforced at runtime.
Source code in src/zarr_metadata/model/_group.py
kind
class-attribute
instance-attribute
¶
__init__ ¶
__init__(
*,
must_understand: bool = False,
metadata: dict[
str, ZarrV3ArrayMetadata | ZarrV3GroupMetadata
],
) -> None
__post_init__ ¶
Source code in src/zarr_metadata/model/_group.py
from_json
classmethod
¶
from_json(data: object) -> ZarrV3ConsolidatedMetadata
Source code in src/zarr_metadata/model/_group.py
to_json ¶
to_json() -> ZarrV3ConsolidatedMetadataJSON
Source code in src/zarr_metadata/model/_group.py
ZarrV3GroupMetadata
dataclass
¶
In-memory model of a v3 group metadata document.
A canonical, semantically lossless representation of the zarr.json
content for a group. The consolidated_metadata reference-implementation
convention is modeled as a typed field holding thin child models; every
other unknown top-level key lands in extra_fields verbatim.
Source code in src/zarr_metadata/model/_group.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 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 | |
consolidated_metadata
instance-attribute
¶
consolidated_metadata: ZarrV3ConsolidatedMetadata | UNSET
must_understand_fields
property
¶
must_understand_fields: dict[str, ZarrV3ExtensionField]
Extra fields the reader is obligated to understand.
Everything in extra_fields not explicitly waived with
must_understand: false (the spec's implicit-true rule). A compliant
reader MUST fail to open the group if this contains any field it does
not recognize; the model layer only partitions by obligation, since
recognition is reader-specific.
node_type
class-attribute
instance-attribute
¶
zarr_format
class-attribute
instance-attribute
¶
__init__ ¶
__init__(
*,
attributes: dict[str, JSONValue],
consolidated_metadata: ZarrV3ConsolidatedMetadata
| UNSET,
extra_fields: dict[str, ZarrV3ExtensionField],
) -> None
__post_init__ ¶
Source code in src/zarr_metadata/model/_group.py
create_default
classmethod
¶
create_default(
**overrides: Unpack[ZarrV3GroupMetadataPartial],
) -> ZarrV3GroupMetadata
Create a default (empty) v3 group metadata model, with optional overrides.
The default is a structurally-valid group with no attributes — the group
analog of list() returning []. Any field can be overridden by keyword
(the same fields accepted by update).
Source code in src/zarr_metadata/model/_group.py
from_json
classmethod
¶
from_json(data: object) -> ZarrV3GroupMetadata
Source code in src/zarr_metadata/model/_group.py
from_key_value
classmethod
¶
from_key_value(
mapping: Mapping[str, bytes],
) -> ZarrV3GroupMetadata
to_json ¶
to_json() -> ZarrV3GroupMetadataJSON
Source code in src/zarr_metadata/model/_group.py
to_key_value ¶
to_key_value(
*, indent: int | str | None = None
) -> Mapping[ZarrV3GroupMetadataStoreKey, bytes]
update ¶
update(
**kwargs: Unpack[ZarrV3GroupMetadataPartial],
) -> ZarrV3GroupMetadata
Return a new ZarrV3GroupMetadata with the given fields updated.
Only the constructor-settable fields listed in
ZarrV3GroupMetadataPartial can be updated; the fixed zarr_format /
node_type are rejected at the type level. Each given field fully
replaces its previous value, including extra_fields.
Source code in src/zarr_metadata/model/_group.py
ZarrV3GroupMetadataPartial ¶
Bases: TypedDict
Partial form of the constructor-settable fields of ZarrV3GroupMetadata.
Every key is optional and typed with the model's own value types, so it
describes valid keyword arguments to ZarrV3GroupMetadata.update and
create_default. The init=False fields zarr_format and node_type
are intentionally excluded, since they cannot be passed to
dataclasses.replace.
Drift between this type and the model's settable fields is prevented by
tests/model/test_group.py::test_group_partial_keys_match_settable_model_fields.
Source code in src/zarr_metadata/model/_group.py
ZarrV3NamedConfig
dataclass
¶
A normalized v3 metadata field with its reader obligation.
Bare names and missing configurations normalize to an empty configuration.
Bare names and missing must_understand members normalize to the spec's
implicit True value.
Source code in src/zarr_metadata/model/_array.py
__init__ ¶
__init__(
*,
name: str,
configuration: dict[str, JSONValue],
must_understand: bool = True,
) -> None
from_json
classmethod
¶
from_json(data: object) -> ZarrV3NamedConfig
Source code in src/zarr_metadata/model/_array.py
to_json ¶
to_json() -> ZarrV3MetadataFieldJSON
Source code in src/zarr_metadata/model/_array.py
is_array_metadata_v2 ¶
is_array_metadata_v2(
value: object,
) -> TypeIs[ZarrV2ArrayMetadataJSON]
Whether value is a structurally-valid v2 array metadata document.
Source code in src/zarr_metadata/model/_validation.py
is_array_metadata_v3 ¶
is_array_metadata_v3(
value: object,
) -> TypeIs[ZarrV3ArrayMetadataJSON]
Whether value is a structurally-valid v3 array metadata document.
Source code in src/zarr_metadata/model/_validation.py
is_group_metadata_v2 ¶
is_group_metadata_v2(
value: object,
) -> TypeIs[ZarrV2GroupMetadataJSON]
Whether value is a structurally-valid v2 group metadata document.
is_group_metadata_v3 ¶
is_group_metadata_v3(
value: object,
) -> TypeIs[ZarrV3GroupMetadataJSON]
Whether value is a structurally-valid v3 group metadata document.
is_json ¶
is_metadata_field_v3 ¶
is_metadata_field_v3(
value: object,
) -> TypeIs[ZarrV3MetadataFieldJSON]
Whether value is a v3 metadata field: a bare name or a named config.
Source code in src/zarr_metadata/model/_validation.py
parse_array_metadata_v2 ¶
parse_array_metadata_v2(
value: object,
) -> ZarrV2ArrayMetadataJSON
Return value as ZarrV2ArrayMetadataJSON, or raise MetadataValidationError.
Source code in src/zarr_metadata/model/_validation.py
parse_array_metadata_v3 ¶
parse_array_metadata_v3(
value: object,
) -> ZarrV3ArrayMetadataJSON
Return value as ZarrV3ArrayMetadataJSON, or raise MetadataValidationError.
Source code in src/zarr_metadata/model/_validation.py
parse_group_metadata_v2 ¶
parse_group_metadata_v2(
value: object,
) -> ZarrV2GroupMetadataJSON
Return value narrowed to ZarrV2GroupMetadataJSON, or raise MetadataValidationError.
Source code in src/zarr_metadata/model/_validation.py
parse_group_metadata_v3 ¶
parse_group_metadata_v3(
value: object,
) -> ZarrV3GroupMetadataJSON
Return value narrowed to ZarrV3GroupMetadataJSON, or raise MetadataValidationError.
Source code in src/zarr_metadata/model/_validation.py
parse_json ¶
Return a canonical JSONValue, or raise MetadataValidationError.
Source code in src/zarr_metadata/model/_validation.py
parse_metadata_field_v3 ¶
parse_metadata_field_v3(
value: object,
) -> ZarrV3MetadataFieldJSON
Return value narrowed to ZarrV3MetadataFieldJSON, or raise MetadataValidationError.
Source code in src/zarr_metadata/model/_validation.py
validate_array_metadata_v2 ¶
validate_array_metadata_v2(
value: object,
) -> list[ValidationProblem]
Return every reason value is not a structurally-valid v2 array doc.
Checks structure, not domain validity: dtype must be a string or field
records, but the string content is not interpreted; compressor and
filters are required keys that may be None, and otherwise must be
codec configurations (mappings with a string id).
Source code in src/zarr_metadata/model/_validation.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | |
validate_array_metadata_v3 ¶
validate_array_metadata_v3(
value: object,
) -> list[ValidationProblem]
Return every reason value is not a structurally-valid v3 array doc.
Checks structure, not domain validity. Unknown top-level keys are allowed
(they map to extra_fields).
Source code in src/zarr_metadata/model/_validation.py
validate_group_metadata_v2 ¶
validate_group_metadata_v2(
value: object,
) -> list[ValidationProblem]
Return every reason value is not a structurally-valid v2 group doc.
Validates the in-memory merged form: the .zgroup fields plus an
optional attributes mapping folded in from .zattrs.
Source code in src/zarr_metadata/model/_validation.py
validate_group_metadata_v3 ¶
validate_group_metadata_v3(
value: object,
) -> list[ValidationProblem]
Return every reason value is not a structurally-valid v3 group doc.
Checks structure, not domain validity. Unknown top-level keys are allowed
(they map to extra_fields); a consolidated_metadata key, if present,
is deep-validated (envelope and entries) via
validate_consolidated_metadata_v3.
Source code in src/zarr_metadata/model/_validation.py
validate_json ¶
validate_json(value: object) -> list[ValidationProblem]
Return every reason value is not JSON-serializable (recursively).
Source code in src/zarr_metadata/model/_validation.py
validate_metadata_field_v3 ¶
validate_metadata_field_v3(
value: object,
*,
allow_must_understand_false: bool = True,
) -> list[ValidationProblem]
Return every reason value is not a v3 metadata field.
A metadata field is a bare name string or a mapping containing name and
optional configuration and must_understand members.