General Writer
The pysdmx general writer is a set of methods to read any SDMX message, regardless of the format or version.
Tutorial on writing SDMX Data messages.
Tutorial on writing SDMX Structure messages.
Formats and Versions Supported
List of formats and versions supported by the general writer:
Write SDMX
Serializes any SDMX object to a file or returns it as a string.
Examples of SDMX objects:
MaintainableArtefacts (e.g.
Codelist
,DataStructureDefinition
,ConceptScheme
, etc.)
Warning
Currently, the general writer is able to write one by one the objects, but it cannot access to the referenced objects (i.e we do not write the children/descendants of an object, we generate its references only even if the actual object is present). You may write the referenced objects by adding them as parameters to the write_sdmx function, as if you were writing them individually in the same SDMX Message.
In a following release, we will add support for writing the referenced objects (if already present) or download them automatically.
- pysdmx.io.write_sdmx(sdmx_objects, sdmx_format, output_path='', **kwargs)
Writes any SDMX object (or list of them) to any supported SDMX format.
See the formats available
Important
To use the pysdmx.io data functionalities, you need to install the pysdmx[data] extra.
For SDMX-ML support, you also need to install the pysdmx[xml] extra.
Check the installation guide for more information.
Important
To write SDMX-ML Generic or Series messages, the PandasDataset requires to have its structure defined as a
Schema
.- Parameters:
sdmx_objects (
Any
) – Model objects to write, including PandasDataset, DataStructure, Dataflow, ConceptScheme, etc.sdmx_format (
Format
) – The pysdmx.io.Format to write to, e.g., Format.DATA_SDMX_ML_3_0.output_path (
str
) – The path to save the file. If empty, returns a string.**kwargs (
Any
) – Additional keyword arguments (see below).
- Keyword Arguments:
prettyprint – Whether to pretty-print the output (default: True) (only for SDMX-ML).
header – Custom
Header
to include in the SDMX Message (only for SDMX-ML)dimension_at_observation – Mapping for dimension at observation (only for SDMX-ML Data formats). This is a dictionary where the keys are short URNs and the values are the dimension IDs that should be used as the dimension at observation for that structure in the output. For example,
{"Dataflow=MD:TEST_MD(1.0)": "TIME_PERIOD"}
. Overrides the header.structure (if a custom header is provided).
- Return type:
Optional
[str
]- Returns:
A serialised string if output_path is an empty string, otherwise None.
- Raises:
Invalid – If the file is empty or the format is not supported.