Skip to main content

SDMX structural metadata library for Python

Project description

sdmxlib

Note: This library has been written extensively with AI assistance (Claude Code). Users who are not comfortable with AI-generated code should take that into account before adopting it.

SDMX structural metadata library for Python. Fetch and navigate Data Structure Definitions, Codelists, Dataflows, and related artefacts from any SDMX REST endpoint — with plain attribute access, no XML or URN chasing required.

Quick start

import sdmxlib as sl

with sl.RestRegistry(sl.Provider.BIS) as reg:
    dsd = reg.get(sl.DataStructure, agency="BIS", id="WS_CBPOL").resolve()

    for dim in dsd.dimensions:
        if dim.is_enumerated:
            cl = dim.representation()
            print(f"{dim.id}: {cl.id} ({len(cl.codes)} codes)")
FREQ: CL_FREQ (7 codes)
REF_AREA: CL_BIS_IF_REF_AREA (44 codes)
INSTR_ASSET: CL_INSTR_ASSET (12 codes)
BORROWER_CTY: CL_BIS_IF_REF_AREA (44 codes)

Installation

uv add sdmxlib
# or: pip install sdmxlib

What it does

  • Connects to any SDMX 2.1 or 3.0 REST endpoint; built-in shortcuts for ECB, BIS, ESTAT, IMF, OECD, and the SDMX Global Registry via sl.Provider
  • Three resolution modes: browse() for catalogue scanning, fetch() for unresolved artefacts, resolve() for the full reference graph (with optional constraint-trimming via partial=True/False)
  • Returns fully resolved domain objects with plain attribute access — no XML, no URN chasing
  • Filter collections with lambdas or the item() expression API
  • Build SDMX artefacts locally and serialise to SDMX-ML or SDMX-JSON
  • Registry -- a DuckDB-backed persistent store for offline access with lazy codelist + hierarchy loading, automatic Ref resolution, and direct SQL code maps; supports shared connections and any-language queries
  • Uniform SKOS-aligned tree API (roots/leaves/narrower/broader/ *_transitive/depth_of plus bulk projections depths/broader_map/ ancestors_map/inherit_along_broader) on Codelist, Hierarchy, CategoryScheme, MetadataStructure — and their lazy SQL variants LazyCodelist/LazyHierarchy
  • Reference metadata via MetadataStructure (MSD), Metadataflow, and MetadataSet — attach typed footnotes, methodology notes, or quality reports to any identifiable artefact. Definitions ride in StructureMessage; populated payloads ride in MetadataMessage (<mes:GenericMetadata> in SDMX-ML 3.0; metadata-schema envelope in SDMX-JSON 2.0). Both message kinds round-trip through Registry, JSON, and XML.
  • Integrates with Polars for schema generation and data validation
  • Fully typed — IDE completion and static analysis work throughout

For AI assistants

Two condensed reference files at the repo root are written for LLM tools (Claude Code, Cursor, Copilot, etc.):

  • llms.txt — full library overview: install, registries, data fetching, reference metadata, and the domain-type cheat sheet
  • llms-dsl.txt — focused query-DSL reference: sl.item / sl.code / sl.node / sl.dim predicates, Query / DataQuery / CodeQuery / HierarchyNodeQuery chains, and the uniform SKOS tree API

Point your assistant at these to keep generated code aligned with the library's actual surface.

Documentation

See the docs for the full cookbook, including:

  • Connecting to registries and choosing a resolution mode
  • Persisting artefacts in a local DuckDB store with Registry
  • Fetching observation data with sl.dim() filters and pivoting to wide format
  • Inspecting DSDs and building code maps for ETL pipelines
  • Generating Polars schemas from SDMX Data Structure Definitions
  • Browsing data catalogs and filtering dataflows
  • Working with constraints, hierarchies, and serialisation

Development

just check           # lint + typecheck
just test            # unit tests
just test-integration  # live endpoint tests (requires network)
just ci              # full pre-commit gate

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sdmxlib-0.40.0.tar.gz (262.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sdmxlib-0.40.0-py3-none-any.whl (313.0 kB view details)

Uploaded Python 3

File details

Details for the file sdmxlib-0.40.0.tar.gz.

File metadata

  • Download URL: sdmxlib-0.40.0.tar.gz
  • Upload date:
  • Size: 262.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sdmxlib-0.40.0.tar.gz
Algorithm Hash digest
SHA256 39d33c8f3fa215d529649a4e28256ddfa0c9377371f3469a7d7a3d1d3676cb59
MD5 3aec869ebbc0c392158b79b7f2897bc8
BLAKE2b-256 f9e58c226a81c753bee863193ccb03b136e569be32feeb7aede954d1a5e0d771

See more details on using hashes here.

File details

Details for the file sdmxlib-0.40.0-py3-none-any.whl.

File metadata

  • Download URL: sdmxlib-0.40.0-py3-none-any.whl
  • Upload date:
  • Size: 313.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sdmxlib-0.40.0-py3-none-any.whl
Algorithm Hash digest
SHA256 574e6806b5f6a8f69d2caaf72c49d44390f9900877f067bf7c19521e9138060b
MD5 8d4bef6c0a891383944e584b4e28a0e3
BLAKE2b-256 740036d2c8f5d447b525f7c2c8e48c304b413807a2a54a3eecc1f3edc39af81a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page