SDMX-REST Service Clients
Note
Additional information about how to execute SDMX-REST queries against a specific service can be found in the following tutorial:
Build SDMX-REST queries.
- class pysdmx.api.qb.ApiVersion(*values)
The version of the SDMX-REST API.
- property label: str
The release number as defined by the SDMX-REST specification.
- class pysdmx.api.qb.AsyncLenientRestService(api_endpoint, api_version, data_format=DataFormat.SDMX_JSON_2_0_0, structure_format=StructureFormat.SDMX_JSON_2_0_0, schema_format=SchemaFormat.SDMX_JSON_2_0_0_STRUCTURE, refmeta_format=RefMetaFormat.SDMX_JSON_2_0_0, avail_format=AvailabilityFormat.SDMX_JSON_2_0_0, registry_format=RegistryFormat.FUSION_JSON, pem=None, timeout=5.0, extraction_timeout=600.0)
A lenient asynchronous connector to SDMX-REST services.
It is instantiated and used as the
AsyncRestService, which is strict, but, as theLenientRestService, it also decompresses a response body compressed with gzip but sent without aContent-Encodingheader, anddata()andstream_data()follow the asynchronous extractions in which Eurostat’s SDMX API queues large data queries.Besides the arguments of the
AsyncRestService, it takes the following one.- Parameters:
extraction_timeout (
Optional[float]) – The maximum number of seconds to wait, since the query, for an asynchronous extraction to be available, orNoneto wait without limit. Defaults to 600 seconds.
- async data(query)
Execute a data query against the service.
An asynchronous extraction is followed, and a long wait warned about, as by
stream_data().- Return type:
bytes
- async stream_data(query, chunk_size=8192)
Execute a data query against the service.
If the service queues the query as an asynchronous extraction, as Eurostat’s SDMX API does with large data queries, the status of the extraction is checked every 10 seconds, until it is available or
extraction_timeoutseconds have passed since the query, and the data of the extraction are streamed.If the service has not started to send the data after 60 seconds, a
UserWarningis emitted, and another one every 10 seconds while it keeps waiting.- Return type:
AsyncGenerator[bytes,None]
- class pysdmx.api.qb.AsyncRestService(api_endpoint, api_version, data_format=DataFormat.SDMX_JSON_2_0_0, structure_format=StructureFormat.SDMX_JSON_2_0_0, schema_format=SchemaFormat.SDMX_JSON_2_0_0_STRUCTURE, refmeta_format=RefMetaFormat.SDMX_JSON_2_0_0, avail_format=AvailabilityFormat.SDMX_JSON_2_0_0, registry_format=RegistryFormat.FUSION_JSON, pem=None, timeout=5.0, token=None)
Asynchronous connector to SDMX-REST services.
The service is expected to be protocol-correct: a response is only decoded as declared by its
Content-Encodingheader. Services that are not can be queried using theAsyncLenientRestService.- Parameters:
api_endpoint (
str) – The entry point (URL) of the SDMX-REST service.api_version (
ApiVersion) – The most recent version of the SDMX-REST specification supported by the service.data_format (
DataFormat) – The default format for data queries.structure_format (
StructureFormat) – The default format for structure queries.schema_format (
SchemaFormat) – The default format for schema queries.refmeta_format (
RefMetaFormat) – The default format for reference metadata queries.avail_format (
AvailabilityFormat) – The default format for availability queries.registry_format (
RegistryFormat) – The default format for registration queries.pem (
Optional[str]) – In case the service uses SSL/TLS with self-signed certificate, this attribute should be used to pass the pem file with the list of trusted certicate authorities.timeout (
Optional[float]) – The maximum number of seconds to wait before considering that a request timed out. Defaults to 5 seconds.token (
Optional[str]) – An optional bearer token to be sent as anAuthorizationheader on every request, for services requiring authentication.
- async availability(query)
Execute an availability query against the service.
- Return type:
bytes
- async data(query)
Execute a data query against the service.
- Return type:
bytes
- async reference_metadata(query)
Execute a reference metadata query against the service.
- Return type:
bytes
- async registration(query)
Execute a registration query against the service.
- Return type:
bytes
- async schema(query)
Execute a schema query against the service.
- Return type:
bytes
- async stream_data(query, chunk_size=8192)
Execute a data query against the service.
- Return type:
AsyncGenerator[bytes,None]
- async structure(query)
Execute a structure query against the service.
- Return type:
bytes
- class pysdmx.api.qb.LenientRestService(api_endpoint, api_version, data_format=DataFormat.SDMX_JSON_2_0_0, structure_format=StructureFormat.SDMX_JSON_2_0_0, schema_format=SchemaFormat.SDMX_JSON_2_0_0_STRUCTURE, refmeta_format=RefMetaFormat.SDMX_JSON_2_0_0, avail_format=AvailabilityFormat.SDMX_JSON_2_0_0, registry_format=RegistryFormat.FUSION_JSON, pem=None, timeout=5.0, extraction_timeout=600.0)
A lenient synchronous connector to SDMX-REST services.
It is instantiated and used as the
RestService, which is strict: it expects the service to be protocol-correct. This connector also accepts the following deviations:A response body compressed with gzip, but sent without a
Content-Encodingheader (e.g. by Eurostat’s SDMX API), is decompressed if its first bytes are those of a gzip stream.A data query that Eurostat’s SDMX API queues as an asynchronous extraction, answering with the id of the extraction instead of the data, is followed:
data(),stream_data()andstream_message()return the data of the extraction once it is available.An error that Eurostat’s SDMX API describes in a SOAP fault, instead of an SDMX-ML error message, is raised by
stream_message()as any other error, with the fault in its message.
Besides the arguments of the
RestService, it takes the following one.- Parameters:
extraction_timeout (
Optional[float]) – The maximum number of seconds to wait, since the query, for an asynchronous extraction to be available, orNoneto wait without limit. Defaults to 600 seconds.
- data(query)
Execute a data query against the service.
An asynchronous extraction is followed, and a long wait warned about, as by
stream_data().- Return type:
bytes
- stream_data(query, chunk_size=8192)
Execute a data query against the service.
If the service queues the query as an asynchronous extraction, as Eurostat’s SDMX API does with large data queries, the status of the extraction is checked every 10 seconds, until it is available or
extraction_timeoutseconds have passed since the query, and the data of the extraction are streamed.If the service has not started to send the data after 60 seconds, a
UserWarningis emitted, and another one every 10 seconds while it keeps waiting.- Return type:
Generator[bytes,None,None]
- stream_message(url)
Streams the text of the SDMX message found at a URL.
The URL is requested as it is, whatever the endpoint of the service is. If the service answers with an error status and an XML body, as an SDMX-ML error message, the body is streamed as the message, so that the error it describes can be read. A SOAP fault, in which Eurostat’s SDMX API describes its errors instead, is raised as any other error.
If the service queues the query as an asynchronous extraction, as Eurostat’s SDMX API does with large data queries, the status of the extraction is checked every 10 seconds, until it is available or
extraction_timeoutseconds have passed since the request, and the data of the extraction are streamed as the message.If the service has not started to send the message after 60 seconds, a
UserWarningis emitted, and another one every 10 seconds while it keeps waiting.- Parameters:
url (
str) – The URL of the message.- Yields:
The chunks of the text of the message, decoded with the charset declared by the service (UTF-8 by default).
- Raises:
NotFound – If the message is not found.
Invalid – If the service answers with another client error.
InternalError – If the service answers with a server error, or does not tell the status of an extraction.
Unavailable – If the service cannot be reached, the response cannot be decoded, or an extraction fails or is not available in time.
NotImplemented – If the service queues the query as an extraction that cannot be followed, outside Eurostat’s SDMX APIs.
- class pysdmx.api.qb.RestService(api_endpoint, api_version, data_format=DataFormat.SDMX_JSON_2_0_0, structure_format=StructureFormat.SDMX_JSON_2_0_0, schema_format=SchemaFormat.SDMX_JSON_2_0_0_STRUCTURE, refmeta_format=RefMetaFormat.SDMX_JSON_2_0_0, avail_format=AvailabilityFormat.SDMX_JSON_2_0_0, registry_format=RegistryFormat.FUSION_JSON, pem=None, timeout=5.0, token=None)
Synchronous connector to SDMX-REST services.
The service is expected to be protocol-correct: a response is only decoded as declared by its
Content-Encodingheader. Services that are not can be queried using theLenientRestService.- Parameters:
api_endpoint (
str) – The entry point (URL) of the SDMX-REST service.api_version (
ApiVersion) – The most recent version of the SDMX-REST specification supported by the service.data_format (
DataFormat) – The default format for data queries.structure_format (
StructureFormat) – The default format for structure queries.schema_format (
SchemaFormat) – The default format for schema queries.refmeta_format (
RefMetaFormat) – The default format for reference metadata queries.avail_format (
AvailabilityFormat) – The default format for availability queries.registry_format (
RegistryFormat) – The default format for registration queries.pem (
Optional[str]) – In case the service uses SSL/TLS with self-signed certificate, this attribute should be used to pass the pem file with the list of trusted certicate authorities.timeout (
Optional[float]) – The maximum number of seconds to wait before considering that a request timed out. Defaults to 5 seconds.token (
Optional[str]) – An optional bearer token to be sent as anAuthorizationheader on every request, for services requiring authentication.
- availability(query)
Execute an availability query against the service.
- Return type:
bytes
- data(query)
Execute a data query against the service.
- Return type:
bytes
- reference_metadata(query)
Execute a reference metadata query against the service.
- Return type:
bytes
- registration(query)
Execute a registration query against the service.
- Return type:
bytes
- schema(query)
Execute a schema query against the service.
- Return type:
bytes
- stream_data(query, chunk_size=8192)
Execute a data query against the service.
- Return type:
Generator[bytes,None,None]
- structure(query)
Execute a structure query against the service.
- Return type:
bytes