SDMX-ML
SDMX-ML is the most used format to exchange statistical data and metadata. On pysdmx, we support the validation against XSD schemas.
Important
To use the SDMX-ML functionalities, you need to install the pysdmx[xml] extra.
Check the installation guide for more information.
Reading
Although the use of the general reader is always recommended, specific readers for SDMX-ML are also available:
DATA_SDMX_ML_2_1_GEN -> pysdmx.io.xml.sdmx21.reader.generic
- pysdmx.io.xml.sdmx21.reader.generic.read(input_str, validate=True)
Reads an SDMX-ML 2.1 Generic data and returns a Sequence of Datasets.
- Parameters:
input_str (
str
) – SDMX-ML data to read.validate (
bool
) – If True, the XML data will be validated against the XSD.
- Return type:
Sequence
[PandasDataset
]
DATA_SDMX_ML_2_1_STR -> pysdmx.io.xml.sdmx21.reader.structure_specific
- pysdmx.io.xml.sdmx21.reader.structure_specific.read(input_str, validate=True)
Reads an SDMX-ML 2.1 and returns a Sequence of Datasets.
- Parameters:
input_str (
str
) – SDMX-ML data to read.validate (
bool
) – If True, the XML data will be validated against the XSD.
- Return type:
Sequence
[PandasDataset
]
STRUCTURE_SDMX_ML_2_1 -> pysdmx.io.xml.sdmx21.reader.structure
- pysdmx.io.xml.sdmx21.reader.structure.read(input_str, validate=True)
Reads an SDMX-ML 2.1 Structure data and returns the structures.
- Parameters:
input_str (
str
) – SDMX-ML structure message to read.validate (
bool
) – If True, the XML data will be validated against the XSD.
- Returns:
Dictionary with the parsed structures.
- Return type:
dict
DATA_SDMX_ML_3_0 -> pysdmx.io.xml.sdmx30.reader.structure_specific
- pysdmx.io.xml.sdmx30.reader.structure_specific.read(input_str, validate=True)
Reads an SDMX-ML 3.0 and returns a Sequence of Datasets.
- Parameters:
input_str (
str
) – SDMX-ML data to read.validate (
bool
) – If True, the XML data will be validated against the XSD.
- Return type:
Sequence
[PandasDataset
]
STRUCTURE_SDMX_ML_3_0 -> pysdmx.io.xml.sdmx30.reader.structure
- pysdmx.io.xml.sdmx30.reader.structure.read(input_str, validate=True)
Reads an SDMX-ML 3.0 Structure data and returns the structures.
- Parameters:
input_str (
str
) – SDMX-ML structure message to read.validate (
bool
) – If True, the XML data will be validated against the XSD.
- Returns:
Dictionary with the parsed structures.
- Return type:
dict
After reading the string, we will have a message object that contains a pandas DataFrame with the data or a structure object with the metadata.
Writing
Although the use of the general writer is always recommended, specific readers for SDMX-ML are also available:
DATA_SDMX_ML_2_1_GEN -> pysdmx.io.xml.sdmx21.writer.generic
- pysdmx.io.xml.sdmx21.writer.generic.write(datasets, output_path=None, prettyprint=True, header=None, dimension_at_observation=None)
Write data to SDMX-ML 2.1 Generic format.
- Parameters:
datasets (
Sequence
[PandasDataset
]) – The datasets to be written.output_path (
Union
[str
,Path
,None
]) – The path to save the file.prettyprint (
bool
) – Prettyprint or not.header (
Optional
[Header
]) – The header to be used (generated if None).dimension_at_observation (
Optional
[Dict
[str
,str
]]) – The mapping between the dataset and the dimension at observation.
- Return type:
Optional
[str
]- Returns:
The XML string if path is empty, None otherwise.
DATA_SDMX_ML_2_1_STR -> pysdmx.io.xml.sdmx21.writer.structure_specific
- pysdmx.io.xml.sdmx21.writer.structure_specific.write(datasets, output_path=None, prettyprint=True, header=None, dimension_at_observation=None)
Write data to SDMX-ML 2.1 Structure Specific format.
- Parameters:
datasets (
Sequence
[PandasDataset
]) – The datasets to be written.output_path (
Union
[str
,Path
,None
]) – The path to save the file.prettyprint (
bool
) – Prettyprint or not.header (
Optional
[Header
]) – The header to be used (generated if None).dimension_at_observation (
Optional
[Dict
[str
,str
]]) – The mapping between the dataset and the dimension at observation.
- Return type:
Optional
[str
]- Returns:
The XML string if path is empty, None otherwise.
STRUCTURE_SDMX_ML_2_1 -> pysdmx.io.xml.sdmx21.writer.structure
- pysdmx.io.xml.sdmx21.writer.structure.write(structures, output_path=None, prettyprint=True, header=None)
This function writes a SDMX-ML file from the Message Content.
- Parameters:
structures (
Sequence
[MaintainableArtefact
]) – The content to be writtenoutput_path (
Union
[str
,Path
,None
]) – The path to save the fileprettyprint (
bool
) – Prettyprint or notheader (
Optional
[Header
]) – The header to be used (generated if None)
- Return type:
Optional
[str
]- Returns:
The XML string if output_path is empty, None otherwise
DATA_SDMX_ML_3_0 -> pysdmx.io.xml.sdmx30.writer.structure_specific
- pysdmx.io.xml.sdmx30.writer.structure_specific.write(datasets, output_path=None, prettyprint=True, header=None, dimension_at_observation=None)
Write data to SDMX-ML 3.0 Structure Specific format.
- Parameters:
datasets (
Sequence
[PandasDataset
]) – The datasets to be written.output_path (
Union
[str
,Path
,None
]) – The path to save the file.prettyprint (
bool
) – Prettyprint or not.header (
Optional
[Header
]) – The header to be used (generated if None).dimension_at_observation (
Optional
[Dict
[str
,str
]]) – The mapping between the dataset and the dimension at observation.
- Return type:
Optional
[str
]- Returns:
The XML string if path is empty, None otherwise.
STRUCTURE_SDMX_ML_3_0 -> pysdmx.io.xml.sdmx30.writer.structure
- pysdmx.io.xml.sdmx30.writer.structure.write(structures, output_path=None, prettyprint=True, header=None)
This function writes a SDMX-ML file from the Message Content.
- Parameters:
structures (
Sequence
[MaintainableArtefact
]) – The content to be writtenoutput_path (
Union
[str
,Path
,None
]) – The path to save the fileprettyprint (
bool
) – Prettyprint or notheader (
Optional
[Header
]) – The header to be used (generated if None)
- Return type:
Optional
[str
]- Returns:
The XML string if output_path is empty, None otherwise