sdmxlib 0.72.1__tar.gz → 0.74.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/PKG-INFO +8 -1
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/README.md +7 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/pyproject.toml +2 -1
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/pyproject.toml.orig +5 -1
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/__init__.py +13 -2
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/builders/contentconstraint.py +6 -6
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/builders/metadata_annotation.py +4 -4
- sdmxlib-0.74.0/src/sdmxlib/bundle/__init__.py +138 -0
- sdmxlib-0.74.0/src/sdmxlib/bundle/_canonical.py +146 -0
- sdmxlib-0.74.0/src/sdmxlib/bundle/_check.py +436 -0
- sdmxlib-0.74.0/src/sdmxlib/bundle/_copy.py +96 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/bundle/_fetch.py +10 -8
- sdmxlib-0.74.0/src/sdmxlib/bundle/_finding.py +24 -0
- sdmxlib-0.74.0/src/sdmxlib/bundle/_fingerprint.py +148 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/bundle/_overlay.py +210 -35
- sdmxlib-0.74.0/src/sdmxlib/bundle/_remote.py +85 -0
- sdmxlib-0.74.0/src/sdmxlib/bundle/_write.py +476 -0
- sdmxlib-0.74.0/src/sdmxlib/bundle/manifest.schema.json +349 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/bundle/overlay.schema.json +63 -2
- sdmxlib-0.74.0/src/sdmxlib/formats/render.py +61 -0
- sdmxlib-0.74.0/src/sdmxlib/local/__init__.py +8 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/local/data_store.py +24 -12
- sdmxlib-0.74.0/src/sdmxlib/local/engine.py +147 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/local/registry.py +691 -424
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/query.py +4 -4
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/session.py +46 -0
- sdmxlib-0.74.0/src/sdmxlib/storage/_manifest.py +431 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/storage/_projections.py +4 -3
- sdmxlib-0.74.0/src/sdmxlib/storage/_references.py +249 -0
- sdmxlib-0.74.0/src/sdmxlib/storage/_trim.py +159 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/storage/readers.py +8 -5
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/storage/schema.py +40 -3
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/storage/writers.py +12 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/testing.py +235 -22
- sdmxlib-0.72.1/src/sdmxlib/bundle/__init__.py +0 -99
- sdmxlib-0.72.1/src/sdmxlib/bundle/_check.py +0 -217
- sdmxlib-0.72.1/src/sdmxlib/bundle/_write.py +0 -109
- sdmxlib-0.72.1/src/sdmxlib/bundle/manifest.schema.json +0 -212
- sdmxlib-0.72.1/src/sdmxlib/local/__init__.py +0 -7
- sdmxlib-0.72.1/src/sdmxlib/storage/_manifest.py +0 -184
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/LICENSE +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/_duckdb.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/_singleflight.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/_time.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/api/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/api/_freshness.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/api/client.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/api/federated.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/api/policy.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/api/providers.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/api/registry.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/api/session.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/builders/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/data_store.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/_arrow.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/_attachment.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/_coerce.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/_index.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/_positions.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/_refuse.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/data_format.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/gaps.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_csv/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_csv/reader.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_csv/writer.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/_data_common.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/_dto.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/_header.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/_losses.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/_periods.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/_resolve.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/_structure_dto.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/_structure_ingest.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/data.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/data_v1.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/data_v2.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/metadata.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/reader.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/structure_values.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json/writer.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json_1_0/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_json_1_0/writer.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml/_allowed_children.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml/_closed_world.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml/_common.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml/_header.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml/_losses.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml/_v3_reader.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml/_v3_writer.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml21/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml21/_providers.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml21/_synthetic.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml21/namespaces.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml21/reader.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml21/writer.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml30/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml30/metadata.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml30/namespaces.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml30/reader.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml30/writer.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml31/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml31/namespaces.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml31/reader.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/formats/sdmx_ml31/writer.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/local/_scan.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/local/sql.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/_binding.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/_container.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/_invariants.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/_items.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/_label_match.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/_rebind.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/_referenceable.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/_refshape.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/_resolvers.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/_rules.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/_tree.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/annotations.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/base.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/binding.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/category.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/codelist.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/collections.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/concept.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/constraint.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/convert.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/dataflow.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/datastructure.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/errors.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/expr.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/header.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/hierarchy.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/in_memory_registry.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/istring.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/link.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/mapping.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/message.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/metadata_provision.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/metadataflow.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/metadataset.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/metadatastructure.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/organisation.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/provision.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/ref.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/registry.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/representation.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/rest_api.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/rollup.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/urn.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/validation.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/valuelist.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/version.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/model/version_rewrite.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/polars.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/py.typed +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/_closure.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/_common.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/_compile.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/_edges.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/_execute.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/_expr.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/_joins.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/_plan.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/_pushdown.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/_rebase.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/_rest.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/accessors.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/observations.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/raw.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/query/schema.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/rest.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/sql.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/storage/__init__.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/storage/_checked.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/storage/_kinds.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/storage/_parsed.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/storage/_synthetic.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/storage/lazy.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/storage/resolve.py +0 -0
- {sdmxlib-0.72.1 → sdmxlib-0.74.0}/src/sdmxlib/versions.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sdmxlib
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.74.0
|
|
4
4
|
Summary: SDMX for Python: structures, reference metadata and observation data, from REST, files or a local DuckDB store.
|
|
5
5
|
Keywords: sdmx,statistics,metadata,datastructure
|
|
6
6
|
Author: gabrielgellner
|
|
@@ -31,6 +31,13 @@ Description-Content-Type: text/markdown
|
|
|
31
31
|
|
|
32
32
|
# sdmxlib
|
|
33
33
|
|
|
34
|
+
[](https://pypi.org/project/sdmxlib/)
|
|
35
|
+
[](https://pypi.org/project/sdmxlib/)
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
[](https://statcat-suite.github.io/sdmxlib/)
|
|
38
|
+
[](https://github.com/astral-sh/uv)
|
|
39
|
+
[](https://github.com/astral-sh/ruff)
|
|
40
|
+
|
|
34
41
|
> **Note:** This library has been written extensively with AI assistance
|
|
35
42
|
> (Claude Code). Users who are not comfortable with AI-generated code should
|
|
36
43
|
> take that into account before adopting it.
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# sdmxlib
|
|
2
2
|
|
|
3
|
+
[](https://pypi.org/project/sdmxlib/)
|
|
4
|
+
[](https://pypi.org/project/sdmxlib/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://statcat-suite.github.io/sdmxlib/)
|
|
7
|
+
[](https://github.com/astral-sh/uv)
|
|
8
|
+
[](https://github.com/astral-sh/ruff)
|
|
9
|
+
|
|
3
10
|
> **Note:** This library has been written extensively with AI assistance
|
|
4
11
|
> (Claude Code). Users who are not comfortable with AI-generated code should
|
|
5
12
|
> take that into account before adopting it.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sdmxlib"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.74.0"
|
|
4
4
|
description = "SDMX for Python: structures, reference metadata and observation data, from REST, files or a local DuckDB store."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -58,6 +58,7 @@ markers = [
|
|
|
58
58
|
"serial: thread-heavy tests `just test` runs alone, after the parallel phase; under -n they starve",
|
|
59
59
|
"bench: performance benchmarks; excluded from default test runs",
|
|
60
60
|
"bundle: benchmarks against a real SDMX bundle; need $SDMXLIB_BENCH_BUNDLE",
|
|
61
|
+
"recompute: bundle-tier assertions that recompute what publishing computed; in `just bench-bundle`, not `just ci`",
|
|
61
62
|
]
|
|
62
63
|
|
|
63
64
|
[tool.coverage.run]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sdmxlib"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.74.0"
|
|
4
4
|
description = "SDMX for Python: structures, reference metadata and observation data, from REST, files or a local DuckDB store."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -87,6 +87,10 @@ markers = [
|
|
|
87
87
|
# cannot be, in the repo. Split from `bench` so `just bench` means the same
|
|
88
88
|
# thing on every machine and `bench/baselines/` stays comparable across them.
|
|
89
89
|
"bundle: benchmarks against a real SDMX bundle; need $SDMXLIB_BENCH_BUNDLE",
|
|
90
|
+
# An assertion that redoes what publishing computed — the census `publish`
|
|
91
|
+
# check recomputes every fingerprint, about 6.5 minutes. `just ci` leaves it
|
|
92
|
+
# out; `just bench-bundle` runs it.
|
|
93
|
+
"recompute: bundle-tier assertions that recompute what publishing computed; in `just bench-bundle`, not `just ci`",
|
|
90
94
|
]
|
|
91
95
|
|
|
92
96
|
[tool.coverage.run]
|
|
@@ -46,14 +46,22 @@ from sdmxlib.query._joins import PathError
|
|
|
46
46
|
from sdmxlib.query._pushdown import PushdownError
|
|
47
47
|
from sdmxlib.sql import SqlRelation
|
|
48
48
|
from sdmxlib.formats import parse, read, serialize, to_json, to_xml
|
|
49
|
-
from sdmxlib.local import
|
|
49
|
+
from sdmxlib.local import (
|
|
50
|
+
BundleEngine,
|
|
51
|
+
BundleRegistry,
|
|
52
|
+
LazyCodelist,
|
|
53
|
+
LazyHierarchy,
|
|
54
|
+
QueryPlan,
|
|
55
|
+
LocalRegistry,
|
|
56
|
+
SchemaInspector,
|
|
57
|
+
)
|
|
50
58
|
from sdmxlib.local.data_store import DuckDBDataStore, DuckLakeVersionError
|
|
51
59
|
from sdmxlib.local.sql import SidecarNotUniqueError
|
|
52
60
|
from sdmxlib.rest import ComponentFilter, parse_components, widen_key
|
|
53
61
|
from sdmxlib.query._common import Descending
|
|
54
62
|
from sdmxlib.model.convert import from_dict, to_dict
|
|
55
63
|
from sdmxlib.model.errors import ImRuleWarning, ReadAssumption, ReadGap, SdmxWarning
|
|
56
|
-
from sdmxlib.storage._manifest import ManifestError
|
|
64
|
+
from sdmxlib.storage._manifest import ManifestError, StoreFormatError
|
|
57
65
|
from sdmxlib.storage.schema import StoreSchemaError
|
|
58
66
|
from sdmxlib.model.validation import (
|
|
59
67
|
LossyReadError,
|
|
@@ -241,6 +249,8 @@ __all__ = [
|
|
|
241
249
|
"AttributeUsage",
|
|
242
250
|
"AvailabilityConstraint",
|
|
243
251
|
"BearerToken",
|
|
252
|
+
"BundleEngine",
|
|
253
|
+
"BundleRegistry",
|
|
244
254
|
"CascadeSelection",
|
|
245
255
|
"Categorisation",
|
|
246
256
|
"Category",
|
|
@@ -402,6 +412,7 @@ __all__ = [
|
|
|
402
412
|
"SliceError",
|
|
403
413
|
"SourceValue",
|
|
404
414
|
"SqlRelation",
|
|
415
|
+
"StoreFormatError",
|
|
405
416
|
"StoreSchemaError",
|
|
406
417
|
"Str",
|
|
407
418
|
"StructureMap",
|
|
@@ -31,7 +31,7 @@ from typing import Literal
|
|
|
31
31
|
|
|
32
32
|
import duckdb
|
|
33
33
|
|
|
34
|
-
from sdmxlib.local.registry import
|
|
34
|
+
from sdmxlib.local.registry import BundleRegistry
|
|
35
35
|
from sdmxlib.model.binding import DataflowBinding
|
|
36
36
|
from sdmxlib.model.constraint import (
|
|
37
37
|
ComponentValueSet,
|
|
@@ -51,7 +51,7 @@ from sdmxlib.rest import ComponentFilter, parse_components
|
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
def build_dataflow_constraint(
|
|
54
|
-
registry:
|
|
54
|
+
registry: BundleRegistry,
|
|
55
55
|
dataflow_urn: SdmxUrn[Dataflow],
|
|
56
56
|
*,
|
|
57
57
|
name: InternationalString | dict[str, str],
|
|
@@ -73,7 +73,7 @@ def build_dataflow_constraint(
|
|
|
73
73
|
right source for an "actual availability" statement.
|
|
74
74
|
|
|
75
75
|
Args:
|
|
76
|
-
registry: An open `LocalRegistry`. Used to look up the
|
|
76
|
+
registry: An open registry: a published `BundleRegistry` or a `LocalRegistry`. Used to look up the
|
|
77
77
|
binding and (when ``conn`` is omitted) the DuckDB connection.
|
|
78
78
|
dataflow_urn: URN of the dataflow to describe.
|
|
79
79
|
name: The constraint's name, in each language it has. Required: SDMX
|
|
@@ -135,7 +135,7 @@ def build_dataflow_constraint(
|
|
|
135
135
|
|
|
136
136
|
|
|
137
137
|
def build_component_availability(
|
|
138
|
-
registry:
|
|
138
|
+
registry: BundleRegistry,
|
|
139
139
|
dataflow_urn: SdmxUrn[Dataflow],
|
|
140
140
|
*,
|
|
141
141
|
name: InternationalString | dict[str, str],
|
|
@@ -179,7 +179,7 @@ def build_component_availability(
|
|
|
179
179
|
leave the cube non-empty if added to the key.
|
|
180
180
|
|
|
181
181
|
Args:
|
|
182
|
-
registry: An open `LocalRegistry`.
|
|
182
|
+
registry: An open registry: a published `BundleRegistry` or a `LocalRegistry`.
|
|
183
183
|
dataflow_urn: URN of the dataflow to describe.
|
|
184
184
|
name: The constraint's name, in each language it has. Required: SDMX
|
|
185
185
|
requires one, and which language is the caller's to say (#492).
|
|
@@ -280,7 +280,7 @@ def build_component_availability(
|
|
|
280
280
|
)
|
|
281
281
|
|
|
282
282
|
|
|
283
|
-
def _resolve_key_slot_ids(registry:
|
|
283
|
+
def _resolve_key_slot_ids(registry: BundleRegistry, dataflow_urn: SdmxUrn[Dataflow], api: ApiVersion) -> list[str]:
|
|
284
284
|
"""Resolve the DSD's key-dimension ids (SDMX-key order) for the dataflow.
|
|
285
285
|
|
|
286
286
|
Mirrors the dataflow → DSD hop `LocalRegistry.dsd` does for labelling: fetch the
|
|
@@ -65,7 +65,7 @@ Example:
|
|
|
65
65
|
import duckdb
|
|
66
66
|
from attrs import evolve, frozen
|
|
67
67
|
|
|
68
|
-
from sdmxlib.local.registry import
|
|
68
|
+
from sdmxlib.local.registry import BundleRegistry
|
|
69
69
|
from sdmxlib.model.annotations import Annotation, Annotations
|
|
70
70
|
from sdmxlib.model.message import StructureMessage
|
|
71
71
|
from sdmxlib.model.ref import artefact_urn
|
|
@@ -221,7 +221,7 @@ def _accumulate(
|
|
|
221
221
|
|
|
222
222
|
|
|
223
223
|
def _resolve_conn(
|
|
224
|
-
registry:
|
|
224
|
+
registry: BundleRegistry,
|
|
225
225
|
conn: duckdb.DuckDBPyConnection | None,
|
|
226
226
|
) -> duckdb.DuckDBPyConnection:
|
|
227
227
|
"""The explicit ``conn`` or the registry's own DuckDB connection."""
|
|
@@ -241,7 +241,7 @@ def _resolve_conn(
|
|
|
241
241
|
|
|
242
242
|
|
|
243
243
|
def build_dsd_metadata_map(
|
|
244
|
-
registry:
|
|
244
|
+
registry: BundleRegistry,
|
|
245
245
|
*,
|
|
246
246
|
conn: duckdb.DuckDBPyConnection | None = None,
|
|
247
247
|
) -> dict[str, list[DsdMetadataLink]]:
|
|
@@ -316,7 +316,7 @@ ORDER BY mt.target_urn, mt.set_urn
|
|
|
316
316
|
|
|
317
317
|
|
|
318
318
|
def build_metadata_target_links(
|
|
319
|
-
registry:
|
|
319
|
+
registry: BundleRegistry,
|
|
320
320
|
*,
|
|
321
321
|
conn: duckdb.DuckDBPyConnection | None = None,
|
|
322
322
|
) -> dict[str, list[str]]:
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""A bundle as a published artefact: its manifest, and what identifies it.
|
|
2
|
+
|
|
3
|
+
A bundle is a directory holding one directory per publication, named by its
|
|
4
|
+
token, and the ``data/`` every publication shares.
|
|
5
|
+
``LocalRegistry.build(bundle, previous=token)`` starts a publication, minting
|
|
6
|
+
its token; `write_manifest` publishes it: a file inventory with a sha256 per
|
|
7
|
+
file, observation counts per binding, and the ``token``, the value a cache or
|
|
8
|
+
an ETag keys on. ``LocalRegistry.bundle(publication)`` opens it read-only.
|
|
9
|
+
`read_manifest` reads a manifest back, refusing a format it cannot read;
|
|
10
|
+
`check_bundle` checks a publication against it and against itself;
|
|
11
|
+
`copy_bundle` copies one elsewhere, manifest last; `verify_remote` checks the
|
|
12
|
+
files a server reads from blob storage by size and Content-MD5; and `fetch_bundle` lands
|
|
13
|
+
one dataflow from an SDMX REST source as a published bundle, its provenance
|
|
14
|
+
recorded. `apply_overlays` changes display annotations without a rebuild,
|
|
15
|
+
`effective_token` is what a cache keys on when it does, and `fold_overlays`
|
|
16
|
+
writes overlays into a new publication for good. `canonical_json` is the
|
|
17
|
+
defined text of an artefact that a fingerprint hashes. The manifest's JSON Schema
|
|
18
|
+
ships beside it, for producers outside Python: `manifest_schema`.
|
|
19
|
+
|
|
20
|
+
From a shell, ``sdmxlib bundle check``, ``sdmxlib bundle copy`` and
|
|
21
|
+
``sdmxlib bundle fetch`` run these: they are the ``sdmxlib-cli`` package
|
|
22
|
+
(``uv tool install sdmxlib-cli``), released with this one, so the library
|
|
23
|
+
itself never depends on typer.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
from sdmxlib.bundle import Producer, write_manifest
|
|
27
|
+
|
|
28
|
+
with sl.LocalRegistry.build("out/cenprof") as builder:
|
|
29
|
+
builder.add_all(artefacts)
|
|
30
|
+
publication = builder.publication
|
|
31
|
+
manifest = write_manifest(publication, bundle_id="cenprof-2021",
|
|
32
|
+
producer=Producer(name="my-builder", version="1.2"))
|
|
33
|
+
with sl.LocalRegistry.bundle(publication) as reg:
|
|
34
|
+
reg.manifest.token
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
from importlib import resources
|
|
38
|
+
|
|
39
|
+
from sdmxlib.bundle._canonical import CANONICAL_FORM, canonical_json
|
|
40
|
+
from sdmxlib.bundle._check import Check, Profile, Report, check_bundle, check_on_open
|
|
41
|
+
from sdmxlib.bundle._finding import Finding
|
|
42
|
+
from sdmxlib.bundle._copy import copy_bundle
|
|
43
|
+
from sdmxlib.bundle._remote import RemoteFile, content_md5, verify_remote
|
|
44
|
+
from sdmxlib.bundle._fetch import fetch_bundle
|
|
45
|
+
from sdmxlib.bundle._overlay import (
|
|
46
|
+
OVERLAY_FORMAT,
|
|
47
|
+
Merge,
|
|
48
|
+
MergeHook,
|
|
49
|
+
Overlay,
|
|
50
|
+
OverlayAnnotation,
|
|
51
|
+
OverlayEntry,
|
|
52
|
+
OverlayError,
|
|
53
|
+
OverlayText,
|
|
54
|
+
applied,
|
|
55
|
+
apply_overlays,
|
|
56
|
+
effective_token,
|
|
57
|
+
fold_overlays,
|
|
58
|
+
overlay_digest,
|
|
59
|
+
read_overlay,
|
|
60
|
+
)
|
|
61
|
+
from sdmxlib.bundle._write import Lifecycle, inventory, write_manifest
|
|
62
|
+
from sdmxlib.storage._manifest import (
|
|
63
|
+
DATA_PATH,
|
|
64
|
+
DUCKLAKE_SPEC_VERSION,
|
|
65
|
+
FORMAT_VERSION,
|
|
66
|
+
MANIFEST_NAME,
|
|
67
|
+
ArtefactEntry,
|
|
68
|
+
BindingCount,
|
|
69
|
+
BundleFile,
|
|
70
|
+
Manifest,
|
|
71
|
+
ManifestError,
|
|
72
|
+
Producer,
|
|
73
|
+
Provenance,
|
|
74
|
+
SIGNATURE_NAME,
|
|
75
|
+
StoreFormatError,
|
|
76
|
+
Tier,
|
|
77
|
+
read_manifest,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
__all__ = [
|
|
81
|
+
"CANONICAL_FORM",
|
|
82
|
+
"DATA_PATH",
|
|
83
|
+
"DUCKLAKE_SPEC_VERSION",
|
|
84
|
+
"FORMAT_VERSION",
|
|
85
|
+
"MANIFEST_NAME",
|
|
86
|
+
"OVERLAY_FORMAT",
|
|
87
|
+
"SIGNATURE_NAME",
|
|
88
|
+
"ArtefactEntry",
|
|
89
|
+
"BindingCount",
|
|
90
|
+
"BundleFile",
|
|
91
|
+
"Check",
|
|
92
|
+
"Finding",
|
|
93
|
+
"Lifecycle",
|
|
94
|
+
"Manifest",
|
|
95
|
+
"ManifestError",
|
|
96
|
+
"Merge",
|
|
97
|
+
"MergeHook",
|
|
98
|
+
"Overlay",
|
|
99
|
+
"OverlayAnnotation",
|
|
100
|
+
"OverlayEntry",
|
|
101
|
+
"OverlayError",
|
|
102
|
+
"OverlayText",
|
|
103
|
+
"Producer",
|
|
104
|
+
"Profile",
|
|
105
|
+
"Provenance",
|
|
106
|
+
"RemoteFile",
|
|
107
|
+
"Report",
|
|
108
|
+
"StoreFormatError",
|
|
109
|
+
"Tier",
|
|
110
|
+
"applied",
|
|
111
|
+
"apply_overlays",
|
|
112
|
+
"canonical_json",
|
|
113
|
+
"check_bundle",
|
|
114
|
+
"check_on_open",
|
|
115
|
+
"content_md5",
|
|
116
|
+
"copy_bundle",
|
|
117
|
+
"effective_token",
|
|
118
|
+
"fetch_bundle",
|
|
119
|
+
"fold_overlays",
|
|
120
|
+
"inventory",
|
|
121
|
+
"manifest_schema",
|
|
122
|
+
"overlay_digest",
|
|
123
|
+
"overlay_schema",
|
|
124
|
+
"read_manifest",
|
|
125
|
+
"read_overlay",
|
|
126
|
+
"verify_remote",
|
|
127
|
+
"write_manifest",
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def overlay_schema() -> bytes:
|
|
132
|
+
"""The JSON Schema for an overlay document, as shipped (`overlay.schema.json`)."""
|
|
133
|
+
return resources.files(__package__).joinpath("overlay.schema.json").read_bytes()
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def manifest_schema() -> bytes:
|
|
137
|
+
"""The JSON Schema for ``bundle.manifest.json``, as shipped (`manifest.schema.json`)."""
|
|
138
|
+
return resources.files(__package__).joinpath("manifest.schema.json").read_bytes()
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""The canonical text of a model object, which an artefact fingerprint hashes (GH-126).
|
|
2
|
+
|
|
3
|
+
Two artefacts with equal content give byte-equal text; any change to a field
|
|
4
|
+
the model holds changes it. That needs a form defined field by field rather
|
|
5
|
+
than borrowed from a wire format: SDMX-JSON cannot carry 28 of the model's
|
|
6
|
+
fields and writes the minimal spelling, and msgspec cannot encode the attrs
|
|
7
|
+
model at all.
|
|
8
|
+
|
|
9
|
+
The form, `CANONICAL_FORM` ``"1"``: compact JSON in UTF-8, with every
|
|
10
|
+
object's keys sorted, built as follows.
|
|
11
|
+
|
|
12
|
+
- An attrs object is an object holding ``"$class"``, its Python class name,
|
|
13
|
+
and every field set through ``__init__``, ``null`` included. Fields the
|
|
14
|
+
class derives itself (``init=False``) are left out.
|
|
15
|
+
- ``maintainer`` is the agency's id: it refers to an Agency item, whose own
|
|
16
|
+
content belongs to its scheme's text.
|
|
17
|
+
- A `Ref` is its URN, never followed.
|
|
18
|
+
- An `InternationalString` is an object of language tag to text.
|
|
19
|
+
- A list, tuple, `ItemList` or `Annotations` is an array in its order; a set
|
|
20
|
+
or frozenset is an array sorted by each element's canonical text.
|
|
21
|
+
- An enum is its member's name; a ``datetime`` is UTC, ``YYYY-MM-DDTHH:MM:SS.ffffffZ``;
|
|
22
|
+
a ``date`` is ``YYYY-MM-DD``.
|
|
23
|
+
- A float is msgspec's shortest round-trip form, and a non-finite one is
|
|
24
|
+
refused: JSON has no spelling for it.
|
|
25
|
+
|
|
26
|
+
Any other value is refused naming its type and field, so a new kind of field
|
|
27
|
+
fails here rather than encoding as something ambiguous. A change to any rule
|
|
28
|
+
above is a new `CANONICAL_FORM`; fingerprints made at different forms are
|
|
29
|
+
never compared.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
import enum
|
|
33
|
+
import math
|
|
34
|
+
from collections.abc import Mapping
|
|
35
|
+
from datetime import UTC, date, datetime
|
|
36
|
+
from typing import TypeIs
|
|
37
|
+
|
|
38
|
+
import attrs
|
|
39
|
+
import msgspec
|
|
40
|
+
|
|
41
|
+
from sdmxlib.model.annotations import Annotations
|
|
42
|
+
from sdmxlib.model.collections import ItemList
|
|
43
|
+
from sdmxlib.model.istring import InternationalString
|
|
44
|
+
from sdmxlib.model.organisation import Agency
|
|
45
|
+
from sdmxlib.model.ref import Ref
|
|
46
|
+
|
|
47
|
+
#: The version of the rules above. Recorded beside every fingerprint made from them.
|
|
48
|
+
CANONICAL_FORM = "1"
|
|
49
|
+
|
|
50
|
+
_ENCODER = msgspec.json.Encoder(order="sorted")
|
|
51
|
+
|
|
52
|
+
#: A canonical value, as msgspec encodes it.
|
|
53
|
+
type _Plain = bool | int | float | str | list[_Plain] | dict[str, _Plain] | None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def canonical_json(obj: object) -> bytes:
|
|
57
|
+
"""The canonical text of a model object: an artefact, an item, a component.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
obj: An attrs instance from `sdmxlib.model`. A store-backed
|
|
61
|
+
`LazyCodelist` is not one and is refused; read the codelist with
|
|
62
|
+
``eager=True``.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
Compact, key-sorted UTF-8 JSON, as the module docstring defines it.
|
|
66
|
+
|
|
67
|
+
Raises:
|
|
68
|
+
TypeError: If a field holds a value the form does not define.
|
|
69
|
+
ValueError: If a field holds a non-finite float or a naive datetime.
|
|
70
|
+
"""
|
|
71
|
+
return _ENCODER.encode(_plain(obj, type(obj).__name__))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _plain(value: object, path: str) -> _Plain:
|
|
75
|
+
"""`value` as plain JSON values; `path` names it in an error."""
|
|
76
|
+
match value:
|
|
77
|
+
# Before the attrs case: `Ref` is an attrs class, and its fields hold
|
|
78
|
+
# the resolved target, which the form never follows.
|
|
79
|
+
case Ref():
|
|
80
|
+
return str(value.urn)
|
|
81
|
+
case InternationalString():
|
|
82
|
+
return {lang: value[lang] for lang in value}
|
|
83
|
+
case Annotations() | ItemList() | list() | tuple():
|
|
84
|
+
return [_plain(item, f"{path}[{i}]") for i, item in enumerate(value)]
|
|
85
|
+
case set() | frozenset():
|
|
86
|
+
return sorted((_plain(item, f"{path}{{}}") for item in value), key=_ENCODER.encode)
|
|
87
|
+
case Mapping():
|
|
88
|
+
return _mapping(value, path)
|
|
89
|
+
case _ if _is_attrs_instance(value):
|
|
90
|
+
return _object(value, path)
|
|
91
|
+
case _:
|
|
92
|
+
return _scalar(value, path)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _scalar(value: object, path: str) -> _Plain:
|
|
96
|
+
"""A value that is not a container: a JSON scalar, or a model value with one spelling."""
|
|
97
|
+
match value:
|
|
98
|
+
# Before `str()`: a `StrEnum` member is a `str`, and is spelled by name too.
|
|
99
|
+
case enum.Enum():
|
|
100
|
+
return value.name
|
|
101
|
+
case None | bool() | int() | str():
|
|
102
|
+
return value
|
|
103
|
+
case float():
|
|
104
|
+
if not math.isfinite(value):
|
|
105
|
+
msg = f"{path} is {value}, which canonical JSON cannot spell"
|
|
106
|
+
raise ValueError(msg)
|
|
107
|
+
return value
|
|
108
|
+
case datetime():
|
|
109
|
+
if value.tzinfo is None:
|
|
110
|
+
msg = f"{path} is a naive datetime; the model holds every datetime in UTC"
|
|
111
|
+
raise ValueError(msg)
|
|
112
|
+
return value.astimezone(UTC).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
|
113
|
+
case date():
|
|
114
|
+
return value.isoformat()
|
|
115
|
+
case _:
|
|
116
|
+
msg = f"{path} holds a {type(value).__name__}, which the canonical form does not define"
|
|
117
|
+
raise TypeError(msg)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _is_attrs_instance(value: object) -> TypeIs[attrs.AttrsInstance]:
|
|
121
|
+
"""An attrs instance, narrowed on the value (``attrs.has`` takes a class)."""
|
|
122
|
+
return not isinstance(value, type) and attrs.has(type(value))
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _mapping(value: Mapping[object, object], path: str) -> dict[str, _Plain]:
|
|
126
|
+
plain: dict[str, _Plain] = {}
|
|
127
|
+
for key, item in value.items():
|
|
128
|
+
if not isinstance(key, str):
|
|
129
|
+
msg = f"{path} has a {type(key).__name__} key; canonical JSON keys are strings"
|
|
130
|
+
raise TypeError(msg)
|
|
131
|
+
plain[key] = _plain(item, f"{path}[{key!r}]")
|
|
132
|
+
return plain
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _object(value: attrs.AttrsInstance, path: str) -> dict[str, _Plain]:
|
|
136
|
+
cls = type(value)
|
|
137
|
+
plain: dict[str, _Plain] = {"$class": cls.__name__}
|
|
138
|
+
for field in attrs.fields(cls):
|
|
139
|
+
if not field.init:
|
|
140
|
+
continue
|
|
141
|
+
item: object = getattr(value, field.name)
|
|
142
|
+
if field.name == "maintainer" and isinstance(item, Agency):
|
|
143
|
+
plain[field.name] = item.id
|
|
144
|
+
else:
|
|
145
|
+
plain[field.name] = _plain(item, f"{path}.{field.name}")
|
|
146
|
+
return plain
|