SDMX CSV
This format is only used for data, not for Structures. The SDMX CSV readers and writers are compatible with SDMX-CSV 1.0 and 2.0 standards on the Basic format.
Important
To use the SDMX-CSV functionalities, you need to install the pysdmx[data] extra.
Check the installation guide for more information.
Reading
Although the use of the general reader is always recommended, specific readers for SDMX-CSV are also available:
DATA_SDMX_CSV_1_0_0 -> pysdmx.io.csv.sdmx10.reader
- pysdmx.io.csv.sdmx10.reader.read(input_str)
Reads csv data and returns a sequence of Datasets.
- Parameters:
input_str (
str
) – str.- Return type:
Sequence
[PandasDataset
]- Returns:
A Sequence of Pandas Datasets.
- Raises:
Invalid – If it is an invalid CSV file.
DATA_SDMX_CSV_2_0_0 -> pysdmx.io.csv.sdmx20.reader
- pysdmx.io.csv.sdmx20.reader.read(input_str)
Reads csv data and returns a sequence of Datasets.
- Parameters:
input_str (
str
) – str.- Return type:
Sequence
[PandasDataset
]- Returns:
A Sequence of Pandas Datasets.
- Raises:
Invalid – If it is an invalid CSV file.
DATA_SDMX_CSV_2_1_0 -> pysdmx.io.csv.sdmx21.reader
- pysdmx.io.csv.sdmx21.reader.read(input_str)
Reads csv data and returns a sequence of Datasets.
- Parameters:
input_str (
str
) – str.- Return type:
Sequence
[PandasDataset
]- Returns:
A Sequence of Pandas Datasets.
- Raises:
Invalid – If it is an invalid CSV file.
Writing
Although the use of the general writer is always recommended, specific writers for SDMX-CSV are also available:
DATA_SDMX_CSV_1_0_0 -> pysdmx.io.csv.sdmx10.writer
- pysdmx.io.csv.sdmx10.writer.write(datasets, labels=None, time_format=None, output_path=None)
Write data to SDMX-CSV 1.0 format.
- Parameters:
datasets (
Sequence
[PandasDataset
]) – List of datasets to write. Must have the same components.output_path (
Union
[str
,Path
,None
]) – Path to write the data to. If None, the data is returned as a string.labels (
Optional
[Literal
['id'
,'both'
]]) – How to write the name of the columns. If None, only the IDs are written. if “id”, the names are written as ID only. If “both”, the names are witten as id:Name.time_format (
Optional
[Literal
['original'
,'normalized'
]]) – How to write the time period. If None, the time period is not modified. If “original”, the time period is written as it is in the dataset. “Normalized” is not implemented yet.
- Return type:
Optional
[str
]- Returns:
SDMX CSV data as a string, if output_path is None.
DATA_SDMX_CSV_2_0_0 -> pysdmx.io.csv.sdmx20.writer
- pysdmx.io.csv.sdmx20.writer.write(datasets, labels=None, time_format=None, keys=None, output_path=None)
Write data to SDMX-CSV 2.0 format.
- Parameters:
datasets (
Sequence
[PandasDataset
]) – List of datasets to write. Must have the same components.labels (
Optional
[Literal
['name'
,'id'
,'both'
]]) – How to write the name of the columns. If None, only the IDs are written. if “id”, the names are written as ID only. if “name”, a colum called “STRUCTURE_NAME” is added after struture ID. If “both”, the names are witten as id:Name.time_format (
Optional
[Literal
['original'
,'normalized'
]]) – How to write the time period. If None, the time period is not modified. If “original”, the time period is written as it is in the dataset. “normalized” is not implemented yet.keys (
Optional
[Literal
['obs'
,'series'
,'both'
]]) – to write or not the keys columns If None, no keys are written. If “obs”, the keys are write as a single column called “OBS_KEY”. If “series”, the keys are write as a single column called “SERIES_KEY”. If “both”, the keys are write as two columns: “OBS_KEY” and “SERIES_KEY”.output_path (
Union
[str
,Path
,None
]) – Path to write the data to. If None, the data is returned as a string.
- Return type:
Optional
[str
]- Returns:
SDMX CSV data as a string, if output_path is None.
DATA_SDMX_CSV_2_1_0 -> pysdmx.io.csv.sdmx21.writer
- pysdmx.io.csv.sdmx21.writer.write(datasets, labels=None, time_format=None, keys=None, output_path=None)
Write data to SDMX-CSV 2.1 format.
- Parameters:
datasets (
Sequence
[PandasDataset
]) – List of datasets to write. Must have the same components.labels (
Optional
[Literal
['name'
,'id'
,'both'
]]) – How to write the name of the columns. If None, only the IDs are written. if “id”, the names are written as ID only. if “name”, a colum called “STRUCTURE_NAME” is added after struture ID. If “both”, the names are witten as id:Name.time_format (
Optional
[Literal
['original'
,'normalized'
]]) – How to write the time period. If None, the time period is not modified. If “original”, the time period is written as it is in the dataset. “normalized” is not implemented yet.keys (
Optional
[Literal
['obs'
,'series'
,'both'
]]) – to write or not the keys columns If None, no keys are written. If “obs”, the keys are write as a single column called “OBS_KEY”. If “series”, the keys are write as a single column called “SERIES_KEY”. If “both”, the keys are write as two columns: “OBS_KEY” and “SERIES_KEY”.output_path (
Union
[str
,Path
,None
]) – Path to write the data to. If None, the data is returned as a string.
- Return type:
Optional
[str
]- Returns:
SDMX CSV data as a string, if output_path is None.