Install & Compatibility
Where this runs
tested against v2.26.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 1.632s · 185.6MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 9.1s · import 1.532s · 178MB
185MB installed
● package 185MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Request
✓ import sdmx
req = sdmx.Request('ESTAT')
✗ from sdmx import Client
The `sdmx.Client` class was removed in version 2.0.0 and replaced by `sdmx.Request` for clearer API interaction.
read_sdmx
✓ import sdmx
with open('data.xml', 'rb') as f:
msg = sdmx.read_sdmx(f)
Commonly used for parsing SDMX-ML or SDMX-JSON files from local storage.
Demonstrates how to connect to an SDMX agency (e.g., IMF) using `sdmx.Request`, list available dataflows, and print basic information. It includes error handling for common API issues. The example for fetching specific data is commented out as it requires specific knowledge of an agency's data structure.
import sdmx
import os
# Example agency ID; replace with a real one like 'ESTAT' (Eurostat), 'IMF', 'OECD'
# Some agencies may require specific authentication or have strict rate limits.
agency_id = os.environ.get('SDMX_AGENCY_ID', 'IMF') # Using IMF as a common example
try:
# Create a Request object for the specified agency
req = sdmx.Request(agency_id)
print(f"Attempting to connect to SDMX agency: {agency_id}")
# Fetch available dataflows
# This performs an HTTP GET request to the agency's API endpoint
dataflows = req.dataflow()
print(f"Successfully retrieved dataflows from {agency_id}.")
print(f"First 3 dataflows from {agency_id} (ID: Name):")
if dataflows.data.dataflow:
for i, flow in enumerate(dataflows.data.dataflow[:3]):
print(f" - {flow.id}: {flow.name.get('en', 'No English name')}")
else:
print(" No dataflows found.")
# To fetch actual data, you would then use a specific dataflow ID and keys.
# Example (commented out, as specific dataflow IDs and keys vary greatly):
# # For IMF, using International Financial Statistics (IFS) dataflow, if available
# if agency_id == 'IMF':
# print("\nAttempting to fetch data from IMF (example).")
# data = req.get_data(
# resource_id='IFS',
# key={'REF_AREA': ['US', 'CN'], 'INDICATOR': ['LP_CPI_IX']},
# params={'startPeriod': '2020', 'endPeriod': '2022'}
# )
# print(f"Fetched {len(data.series)} series from IFS.")
except sdmx.api.APIError as e:
print(f"Error connecting to or fetching data from {agency_id}: {e}")
print("Possible causes: invalid agency ID, network issues, API rate limits, or specific API endpoint errors.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Errors
Common errors & fixes
AttributeError: module 'sdmx' has no attribute 'Client'
You are attempting to use the `sdmx.Client` class, which was removed in `sdmx1` version 2.0.0.
fixUpdate your code to use `sdmx.Request()` instead of `sdmx.Client()`. For example, `req = sdmx.Request('ESTAT')`. sdmx.api.APIError: 404 Client Error: Not Found for url: ...
The SDMX agency or resource ID specified in your request does not exist, or the URL constructed by the library leads to a non-existent endpoint. This often happens with incorrect agency IDs or resource IDs.
fixDouble-check the `agency_id` and `resource_id` (e.g., dataflow ID) you are passing to `sdmx.Request()` and `req.get_data()`. Verify them against the official SDMX documentation or the agency's portal.
sdmx.api.APIError: 400 Client Error: Bad Request for url: ...
The parameters sent in your data request are invalid, incomplete, or not understood by the SDMX API. Common issues include incorrect dimension keys, missing required parameters like `startPeriod`/`endPeriod`, or invalid date formats.
fixReview the `key` and `params` arguments passed to `req.get_data()`. Ensure all required dimensions are specified and their values are valid according to the agency's data structure definitions. Consult the agency's SDMX API documentation.
Upgrade
Version history
2.26.0latest on PyPI · released Apr 4, 2026
Audit
Dependencies
requests-cacheoptionalFor persistent caching of HTTP requests to improve performance and reduce API calls.