zarr_metadata.rules
zarr_metadata.rules ¶
Validate structure and composition of Zarr metadata documents.
zarr_metadata.model checks JSON structure. This module also checks
cross-field constraints such as fill-value compatibility, codec
ordering, and dimension counts. Its validate_* and parse_* functions
mirror the model API, and canonicalize_array_metadata_v3 answers with
either the document in its simplest equivalent spelling or every reason
it is not valid.
Rules target canonical metadata and may be stricter than readers that
coerce inputs. Unknown entity names are left unjudged. Known entities
must match their modeled shape; extra configuration keys produce an
unknown_key problem without suppressing other checks. Model
round-trips preserve those unmodeled members.
__all__
module-attribute
¶
__all__ = [
"Canonical",
"Invalid",
"canonicalize_array_metadata_v3",
"parse_array_metadata_v2",
"parse_array_metadata_v3",
"parse_group_metadata_v2",
"parse_group_metadata_v3",
"validate_array_metadata_v2",
"validate_array_metadata_v3",
"validate_group_metadata_v2",
"validate_group_metadata_v3",
]
Canonical
dataclass
¶
Bases: Generic[DocumentT]
A semantically valid document, in its simplest equivalent spelling.
Source code in src/zarr_metadata/rules/_canonical.py
Invalid
dataclass
¶
Every reason a document is not semantically valid; never empty.
Source code in src/zarr_metadata/rules/_canonical.py
__init__ ¶
__init__(
problems: tuple[ValidationProblem, ...],
valid: Literal[False] = False,
) -> None
canonicalize_array_metadata_v3 ¶
canonicalize_array_metadata_v3(
document: ZarrV3ArrayMetadataJSON,
*,
context: Context = CORE_AND_EXTENSIONS,
) -> Canonical[ZarrV3ArrayMetadataJSON] | Invalid
document in canonical form, or every reason it is not valid.
Expects a document the model layer has already accepted. Passing one
it has not is not an error -- the semantic problems are reported the
same way -- but the structural problems come back too, and the result
is Invalid rather than a canonical document.
Source code in src/zarr_metadata/rules/_canonical.py
parse_array_metadata_v2 ¶
parse_array_metadata_v2(
value: object,
) -> ZarrV2ArrayMetadataJSON
Return value as a valid ZarrV2ArrayMetadataJSON, or raise.
Normalizes JSON arrays to tuples, then raises a single
MetadataValidationError carrying every structural and composition
problem found.
Source code in src/zarr_metadata/rules/_documents.py
parse_array_metadata_v3 ¶
parse_array_metadata_v3(
value: object, *, context: Context = CORE_AND_EXTENSIONS
) -> ZarrV3ArrayMetadataJSON
Return value as a valid ZarrV3ArrayMetadataJSON, or raise.
Normalizes JSON arrays to tuples, then raises a single
MetadataValidationError carrying every structural and composition
problem found.
Source code in src/zarr_metadata/rules/_documents.py
parse_group_metadata_v2 ¶
parse_group_metadata_v2(
value: object,
) -> ZarrV2GroupMetadataJSON
Return value as a valid ZarrV2GroupMetadataJSON, or raise.
Source code in src/zarr_metadata/rules/_documents.py
parse_group_metadata_v3 ¶
parse_group_metadata_v3(
value: object, *, context: Context = CORE_AND_EXTENSIONS
) -> ZarrV3GroupMetadataJSON
Return value as a valid ZarrV3GroupMetadataJSON, or raise.
Source code in src/zarr_metadata/rules/_documents.py
validate_array_metadata_v2 ¶
validate_array_metadata_v2(
value: object,
) -> tuple[ValidationProblem, ...]
Every reason value is not a valid v2 array document (merged form).
JSON arrays are normalized to tuples before judgment, as in
validate_array_metadata_v3.
Source code in src/zarr_metadata/rules/_documents.py
validate_array_metadata_v3 ¶
validate_array_metadata_v3(
value: object, *, context: Context = CORE_AND_EXTENSIONS
) -> tuple[ValidationProblem, ...]
Why value is not a valid v3 array document.
Every structural problem, and every semantic problem that can be determined. One member that cannot be read costs the composition judgments about the entity holding it -- whether a shard's inner shape divides the array it is handed cannot be answered by a shard that could not be built -- so a document with two defects in one configuration may need a second pass. The verdict is never affected.
Structural problems (from the model layer) and semantic problems
(from the entities themselves) are reported together. JSON arrays are
normalized to tuples before judgment, so list-spelled documents
(e.g. fresh json.loads output) are judged at the canonical data
level rather than rejected for their spelling.
Source code in src/zarr_metadata/rules/_documents.py
validate_group_metadata_v2 ¶
validate_group_metadata_v2(
value: object,
) -> tuple[ValidationProblem, ...]
Every reason value is not a valid v2 group document (merged form).
v2 group documents carry no composition constraints today, so this is the structural judgment, offered here for a uniform read-side API.
Source code in src/zarr_metadata/rules/_documents.py
validate_group_metadata_v3 ¶
validate_group_metadata_v3(
value: object, *, context: Context = CORE_AND_EXTENSIONS
) -> tuple[ValidationProblem, ...]
Every reason value is not a valid v3 group document.
Composition rules recurse into inline consolidated metadata, so a consolidated child document invalid under its own rules is reported here, at its path.