Read SDMX file formats#
SDMX-ML#
sdmx.reader.xml
supports the several types of SDMX-ML messages.
Implementation details:
The collections of
StructureMessage
(e.g.StructureMessage.codelist
) are implemented bysdmx
asDictLike
, withstr
keys, for convenience; the standard would imply these could be other collections, such as a simplelist
. The format of the keys in each collection depends on the content of the message parsed byreader.xml
:Simply
{object.id}
(IdentifiableArtefact.id
) of the contained objects, if these are unique;Otherwise
{maintainer.id}:{object.id}
(using theAgency
id) if these are unique;Otherwise
{maintainer.id}:{object.id}({object.version})
(using theVersionableArtefact.version
).
This ensures that all objects in a parsed message are accessible.
SDMX-ML v2.1 reader.
- class sdmx.reader.xml.v21.Reader[source]#
SDMX-ML 2.1 reader.
- format: ClassVar['types.ModuleType'] = <module 'sdmx.format.xml.v21' from '/home/docs/checkouts/readthedocs.org/user_builds/sdmx1/envs/latest/lib/python3.12/site-packages/sdmx/format/xml/v21.py'>[source]#
Reference to the module defining the format read.
- media_types: ClassVar[List[MediaType]] = [application/vnd.sdmx.generic+xml; version=2.1, application/vnd.sdmx.genericdata+xml; version=2.1, application/vnd.sdmx.genericmetadata+xml; version=2.1, application/vnd.sdmx.generictimeseriesdata+xml; version=2.1, application/vnd.sdmx.schema+xml; version=2.1, application/vnd.sdmx.structure+xml; version=2.1, application/vnd.sdmx.structurespecificdata+xml; version=2.1, application/vnd.sdmx.structurespecificmetadata+xml; version=2.1, application/vnd.sdmx.structurespecifictimeseriesdata+xml; version=2.1, application/xml; version=2.1, text/xml; version=2.1][source]#
List of media types handled by the reader.
- sdmx.reader.xml.v21.add_mds_events(reader: Reader, mds: MetadataStructureDefinition)[source]#
Add parser events for structure-specific metadata.
SDMX-ML 3.0.0 reader.
- class sdmx.reader.xml.v30.Reader[source]#
SDMX-ML 3.0 reader.
- format: ClassVar['types.ModuleType'] = <module 'sdmx.format.xml.v30' from '/home/docs/checkouts/readthedocs.org/user_builds/sdmx1/envs/latest/lib/python3.12/site-packages/sdmx/format/xml/v30.py'>[source]#
Reference to the module defining the format read.
- media_types: ClassVar[List[MediaType]] = [application/vnd.sdmx.data+xml; version=3.0.0, application/vnd.sdmx.structure+xml; version=3.0.0][source]#
List of media types handled by the reader.
SDMX-JSON#
SDMX-JSON v2.1 reader
- class sdmx.reader.json.Reader[source]#
Read SDMX-JSON and expose it as instances from
sdmx.model
.- media_types: ClassVar[List[MediaType]] = [application/vnd.sdmx.data+json; version=1.0.0, application/vnd.sdmx.structure+json; version=1.0.0, application/vnd.sdmx.draft-sdmx-json+json; version=1.0.0, draft-sdmx-json; version=1.0.0, text/json; version=1.0.0][source]#
List of media types handled by the reader.
- read_message(source, structure=None, **kwargs)[source]#
Read message from source.
- Parameters:
source (
file-like
) – Message content.structure –
DataStructure
orMetadataStructure
for aid in reading source.
- Returns:
An instance of a Message subclass.
- Return type:
SDMX-CSV#
Reader API#
- sdmx.reader.READERS = [<class 'sdmx.reader.json.Reader'>, <class 'sdmx.reader.xml.Reader'>][source]#
Reader classes
- sdmx.reader.detect_content_reader(content)[source]#
Return a reader class for content.
The
BaseReader.detect()
method for each class inREADERS
is called; if a reader signals that it is compatible with content, then that class is returned.- Raises:
ValueError – If no reader class matches.
- sdmx.reader.get_reader_for_media_type(value)[source]#
Return a reader class for HTTP content/media type value.
- Raises:
ValueError – If no reader class matches.
See also
BaseReader.media_type
- sdmx.reader.get_reader_for_path(path)[source]#
Return a reader class for file path.
- Raises:
ValueError – If no reader class matches.
See also
BaseReader.suffixes
- sdmx.reader.read_sdmx(filename_or_obj, format=None, **kwargs)[source]#
Load a SDMX-ML or SDMX-JSON message from a file or file-like object.
- Parameters:
format (
'XML'
or'JSON'
, optional)dsd (
DataStructureDefinition
) – For “structure-specific” format`=``XML` messages only.
- class sdmx.reader.base.BaseReader[source]#
-
- classmethod handles_media_type(value: str) bool [source]#
True
if the reader can handle content/media type value.
- abstract read_message(source, structure: sdmx.model.common.Structure | None = None, **kwargs)[source]#
Read message from source.
- Parameters:
source (
file-like
) – Message content.structure –
DataStructure
orMetadataStructure
for aid in reading source.
- Returns:
An instance of a Message subclass.
- Return type: