Parse SDMX file formats
Contents
Parse SDMX file formats#
SDMX-ML#
sdmx
supports the several types of SDMX-ML messages.
SDMXML v2.1 reader.
- class sdmx.reader.xml.Reader[source]#
- annotable(cls, elem, **kwargs)[source]#
Create a AnnotableArtefact of cls from elem and kwargs.
Collects all parsed <com:Annotation>.
- content_types: List[str] = ['application/xml', 'text/xml', 'application/vnd.sdmx.generic+xml;version=2.1', 'application/vnd.sdmx.genericdata+xml;version=2.1', 'application/vnd.sdmx.structurespecificdata+xml;version=2.1', 'application/vnd.sdmx.generictimeseriesdata+xml;version=2.1', 'application/vnd.sdmx.structurespecifictimeseriesdata+xml;version=2.1', 'application/vnd.sdmx.structure+xml;version=2.1', 'application/vnd.sdmx.schema+xml;version=2.1', 'application/vnd.sdmx.genericmetadata+xml;version=2.1', 'application/vnd.sdmx.structurespecificmetadata+xml;version=2.1']#
List of HTTP content types handled by the reader.
- get_single(cls_or_name: Union[Type, str], id: Optional[str] = None, subclass: bool = False) Optional[Any] [source]#
Return a reference to an object while leaving it in its stack.
Always returns 1 object. Returns
None
if no matching object exists, or if 2 or more objects meet the conditions.If id is given, only return an IdentifiableArtefact with the matching ID.
If cls_or_name is a class and subclass is
True
; check all objects in the stack cls_or_name or any stack for a subclass of this class.
- identifiable(cls, elem, **kwargs)[source]#
Create a IdentifiableArtefact of cls from elem and kwargs.
- maintainable(cls, elem, **kwargs)[source]#
Create or retrieve a MaintainableArtefact of cls from elem and kwargs.
Following the SDMX-IM class hierarchy,
maintainable()
callsnameable()
, which in turn callsidentifiable()
, etc. (Since no concrete class is versionable but not maintainable, no separate method is created, for better performance). For all of these methods:Already-parsed items are removed from the stack only if elem is not
None
.kwargs (e.g. ‘id’) take precedence over any values retrieved from attributes of elem.
If elem is None,
maintainable()
returns a MaintainableArtefact with the is_external_reference attribute set toTrue
. Subsequent calls with the same object ID will return references to the same object.
- nameable(cls, elem, **kwargs)[source]#
Create a NameableArtefact of cls from elem and kwargs.
Collects all parsed
InternationalString
localizations of <com:Name> and <com:Description>.
- peek(cls_or_name: Union[Type, str])[source]#
Get the object at the top of stack cls_or_name without removing it.
- pop_all(cls_or_name: Union[Type, str], subclass=False) Iterable [source]#
Pop all objects from stack cls_or_name and return.
If cls_or_name is a class and subclass is
True
; return all objects in the stack cls_or_name or any stack for a subclass of this class.
- pop_resolved_ref(cls_or_name: Union[Type, str])[source]#
Pop a reference to cls_or_name and resolve it.
- pop_single(cls_or_name: Union[Type, str])[source]#
Pop a single object from the stack for cls_or_name and return.
- read_message(source, dsd: Optional[sdmx.model.DataStructureDefinition] = None) sdmx.message.Message [source]#
Read message from source.
- Parameters
source (file-like) – Message content.
dsd (DataStructureDefinition, optional) – DSD for aid in reading source.
- Returns
An instance of a Message subclass.
- Return type
SDMX-JSON#
- class sdmx.reader.json.Reader[source]#
Read SDMX-JSON and expose it as instances from
sdmx.model
.- content_types: List[str] = ['application/vnd.sdmx.draft-sdmx-json+json', 'draft-sdmx-json', 'text/json', 'application/vnd.sdmx.data+json;version=1.0.0', 'application/vnd.sdmx.structure+json;version=1.0.0']#
List of HTTP content types handled by the reader.
- read_message(source, dsd=None)[source]#
Read message from source.
- Parameters
source (file-like) – Message content.
dsd (DataStructureDefinition, optional) – DSD for aid in reading source.
- Returns
An instance of a Message subclass.
- Return type
Reader API#
- sdmx.reader.READERS = [<class 'sdmx.reader.json.Reader'>, <class 'sdmx.reader.xml.Reader'>]#
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_content_type(ctype)[source]#
Return a reader class for HTTP content type content.
- Raises
ValueError – If no reader class matches.
See also
BaseReader.content_types
- 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
filename_or_obj (str or
PathLike
or file) –format ('XML' or 'JSON', optional) –
dsd (
DataStructureDefinition
) – For “structure-specific” format`=``XML` messages only.
- class sdmx.reader.base.BaseReader[source]#
-
- abstract read_message(source, dsd=None)[source]#
Read message from source.
- Parameters
source (file-like) – Message content.
dsd (DataStructureDefinition, optional) – DSD for aid in reading source.
- Returns
An instance of a Message subclass.
- Return type