API reference¶
See also the Implementation notes.
Top-level methods and classes¶
Statistical Data and Metadata eXchange (SDMX) for the Python data ecosystem
- class pandasdmx.Request(source=None, log_level=None, session=None, timeout=30.1, **session_opts)[source]¶
Client for a SDMX REST web service.
Parameters:
- sourcestr or source.Source
Identifier of a data source. If a string, must be one of the known sources in
list_sources()
.- log_levelint
Override the package-wide logger with one of the standard logging levels.
- sessionoptional instance of
requests.Session
, or a subclass. If given, it is used for HTTP requests, and any session_opts passed will raise TypeError. A typical use case is the injection of alternative caching libraries such as Cache Control.
- timeoutfloat or 2-tuple.
It is stored as
Request.timeout
. It is passed on to each HTTP request to an SDMX source. Default is 30.1. If it is a float, it denotes the number of seconds to wait for a response from the server. See the docs for the`requests` library for more details.- session_opts :
Additional keyword arguments are passed to
Session
. Typical uses are to specify proxies, auth or cert.
- property default_locale¶
Return global default locale for international strings used, eg. by writers
- get(resource_type=None, resource_id=None, tofile=None, use_cache=False, dry_run=False, **kwargs)[source]¶
Retrieve SDMX data or metadata.
(Meta)data is retrieved from the
source
of the current Request. The item(s) to retrieve can be specified in one of two ways:resource_type, resource_id: These give the type (see
Resource
) and, optionally, ID of the item(s). If the resource_id is not given, all items of the given type are retrieved.a resource object, i.e. a
MaintainableArtefact
: resource_type and resource_id are determined by the object’s class andid
attribute, respectively.
Data is retrieved with resource_type=’data’. In this case, the optional keyword argument key can be used to constrain the data that is retrieved. Examples of the formats for key:
{'GEO': ['EL', 'ES', 'IE']}
:dict
with dimension name(s) mapped to an iterable of allowable values.{'GEO': 'EL+ES+IE'}
:dict
with dimension name(s) mapped to strings joining allowable values with ‘+’, the logical ‘or’ operator for SDMX web services.'....EL+ES+IE'
:str
in which ordered dimension values (some empty,''
) are joined with'.'
. Using this form requires knowledge of the dimension order in the target data resource_id; in the example, dimension ‘GEO’ is the fifth of five dimensions:'.'.join(['', '', '', '', 'EL+ES+IE'])
.CubeRegion.to_query_string()
can also be used to create properly formatted strings.
For formats 1 and 2, but not 3, the key argument is validated against the relevant
DataStructureDefinition
, either given with the dsd keyword argument, or retrieved from the web service before the main query.For the optional param keyword argument, some useful parameters are:
‘startperiod’, ‘endperiod’: restrict the time range of data to retrieve.
‘references’: control which item(s) related to a metadata resource are retrieved, e.g. references=’parentsandsiblings’.
Parameters:
- resource_typestr or
Resource
, optional Type of resource to retrieve.
- resource_idstr, optional
ID of the resource to retrieve.
- tofilestr or
PathLike
or file-like object, or
fsspec.core.OpenFile
with 1 item, optional File path or file-like to write SDMX data as it is recieved. file-like must be binary and writable. It may be used in a with-context (recommended when using a fsspec.core.OpenFile.- use_cachebool, optional
If
True
, return a previously retrievedMessage
fromcache
, or update the cache with a newly-retrieved Message.- dry_runbool, optional
If
True
, prepare and return arequests.Request
object, but do not execute the query. The prepared URL and headers can be examined by inspecting the returned object.- **kwargs
Other, optional parameters (below).
Other Parameters:
- dsd
DataStructureDefinition
Existing object used to validate the key argument. If not provided, an additional query executed to retrieve a DSD in order to validate the key.
- forcebool
If
True
, execute the query even if thesource
does not support queries for the given resource_type. Default:False
.- headersdict
HTTP headers. Given headers will overwrite instance-wide headers passed to the constructor. Default:
None
to use the default headers of thesource
.- keystr or dict
For queries with resource_type=’data’.
str
values are not validated;dict
values are validated usingmake_constraint()
.- paramsdict
Query parameters. The SDMX REST web service guidelines describe parameters and allowable values for different queries. params is not validated before the query is executed.
- providerstr
ID of the agency providing the data or metadata. Default: ID of the
source
agency.An SDMX web service is a ‘data source’ operated by a specific, ‘source’ agency. A web service may host data or metadata originally published by one or more ‘provider’ agencies. Many sources are also providers. Other agencies—e.g. the SDMX Global Registry—simply aggregate (meta)data from other providers, but do not providing any (meta)data themselves.
- resource
MaintainableArtefact
subclass Object to retrieve. If given, resource_type and resource_id are ignored.
- versionstr
version>
of a resource to retrieve. Default: the keyword ‘latest’.
Returns:
Raises:
- preview_data(flow_id, key={})[source]¶
Return a preview of data.
For the Dataflow flow_id, return all series keys matching key. preview_data() uses a feature supported by some data providers that returns
SeriesKeys
without the correspondingObservations
.To count the number of series:
keys = sdmx.Request('PROVIDER').preview_data('flow') len(keys)
To get a
pandas
object containing the key values:keys_df = sdmx.to_pandas(keys)
Parameters:
- flow_idstr
Dataflow to preview.
- keydict, optional
Mapping of dimension to values, where values may be a ‘+’-delimited list of values. If given, only SeriesKeys that match key are returned. If not given, preview_data is equivalent to
list(req.series_keys(flow_id))
.
Returns:
list of
SeriesKey
- source = None¶
source.Source
for requests sent from the instance.
- validate(msg, schema_dir=None)[source]¶
Validate msg against the XML schemas which must be installed first.
Parameters:
- msg: pandasdmx.message.Message or file-like
the XML message to be validated. If a message.Message instance is provided, the file is re-downloaded, ideally from cache.
- schema_dir: path-like or str
Optional custom dir where schemas are installed.
Returns True on success.
See also the LXML documentation.
- property validation_level¶
Return current validation level.
- class pandasdmx.Resource(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Enumeration of SDMX-REST API resources.
Enum
memberpandasdmx.model
classactualconstraint
agencyscheme
allowedconstraint
attachementconstraint
categorisation
categoryscheme
codelist
conceptscheme
contentconstraint
data
dataflow
dataconsumerscheme
dataproviderscheme
datastructure
organisationscheme
provisionagreement
structure
Mixed.
customtypescheme
Not implemented.
hierarchicalcodelist
Not implemented.
metadata
Not implemented.
metadataflow
Not implemented.
metadatastructure
Not implemented.
namepersonalisationscheme
Not implemented.
organisationunitscheme
Not implemented.
process
Not implemented.
reportingtaxonomy
Not implemented.
rulesetscheme
Not implemented.
schema
Not implemented.
structureset
Not implemented.
transformationscheme
Not implemented.
userdefinedoperatorscheme
Not implemented.
vtlmappingscheme
Not implemented.
- classmethod class_name(value: Resource, default=None) str [source]¶
Return the name of a
pandasdmx.model
class from an enum value.Values are returned in lower case.
- pandasdmx.add_source(info, id=None, override=False, **kwargs)[source]¶
Add a new data source.
The info expected is in JSON format:
{ "id": "ESTAT", "documentation": "http://data.un.org/Host.aspx?Content=API", "url": "http://ec.europa.eu/eurostat/SDMX/diss-web/rest", "name": "Eurostat", "supported": {"codelist": false, "preview": true} }
…with unspecified values using the defaults; see
Source
.- Parameters:
info (dict-like) – String containing JSON information about a data source.
id (str) – Identifier for the new datasource. If
None
(default), then info[‘id’] is used.override (bool) – If
True
, replace any existing data source with id. Otherwise, raiseValueError
.**kwargs – Optional callbacks for handle_response and finish_message hooks.
- pandasdmx.list_sources()[source]¶
Return a sorted list of valid source IDs.
These can be used to create
Request
instances.
- pandasdmx.read_sdmx(filename_or_obj, format=None, **kwargs)[source]¶
Load a SDMX-ML or SDMX-JSON message from a file or file-like object. A given file-like object is closed after loading.
- Parameters:
filename_or_obj (str or
PathLike
) – or open binary file. A file is not closed explicitly. So it should be passed from a with-context.format ('XML' or 'JSON', optional) –
dsd (
DataStructureDefinition
) – For “structure-specific” format`=``XML` messages only.
- pandasdmx.to_xml(obj, **kwargs)[source]¶
Convert an SDMX obj to SDMX-ML.
- Parameters:
kwargs – Passed to
lxml.etree.to_string()
, e.g. pretty_print =True
.- Raises:
NotImplementedError – If writing specific objects to SDMX-ML has not been implemented in
sdmx
.
- pandasdmx.logger = <Logger pandasdmx (ERROR)>¶
Top-level logger.
By default, messages at the log level
ERROR
or greater are printed tosys.stderr
. These include the web service query details (URL and headers) used byRequest
.To debug requests to web services, set to a more permissive level:
import logging pandasdmx.logger.setLevel(logging.DEBUG)
New in version 0.4.
message
: pandasdmx.messages¶
Classes for SDMX messages.
Message
and related classes are not defined in the SDMX
information model, but in the SDMX-ML standard.
sdmx
also uses DataMessage
to encapsulate SDMX-JSON data returned by
data sources.
- class pandasdmx.message.DataMessage(*, header: ~pandasdmx.message.Header = <Header> source: test: False, footer: ~pandasdmx.message.Footer | None = None, response: ~typing.Any | None = None, sdmx_schema_location: str | None = None, data: ~typing.List[~pandasdmx.model.DataSet] = [], dataflow: ~pandasdmx.model.DataflowDefinition = <DataflowDefinition (missing id)>, observation_dimension: ~pandasdmx.model._AllDimensions | ~pandasdmx.model.DimensionComponent | ~typing.List[~pandasdmx.model.DimensionComponent] | None = None)[source]¶
Bases:
Message
Data Message.
Note
A DataMessage may contain zero or more
DataSet
, sodata
is a list. To retrieve the first (and possibly only) data set in the message, access the first element of the list:msg.data[0]
.- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two DataMessages are the same if:
their
dataflow
andobservation_dimension
compare equal.they have the same number of
DataSets
, andcorresponding DataSets compare equal (see
DataSet.compare()
).
- dataflow: DataflowDefinition¶
DataflowDefinition
that contains the data.
- observation_dimension: _AllDimensions | DimensionComponent | List[DimensionComponent] | None¶
The “dimension at observation level”.
- class pandasdmx.message.ErrorMessage(*, header: ~pandasdmx.message.Header = <Header> source: test: False, footer: ~pandasdmx.message.Footer | None = None, response: ~typing.Any | None = None, sdmx_schema_location: str | None = None)[source]¶
Bases:
Message
Bases:
BaseModel
Footer of an SDMX-ML message.
SDMX-JSON messages do not have footers.
Return
True
if self is the same as other.Two Footers are the same if their
code
,severity
, andtext
are equal.
The body text of the Footer contains zero or more blocks of text.
- class pandasdmx.message.Header(*, error: str | None = None, extracted: ~datetime.datetime | None = None, id: str | None = None, prepared: ~datetime.datetime | None = None, reporting_begin: ~datetime.datetime | None = None, reporting_end: ~datetime.datetime | None = None, receiver: ~pandasdmx.model.Agency | None = None, sender: ~pandasdmx.model.Agency | None = None, source: ~pandasdmx.model.InternationalString =, test: bool = False)[source]¶
Bases:
BaseModel
Header of an SDMX-ML message.
SDMX-JSON messages do not have headers.
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two Headers are the same if their corresponding attributes are equal.
- receiver: Agency | None¶
Intended recipient of the message, e.g. the user’s name for an authenticated service.
- reporting_begin: datetime | None¶
Start of the time period covered by a
DataMessage
.
- reporting_end: datetime | None¶
End of the time period covered by a
DataMessage
.
- source: InternationalString¶
- class pandasdmx.message.Message(*, header: ~pandasdmx.message.Header = <Header> source: test: False, footer: ~pandasdmx.message.Footer | None = None, response: ~typing.Any | None = None, sdmx_schema_location: str | None = None)[source]¶
Bases:
BaseModel
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two Messages are the same if their
header
andfooter
compare equal.
(optional)
Footer
instance.
- response: Any | None¶
requests.Response
instance for the response to the HTTP request that returned the Message. This is not part of the SDMX standard.
- class pandasdmx.message.StructureMessage(*, header: ~pandasdmx.message.Header = <Header> source: test: False, footer: ~pandasdmx.message.Footer | None = None, response: ~typing.Any | None = None, sdmx_schema_location: str | None = None, categorisation: ~pandasdmx.util.DictLike[str, ~pandasdmx.model.Categorisation] = None, category_scheme: ~pandasdmx.util.DictLike[str, ~pandasdmx.model.CategoryScheme] = None, codelist: ~pandasdmx.util.DictLike[str, ~pandasdmx.model.Codelist] = None, concept_scheme: ~pandasdmx.util.DictLike[str, ~pandasdmx.model.ConceptScheme] = None, constraint: ~pandasdmx.util.DictLike[str, ~pandasdmx.model.ContentConstraint] = None, dataflow: ~pandasdmx.util.DictLike[str, ~pandasdmx.model.DataflowDefinition] = None, structure: ~pandasdmx.util.DictLike[str, ~pandasdmx.model.DataStructureDefinition] = None, organisation_scheme: ~pandasdmx.util.DictLike[str, ~pandasdmx.model.AgencyScheme] = None, provisionagreement: ~pandasdmx.util.DictLike[str, ~pandasdmx.model.ProvisionAgreement] = None)[source]¶
Bases:
Message
- add(obj: IdentifiableArtefact)[source]¶
Add obj to the StructureMessage.
- categorisation: DictLike[str, Categorisation]¶
Collection of
Categorisation
.
- category_scheme: DictLike[str, CategoryScheme]¶
Collection of
CategoryScheme
.
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two StructureMessages compare equal if
DictLike.compare()
isTrue
for each of the object collection attributes.- Parameters:
strict (bool, optional) – Passed to
DictLike.compare()
.
- concept_scheme: DictLike[str, ConceptScheme]¶
Collection of
ConceptScheme
.
- constraint: DictLike[str, ContentConstraint]¶
Collection of
ContentConstraint
.
- dataflow: DictLike[str, DataflowDefinition]¶
Collection of
DataflowDefinition
.
- get(obj_or_id: str | IdentifiableArtefact) IdentifiableArtefact | None [source]¶
Retrieve obj_or_id from the StructureMessage.
- Parameters:
obj_or_id (str or .IdentifiableArtefact) – If an IdentifiableArtefact, return an object of the same class and
id
; ifstr
, an object with this ID.- Returns:
.IdentifiableArtefact – with the given ID and possibly class.
None – if there is no match.
- Raises:
ValueError – if obj_or_id is a string and there are ≥2 objects (of different classes) with the same ID.
- objects(cls)[source]¶
Get a reference to the attribute for objects of type cls.
For example, if cls is the class
DataStructureDefinition
(not an instance), return a reference tostructure
.
- organisation_scheme: DictLike[str, AgencyScheme]¶
Collection of
AgencyScheme
.
- provisionagreement: DictLike[str, ProvisionAgreement]¶
Collection of
ProvisionAgreement
.
- structure: DictLike[str, DataStructureDefinition]¶
Collection of
DataStructureDefinition
.
model
: SDMX Information Model¶
SDMX Information Model (SDMX-IM).
This module implements many of the classes described in the SDMX-IM specification (‘spec’), which is available from:
- https://sdmx.org/wp-content/uploads/
SDMX_2-1-1_SECTION_2_InformationModel_201108.pdf
Details of the implementation:
Python typing and pydantic are used to enforce the types of attributes that reference instances of other classes.
Some classes have convenience attributes not mentioned in the spec, to ease navigation between related objects. These are marked “
sdmx
extension not in the IM.”Class definitions are grouped by section of the spec, but these sections appear out of order so that dependent classes are defined first.
- class pandasdmx.model.ActionType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
Enum
- append = 3¶
- delete = 1¶
- information = 4¶
- replace = 2¶
- class pandasdmx.model.Agency(*args, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, parent: ~pandasdmx.model.IT | ItemScheme | None = None, child: ~typing.List[~pandasdmx.model.IT] = [], contact: ~typing.List[~pandasdmx.model.Contact] = [])[source]¶
Bases:
Organisation
- class pandasdmx.model.AgencyScheme(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, is_partial: bool | None = None, items: ~typing.Dict[str, ~pandasdmx.model.IT] = {})[source]¶
Bases:
ItemScheme
[Agency
],OrganisationScheme
- class pandasdmx.model.AnnotableArtefact(*, annotations: List[Annotation] = [])[source]¶
Bases:
BaseModel
- annotations: List[Annotation]¶
Annotations
of the object.pandaSDMX
implementation: The IM does not specify the name of this feature.
- get_annotation(**attrib)[source]¶
Return a
Annotation
with given attrib, e.g. ‘id’.If more than one attrib is given, all must match a particular annotation.
- Raises:
KeyError – If there is no matching annotation.
- pop_annotation(**attrib)[source]¶
Remove and return a
Annotation
with given attrib, e.g. ‘id’.If more than one attrib is given, all must match a particular annotation.
- Raises:
KeyError – If there is no matching annotation.
- class pandasdmx.model.Annotation(*, id: str | None = None, title: str | None = None, type: str | None = None, url: str | None = None, text: ~pandasdmx.model.InternationalString =)[source]¶
Bases:
BaseModel
- text: InternationalString¶
Content of the annotation.
- class pandasdmx.model.AttachmentConstraint(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, data_content_keys: ~pandasdmx.model.DataKeySet | None = None, role: ~pandasdmx.model.ConstraintRole, attachment: ~typing.Set[~pandasdmx.model.ConstrainableArtefact] = {})[source]¶
Bases:
Constraint
- attachment: Set[ConstrainableArtefact]¶
- class pandasdmx.model.AttributeDescriptor(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, components: List[CT] = [], auto_order: int = 1)[source]¶
Bases:
ComponentList
[DataAttribute
]
- class pandasdmx.model.AttributeValue(*args, value: str | Code, value_for: DataAttribute | None = None, start_date: date | None = None)[source]¶
Bases:
BaseModel
SDMX-IM AttributeValue.
In the spec, AttributeValue is an abstract class. Here, it serves as both the concrete subclasses CodedAttributeValue and UncodedAttributeValue.
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two AttributeValues are equal if their properties are equal.
- value_for: DataAttribute | None¶
- class pandasdmx.model.Categorisation(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, category: ~pandasdmx.model.Category | None = None, artefact: ~pandasdmx.model.IdentifiableArtefact | None = None)[source]¶
Bases:
MaintainableArtefact
- artefact: IdentifiableArtefact | None¶
- class pandasdmx.model.Category(*args, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, parent: ~pandasdmx.model.IT | ItemScheme | None = None, child: ~typing.List[~pandasdmx.model.IT] = [])[source]¶
-
SDMX-IM Category.
- class pandasdmx.model.CategoryScheme(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, is_partial: bool | None = None, items: ~typing.Dict[str, ~pandasdmx.model.IT] = {})[source]¶
Bases:
ItemScheme
[Category
]
- class pandasdmx.model.Code(*args, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, parent: ~pandasdmx.model.IT | ItemScheme | None = None, child: ~typing.List[~pandasdmx.model.IT] = [])[source]¶
-
SDMX-IM Code.
- class pandasdmx.model.Codelist(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, is_partial: bool | None = None, items: ~typing.Dict[str, ~pandasdmx.model.IT] = {})[source]¶
Bases:
ItemScheme
[Code
]
- class pandasdmx.model.Component(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, concept_identity: Concept | None = None, local_representation: Representation | None = None)[source]¶
Bases:
IdentifiableArtefact
- local_representation: Representation | None¶
- class pandasdmx.model.ComponentList(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, components: List[CT] = [], auto_order: int = 1)[source]¶
Bases:
IdentifiableArtefact
,Generic
[CT
]- append(value: CT)[source]¶
Append value to
components
.
- auto_order¶
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two ComponentLists are the same if:
IdentifiableArtefact.compare()
isTrue
, andcorresponding
components
compare equal.
- Parameters:
strict (bool, optional) – Passed to
compare()
andIdentifiableArtefact.compare()
.
- getdefault(id, cls=None, **kwargs) CT [source]¶
Return or create the component with the given id.
If the component is automatically created, its
Dimension.order
attribute is set to the value ofauto_order
, which is then incremented.- Parameters:
id (str) – Component ID.
cls (type, optional) – Hint for the class of a new object.
kwargs – Passed to the constructor of
Component
, or a Component subclass ifcomponents
is overridden in a subclass of ComponentList.
- class pandasdmx.model.ComponentValue(*, value_for: Component, value: Any = None)[source]¶
Bases:
BaseModel
- class pandasdmx.model.Concept(*args, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, parent: ~pandasdmx.model.IT | ItemScheme | None = None, child: ~typing.List[~pandasdmx.model.IT] = [], core_representation: ~pandasdmx.model.Representation | None = None, iso_concept: ~pandasdmx.model.ISOConceptReference | None = None)[source]¶
-
- core_representation: Representation | None¶
- iso_concept: ISOConceptReference | None¶
- class pandasdmx.model.ConceptScheme(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, is_partial: bool | None = None, items: ~typing.Dict[str, ~pandasdmx.model.IT] = {})[source]¶
Bases:
ItemScheme
[Concept
]
- class pandasdmx.model.ConstrainableArtefact[source]¶
Bases:
BaseModel
SDMX-IM ConstrainableArtefact.
- class pandasdmx.model.Constraint(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, data_content_keys: ~pandasdmx.model.DataKeySet | None = None, role: ~pandasdmx.model.ConstraintRole)[source]¶
Bases:
MaintainableArtefact
- data_content_keys: DataKeySet | None¶
DataKeySet
included in the Constraint.
- role: ConstraintRole¶
- class pandasdmx.model.ConstraintRole(*, role: ConstraintRoleType)[source]¶
Bases:
BaseModel
- role: ConstraintRoleType¶
- class pandasdmx.model.ConstraintRoleType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
Enum
- actual = 2¶
- allowable = 1¶
- class pandasdmx.model.Contact(*, name: ~pandasdmx.model.InternationalString = , org_unit: ~pandasdmx.model.InternationalString = , telephone: str | None = None, responsibility: ~pandasdmx.model.InternationalString = , email: ~typing.List[str], uri: ~typing.List[str])[source]¶
Bases:
BaseModel
Organization contact information.
IMF is the only known data provider that returns messages with
Contact
information. These differ from the IM in several ways. This class reflects these differences:‘name’ and ‘org_unit’ are InternationalString, instead of strings.
‘email’ may be a list of e-mail addresses, rather than a single address.
‘uri’ may be a list of URIs, rather than a single URI.
- name: InternationalString¶
- org_unit: InternationalString¶
- responsibility: InternationalString¶
- class pandasdmx.model.ContentConstraint(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, data_content_keys: ~pandasdmx.model.DataKeySet | None = None, role: ~pandasdmx.model.ConstraintRole, data_content_region: ~typing.List[~pandasdmx.model.CubeRegion] = [], content: ~typing.Set[~pandasdmx.model.ConstrainableArtefact] = {})[source]¶
Bases:
Constraint
- content: Set[ConstrainableArtefact]¶
- data_content_region: List[CubeRegion]¶
CubeRegions
included in the ContentConstraint.
- class pandasdmx.model.CubeRegion(*, included: bool = True, member: Dict[Dimension, MemberSelection] = {})[source]¶
Bases:
BaseModel
- member: Dict[Dimension, MemberSelection]¶
- class pandasdmx.model.DataAttribute(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, concept_identity: Concept | None = None, local_representation: Representation | None = None, related_to: AttributeRelationship | None = None, usage_status: UsageStatus | None = None)[source]¶
Bases:
Component
- usage_status: UsageStatus | None¶
- class pandasdmx.model.DataConsumer(*args, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, parent: ~pandasdmx.model.IT | ItemScheme | None = None, child: ~typing.List[~pandasdmx.model.IT] = [], contact: ~typing.List[~pandasdmx.model.Contact] = [])[source]¶
Bases:
Organisation
,ConstrainableArtefact
SDMX-IM DataConsumer.
- class pandasdmx.model.DataConsumerScheme(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, is_partial: bool | None = None, items: ~typing.Dict[str, ~pandasdmx.model.IT] = {})[source]¶
Bases:
ItemScheme
[DataConsumer
],OrganisationScheme
- class pandasdmx.model.DataKey(*, included: bool, key_value: Dict[Component, ComponentValue])[source]¶
Bases:
BaseModel
- key_value: Dict[Component, ComponentValue]¶
Mapping from
Component
toComponentValue
comprising the key.
- class pandasdmx.model.DataKeySet(*, included: bool, keys: List[DataKey] = [])[source]¶
Bases:
BaseModel
- class pandasdmx.model.DataProvider(*args, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, parent: ~pandasdmx.model.IT | ItemScheme | None = None, child: ~typing.List[~pandasdmx.model.IT] = [], contact: ~typing.List[~pandasdmx.model.Contact] = [])[source]¶
Bases:
Organisation
,ConstrainableArtefact
SDMX-IM DataProvider.
- class pandasdmx.model.DataProviderScheme(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, is_partial: bool | None = None, items: ~typing.Dict[str, ~pandasdmx.model.IT] = {})[source]¶
Bases:
ItemScheme
[DataProvider
],OrganisationScheme
- class pandasdmx.model.DataSet(*, annotations: List[Annotation] = [], action: ActionType | None = None, attrib: DictLike[str, AttributeValue] = None, valid_from: str | None = None, described_by: DataflowDefinition | None = None, structured_by: DataStructureDefinition | None = None, obs: List[Observation] = [], series: DictLike[SeriesKey, List[Observation]] = None, group: DictLike[GroupKey, List[Observation]] = None)[source]¶
Bases:
AnnotableArtefact
- action: ActionType | None¶
- add_obs(observations, series_key=None)[source]¶
Add observations to a series with series_key.
Checks consistency and adds group associations.
- attrib: DictLike[str, AttributeValue]¶
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two DataSets are the same if:
their
action
,valid_from
compare equal.all dataset-level attached attributes compare equal.
they have the same number of observations, series, and groups.
- described_by: DataflowDefinition | None¶
- group: DictLike[GroupKey, List[Observation]]¶
Map of group key → list of observations.
sdmx
extension not in the IM.
- obs: List[Observation]¶
All observations in the DataSet.
- series: DictLike[SeriesKey, List[Observation]]¶
Map of series key → list of observations.
sdmx
extension not in the IM.
- structured_by: DataStructureDefinition | None¶
- class pandasdmx.model.DataStructureDefinition(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, grouping: ~pandasdmx.model.ComponentList | None = None, attributes: ~pandasdmx.model.AttributeDescriptor = <AttributeDescriptor: >, dimensions: ~pandasdmx.model.DimensionDescriptor = <DimensionDescriptor: >, measures: ~pandasdmx.model.MeasureDescriptor = <MeasureDescriptor: >, group_dimensions: ~pandasdmx.util.DictLike[str, ~pandasdmx.model.GroupDimensionDescriptor] = None)[source]¶
Bases:
Structure
,ConstrainableArtefact
SDMX-IM DataStructureDefinition (‘DSD’).
- attributes: AttributeDescriptor¶
A
AttributeDescriptor
that describes the attributes of the data structure.
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two DataStructureDefinitions are the same if each of
attributes
,dimensions
,measures
, andgroup_dimensions
compares equal.- Parameters:
strict (bool, optional) – Passed to
ComponentList.compare()
.
- dimensions: DimensionDescriptor¶
A
DimensionDescriptor
that describes the dimensions of the data structure.
- classmethod from_keys(keys)[source]¶
Return a new DSD given some keys.
The DSD’s
dimensions
refers to a set of newConcepts
andCodelists
, created to represent all the values observed across keys for each dimension.
- group_dimensions: DictLike[str, GroupDimensionDescriptor]¶
Mapping from
GroupDimensionDescriptor.id
toGroupDimensionDescriptor
.
- iter_keys(constraint: Constraint = None, dims: List[str] = []) Generator[Key, None, None] [source]¶
Iterate over keys.
- Parameters:
constraint (Constraint, optional) – If given, only yield Keys that are within the constraint.
dims (list of str, optional) – If given, only iterate over allowable values for the Dimensions with these IDs. Other dimensions have only a single value like “(DIM_ID)”, where DIM_ID is the ID of the dimension.
- make_constraint(key)[source]¶
Return a constraint for key.
key is a
dict
wherein:keys are
str
ids of Dimensions appearing in this DSD’sdimensions
, andvalues are ‘+’-delimited
str
containing allowable values, or iterables ofstr
, each an allowable value.
For example:
cc2 = dsd.make_constraint({'foo': 'bar+baz', 'qux': 'q1+q2+q3'})
cc2
includes any key where the ‘foo’ dimension is ‘bar’ or ‘baz’, and the ‘qux’ dimension is one of ‘q1’, ‘q2’, or ‘q3’.- Returns:
A constraint with one
CubeRegion
in itsdata_content_region
, including only the values appearing in key.- Return type:
- Raises:
ValueError – if key contains a dimension IDs not appearing in
dimensions
.
- make_key(key_cls, values: Mapping, extend=False, group_id=None)[source]¶
Make a
Key
or subclass.- Parameters:
key_cls (Key or SeriesKey or GroupKey) – Class of Key to create.
values (dict) – Used to construct
Key.values
.extend (bool, optional) – If
True
, make_key will not returnKeyError
on missing dimensions. Insteaddimensions
(key_cls is Key or SeriesKey) orgroup_dimensions
(key_cls is GroupKey) will be extended by creating new Dimension objects.group_id (str, optional) – When key_cls is :class`.GroupKey`, the ID of the
GroupDimensionDescriptor
that structures the key.
- Returns:
An instance of key_cls.
- Return type:
- Raises:
KeyError – If any of the keys of values is not a Dimension or Attribute in the DSD.
- measures: MeasureDescriptor¶
- class pandasdmx.model.DataflowDefinition(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, structure: ~pandasdmx.model.DataStructureDefinition = <DataStructureDefinition (missing id)>)[source]¶
Bases:
StructureUsage
,ConstrainableArtefact
- iter_keys(constraint: Constraint = None, dims: List[str] = []) Generator[Key, None, None] [source]¶
Iterate over keys.
See also
- structure: DataStructureDefinition¶
- class pandasdmx.model.Dimension(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, concept_identity: Concept | None = None, local_representation: Representation | None = None, order: int | None = None)[source]¶
Bases:
DimensionComponent
SDMX-IM Dimension.
- class pandasdmx.model.DimensionComponent(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, concept_identity: Concept | None = None, local_representation: Representation | None = None, order: int | None = None)[source]¶
Bases:
Component
- class pandasdmx.model.DimensionDescriptor(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, components: List[CT] = [], auto_order: int = 1)[source]¶
Bases:
ComponentList
[DimensionComponent
]Describes a set of dimensions.
IM: “An ordered set of metadata concepts that, combined, classify a statistical series, and whose values, when combined (the key) in an instance such as a data set, uniquely identify a specific observation.”
components
is alist
(ordered) ofDimension
,MeasureDimension
, and/orTimeDimension
.- assign_order()[source]¶
Assign the
DimensionComponent.order
attribute.The Dimensions in
components
are numbered, starting from 1.
- class pandasdmx.model.DimensionRelationship(*, dimensions: List[DimensionComponent] = [], group_key: GroupDimensionDescriptor | None = None)[source]¶
Bases:
AttributeRelationship
- dimensions: List[DimensionComponent]¶
- group_key: GroupDimensionDescriptor | None¶
NB the IM says “0..*” here in a diagram, but the text does not match.
- class pandasdmx.model.Facet(*, type: FacetType = FacetType(is_sequence=None, min_length=None, max_length=None, min_value=None, max_value=None, start_value=None, end_value=None, interval=None, time_interval=None, decimals=None, pattern=None, start_time=None, end_time=None), value: str | None = None, value_type: FacetValueType | None = None)[source]¶
Bases:
BaseModel
- value_type: FacetValueType | None¶
- class pandasdmx.model.FacetType(*, is_sequence: bool | None = None, min_length: int | None = None, max_length: int | None = None, min_value: float | None = None, max_value: float | None = None, start_value: float | None = None, end_value: str | None = None, interval: float | None = None, time_interval: timedelta | None = None, decimals: int | None = None, pattern: str | None = None, start_time: datetime | None = None, end_time: datetime | None = None)[source]¶
Bases:
BaseModel
- class pandasdmx.model.FacetValueType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
Enum
- alpha = 13¶
- alphaNumeric = 14¶
- basicTimePeriod = 20¶
- bigInteger = 2¶
- boolean = 9¶
- count = 11¶
- dataSetReference = 43¶
- dateTime = 34¶
- day = 38¶
- decimal = 6¶
- double = 8¶
- duration = 40¶
- exclusiveValueRange = 16¶
- float = 7¶
- gregorianDay = 25¶
- gregorianMonth = 23¶
- gregorianTimePeriod = 21¶
- gregorianYear = 22¶
- gregorianYearMonth = 24¶
- identifiableReference = 42¶
- inclusiveValueRange = 12¶
- incremental = 17¶
- integer = 3¶
- keyValues = 41¶
- long = 4¶
- month = 36¶
- monthDay = 37¶
- numeric = 15¶
- observationalTimePeriod = 18¶
- reportingDay = 33¶
- reportingMonth = 31¶
- reportingQuarter = 30¶
- reportingSemester = 28¶
- reportingTimePeriod = 26¶
- reportingTrimester = 29¶
- reportingWeek = 32¶
- reportingYear = 27¶
- short = 5¶
- standardTimePeriod = 19¶
- string = 1¶
- time = 39¶
- timesRange = 35¶
- uri = 10¶
- class pandasdmx.model.GenericDataSet(*, annotations: List[Annotation] = [], action: ActionType | None = None, attrib: DictLike[str, AttributeValue] = None, valid_from: str | None = None, described_by: DataflowDefinition | None = None, structured_by: DataStructureDefinition | None = None, obs: List[Observation] = [], series: DictLike[SeriesKey, List[Observation]] = None, group: DictLike[GroupKey, List[Observation]] = None)[source]¶
Bases:
DataSet
SDMX-IM GenericDataSet.
- class pandasdmx.model.GenericTimeSeriesDataSet(*, annotations: List[Annotation] = [], action: ActionType | None = None, attrib: DictLike[str, AttributeValue] = None, valid_from: str | None = None, described_by: DataflowDefinition | None = None, structured_by: DataStructureDefinition | None = None, obs: List[Observation] = [], series: DictLike[SeriesKey, List[Observation]] = None, group: DictLike[GroupKey, List[Observation]] = None)[source]¶
Bases:
DataSet
SDMX-IM GenericTimeSeriesDataSet.
- class pandasdmx.model.GroupDimensionDescriptor(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, components: List[CT] = [], auto_order: int = 1, attachment_constraint: bool | None = None, constraint: AttachmentConstraint | None = None)[source]¶
Bases:
DimensionDescriptor
- assign_order()[source]¶
assign_order()
has no effect for GroupDimensionDescriptor.
- constraint: AttachmentConstraint | None¶
- class pandasdmx.model.GroupKey(arg: Mapping = None, *, attrib: DictLike[str, AttributeValue] = None, described_by: GroupDimensionDescriptor | None = None, values: DictLike[str, KeyValue] = None, id: str | None = None)[source]¶
Bases:
Key
- described_by: GroupDimensionDescriptor | None¶
- class pandasdmx.model.GroupRelationship(*, group_key: GroupDimensionDescriptor | None = None)[source]¶
Bases:
AttributeRelationship
- group_key: GroupDimensionDescriptor | None¶
- class pandasdmx.model.ISOConceptReference(*, agency: str, id: str, scheme_id: str)[source]¶
Bases:
BaseModel
- class pandasdmx.model.IdentifiableArtefact(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {})[source]¶
Bases:
AnnotableArtefact
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two IdentifiableArtefacts are the same if they have the same
id
,uri
, andurn
.
- class pandasdmx.model.InternationalString(value=None, **kwargs)[source]¶
Bases:
object
SDMX-IM InternationalString.
SDMX-IM LocalisedString is not implemented. Instead, the ‘localizations’ is a mapping where:
keys correspond to the ‘locale’ property of LocalisedString.
values correspond to the ‘label’ property of LocalisedString.
When used as a type hint with pydantic, InternationalString fields can be assigned to in one of four ways:
class Foo(BaseModel): name: InternationalString = InternationalString() # Equivalent: no localizations f = Foo() f = Foo(name={}) # Using an explicit locale f.name['en'] = "Foo's name in English" # Using a (locale, label) tuple f.name = ('fr', "Foo's name in French") # Using a dict f.name = {'en': "Replacement English name", 'fr': "Replacement French name"} # Using a bare string, implicitly for the DEFAULT_LOCALE f.name = "Name in DEFAULT_LOCALE language"
Only the first method preserves existing localizations; the latter three replace them.
- class pandasdmx.model.Item(*args, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, parent: ~pandasdmx.model.IT | ItemScheme | None = None, child: ~typing.List[~pandasdmx.model.IT] = [])[source]¶
Bases:
NameableArtefact
,Generic
[IT
]- get_scheme()[source]¶
Return the
ItemScheme
to which the Item belongs, if any.
- property hierarchical_id¶
Construct the ID of an Item in a hierarchical ItemScheme.
Returns, for example, ‘A.B.C’ for an Item with id ‘C’ that is the child of an item with id ‘B’, which is the child of a root Item with id ‘A’.
See also
- parent: IT | ItemScheme | None¶
- class pandasdmx.model.ItemScheme(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, is_partial: bool | None = None, items: ~typing.Dict[str, ~pandasdmx.model.IT] = {})[source]¶
Bases:
MaintainableArtefact
,Generic
[IT
]SDMX-IM Item Scheme.
The IM states that ItemScheme “defines a set of
Items
…” To simplify indexing/retrieval, this implementation uses adict
for theitems
attribute, in which the keys are theid
of the Item.Because this may change in future versions of pandaSDMX, user code should not access
items
directly. Instead, use thegetattr()
and indexing features of ItemScheme, or the public methods, to access and manipulate Items:>>> foo = ItemScheme(id='foo') >>> bar = Item(id='bar') >>> foo.append(bar) >>> foo <ItemScheme: 'foo', 1 items> >>> (foo.bar is bar) and (foo['bar'] is bar) and (bar in foo) True
- append(item: IT)[source]¶
Add item to the ItemScheme.
- Parameters:
item (same class as
items
) – Item to add.
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two ItemSchemes are the same if:
MaintainableArtefact.compare()
isTrue
, andtheir
items
have the same keys, and correspondingItems
compare equal.
- Parameters:
strict (bool, optional) – Passed to
compare()
andMaintainableArtefact.compare()
.
- get_hierarchical(id: str) IT [source]¶
Get an Item by its
hierarchical_id
.
- class pandasdmx.model.Key(arg: Mapping | Sequence[KeyValue] = None, *, attrib: DictLike[str, AttributeValue] = None, described_by: DimensionDescriptor | None = None, values: DictLike[str, KeyValue] = None)[source]¶
Bases:
BaseModel
SDMX Key class.
The constructor takes an optional list of keyword arguments; the keywords are used as Dimension or Attribute IDs, and the values as KeyValues.
For convience, the values of the key may be accessed directly:
>>> k = Key(foo=1, bar=2) >>> k.values['foo'] 1 >>> k['foo'] 1
- Parameters:
dsd (DataStructureDefinition) – If supplied, the
dimensions
andattributes
are used to separate the kwargs intoKeyValues
andAttributeValues
. The kwargs fordescribed_by
, if any, must bedimensions
or appear ingroup_dimensions
.kwargs – Dimension and Attribute IDs, and/or the class properties.
- attrib: DictLike[str, AttributeValue]¶
- copy(arg=None, **kwargs)[source]¶
Duplicate a model, optionally choose which fields to include, exclude and change.
- Parameters:
include – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data
deep – set to True to make a deep copy of the model
- Returns:
new model instance
- described_by: DimensionDescriptor | None¶
- class pandasdmx.model.KeyValue(*args, id: str, value: Any = None, value_for: Dimension | None = None)[source]¶
Bases:
BaseModel
One value in a multi-dimensional
Key
.
- class pandasdmx.model.MaintainableArtefact(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None)[source]¶
Bases:
VersionableArtefact
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two MaintainableArtefacts are the same if:
VersionableArtefact.compare()
isTrue
, andthey have the same
maintainer
.
- Parameters:
strict (bool, optional) – Passed to
compare()
andVersionableArtefact.compare()
.
- is_external_reference: bool | None¶
True
if the content of the object is held externally; i.e., not the currentMessage
.
- class pandasdmx.model.MeasureDescriptor(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, components: List[CT] = [], auto_order: int = 1)[source]¶
Bases:
ComponentList
[PrimaryMeasure
]
- class pandasdmx.model.MeasureDimension(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, concept_identity: Concept | None = None, local_representation: Representation | None = None, order: int | None = None)[source]¶
Bases:
DimensionComponent
SDMX-IM MeasureDimension.
- class pandasdmx.model.MemberSelection(*, included: bool = True, values_for: Component, values: List[SelectionValue] = [])[source]¶
Bases:
BaseModel
- values: List[SelectionValue]¶
Value(s) included in the selection. Note that the name of this attribute is not stated in the IM, so ‘values’ is chosen for the implementation in this package.
- class pandasdmx.model.MemberValue(*, value: str, cascade_values: bool | None = None)[source]¶
Bases:
SelectionValue
- class pandasdmx.model.NameableArtefact(*args, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =)[source]¶
Bases:
IdentifiableArtefact
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two NameableArtefacts are the same if:
IdentifiableArtefact.compare()
isTrue
, andthey have the same
name
anddescription
.
- Parameters:
strict (bool, optional) – Passed to
compare()
andIdentifiableArtefact.compare()
.
- description: InternationalString¶
Multi-lingual description of the object.
- name: InternationalString¶
Multi-lingual name of the object.
- class pandasdmx.model.Observation(*, attached_attribute: DictLike[str, AttributeValue] = None, series_key: SeriesKey | None = None, dimension: Key | None = None, value: Any | Code | None = None, value_for: PrimaryMeasure | None = None, group_keys: Set[GroupKey] = {})[source]¶
Bases:
BaseModel
SDMX-IM Observation.
This class also implements the spec classes ObservationValue, UncodedObservationValue, and CodedObservation.
- attached_attribute: DictLike[str, AttributeValue]¶
- property attrib¶
Return a view of combined observation, series & group attributes.
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two Observations are equal if:
their
dimension
,value
,series_key
, andvalue_for
are all equal,their corresponding
attached_attribute
andgroup_keys
are all equal.
- property dim¶
- property key¶
Return the entire key, including KeyValues at the series level.
- value_for: PrimaryMeasure | None¶
- class pandasdmx.model.Organisation(*args, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, parent: ~pandasdmx.model.IT | ItemScheme | None = None, child: ~typing.List[~pandasdmx.model.IT] = [], contact: ~typing.List[~pandasdmx.model.Contact] = [])[source]¶
Bases:
Item
[Organisation
]
- class pandasdmx.model.OrganisationScheme[source]¶
Bases:
object
SDMX-IM abstract OrganisationScheme.
- pandasdmx.model.PACKAGE = {<class 'pandasdmx.model.DataProviderScheme'>: 'base', <class 'pandasdmx.model.DataProvider'>: 'base', <class 'pandasdmx.model.Agency'>: 'base', <class 'pandasdmx.model.AgencyScheme'>: 'base', <class 'pandasdmx.model.Categorisation'>: 'categoryscheme', <class 'pandasdmx.model.CategoryScheme'>: 'categoryscheme', <class 'pandasdmx.model.Category'>: 'categoryscheme', <class 'pandasdmx.model.Code'>: 'codelist', <class 'pandasdmx.model.Codelist'>: 'codelist', <class 'pandasdmx.model.ConceptScheme'>: 'conceptscheme', <class 'pandasdmx.model.Concept'>: 'conceptscheme', <class 'pandasdmx.model.StructureUsage'>: 'datastructure', <class 'pandasdmx.model.DataflowDefinition'>: 'datastructure', <class 'pandasdmx.model.DataStructureDefinition'>: 'datastructure', <class 'pandasdmx.model.ProvisionAgreement'>: 'registry', <class 'pandasdmx.model.ContentConstraint'>: 'registry'}¶
The SDMX-IM defines ‘packages’; these are used in URNs.
- class pandasdmx.model.PrimaryMeasure(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, concept_identity: Concept | None = None, local_representation: Representation | None = None)[source]¶
Bases:
Component
SDMX-IM PrimaryMeasure.
- class pandasdmx.model.ProvisionAgreement(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, structure_usage: ~pandasdmx.model.StructureUsage | None = None, data_provider: ~pandasdmx.model.DataProvider | None = None)[source]¶
Bases:
MaintainableArtefact
,ConstrainableArtefact
- data_provider: DataProvider | None¶
- structure_usage: StructureUsage | None¶
- class pandasdmx.model.QueryDatasource(*, url: str)[source]¶
Bases:
Datasource
- class pandasdmx.model.RESTDatasource(*, url: str)[source]¶
Bases:
QueryDatasource
- class pandasdmx.model.RangePeriod(*, start: Period, end: Period)[source]¶
Bases:
TimeRangeValue
- class pandasdmx.model.ReportingYearStartDay(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, concept_identity: Concept | None = None, local_representation: Representation | None = None, related_to: AttributeRelationship | None = None, usage_status: UsageStatus | None = None)[source]¶
Bases:
DataAttribute
- class pandasdmx.model.Representation(*, enumerated: ItemScheme | None = None, non_enumerated: List[Facet] = [])[source]¶
Bases:
BaseModel
- enumerated: ItemScheme | None¶
- class pandasdmx.model.SeriesKey(arg: Mapping | Sequence[KeyValue] = None, *, attrib: DictLike[str, AttributeValue] = None, described_by: DimensionDescriptor | None = None, values: DictLike[str, KeyValue] = None, group_keys: Set[GroupKey] = {})[source]¶
Bases:
Key
- property group_attrib¶
Return a view of combined group attributes.
- class pandasdmx.model.SimpleDatasource(*, url: str)[source]¶
Bases:
Datasource
- class pandasdmx.model.Structure(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, grouping: ~pandasdmx.model.ComponentList | None = None)[source]¶
Bases:
MaintainableArtefact
- grouping: ComponentList | None¶
- class pandasdmx.model.StructureSpecificDataSet(*, annotations: List[Annotation] = [], action: ActionType | None = None, attrib: DictLike[str, AttributeValue] = None, valid_from: str | None = None, described_by: DataflowDefinition | None = None, structured_by: DataStructureDefinition | None = None, obs: List[Observation] = [], series: DictLike[SeriesKey, List[Observation]] = None, group: DictLike[GroupKey, List[Observation]] = None)[source]¶
Bases:
DataSet
SDMX-IM StructureSpecificDataSet.
- class pandasdmx.model.StructureSpecificTimeSeriesDataSet(*, annotations: List[Annotation] = [], action: ActionType | None = None, attrib: DictLike[str, AttributeValue] = None, valid_from: str | None = None, described_by: DataflowDefinition | None = None, structured_by: DataStructureDefinition | None = None, obs: List[Observation] = [], series: DictLike[SeriesKey, List[Observation]] = None, group: DictLike[GroupKey, List[Observation]] = None)[source]¶
Bases:
DataSet
SDMX-IM StructureSpecificTimeSeriesDataSet.
- class pandasdmx.model.StructureUsage(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None, is_final: bool | None = None, is_external_reference: bool | None = None, service_url: str | None = None, structure_url: str | None = None, maintainer: Agency | None = None, structure: ~pandasdmx.model.Structure | None = None)[source]¶
Bases:
MaintainableArtefact
- class pandasdmx.model.TimeDimension(*args, annotations: List[Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: Dict = {}, concept_identity: Concept | None = None, local_representation: Representation | None = None, order: int | None = None)[source]¶
Bases:
DimensionComponent
SDMX-IM TimeDimension.
- class pandasdmx.model.TimeRangeValue[source]¶
Bases:
SelectionValue
SDMX-IM TimeRangeValue.
- class pandasdmx.model.UsageStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
Enum
- conditional = 2¶
- mandatory = 1¶
- class pandasdmx.model.ValidationLevels(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
Enum
- sloppy = 2¶
- strict = 1¶
- class pandasdmx.model.VersionableArtefact(*, annotations: ~typing.List[~pandasdmx.model.Annotation] = [], id: str = '', uri: str | None = None, urn: str | None = None, urn_group: ~typing.Dict = {}, name: ~pandasdmx.model.InternationalString =, description: ~pandasdmx.model.InternationalString =, version: str | None = None, valid_from: str | None = None, valid_to: str | None = None)[source]¶
Bases:
NameableArtefact
- compare(other, strict=True)[source]¶
Return
True
if self is the same as other.Two VersionableArtefacts are the same if:
NameableArtefact.compare()
isTrue
, andthey have the same
version
.
- Parameters:
strict (bool, optional) – Passed to
compare()
andNameableArtefact.compare()
.
- pandasdmx.model.get_class(name: str | Resource, package=None) Type | None [source]¶
Return a class for name and (optional) package names.
- pandasdmx.model.parent_class(cls)[source]¶
Return the class that contains objects of type cls.
E.g. if cls is
PrimaryMeasure
, returnsMeasureDescriptor
.
reader
: Parsers for SDMX file formats¶
SDMX-ML¶
pandasdmx
supports the several types of SDMXML messages.
- class pandasdmx.reader.sdmxml.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.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.
- static get_schema_dir()[source]¶
Calls BaseReader.get_schema_dir() to get the user’s appdata dir. Appends reader-specific subdirs.
- get_single(cls_or_name: Type | str, id: str = None, subclass: bool = False) Any | None [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: Type | str)[source]¶
Get the object at the top of stack cls_or_name without removing it.
- pop_all(cls_or_name: 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_single(cls_or_name: Type | str)[source]¶
Pop a single object from the stack for cls_or_name and return.
- read_message(source, dsd: DataStructureDefinition = None) 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 pandasdmx.reader.sdmxjson.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¶
- pandasdmx.reader.READERS = [<class 'pandasdmx.reader.sdmxjson.Reader'>, <class 'pandasdmx.reader.sdmxml.Reader'>]¶
Reader classes
- pandasdmx.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.
- pandasdmx.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
- pandasdmx.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
- pandasdmx.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. A given file-like object is closed after loading.
- Parameters:
filename_or_obj (str or
PathLike
) – or open binary file. A file is not closed explicitly. So it should be passed from a with-context.format ('XML' or 'JSON', optional) –
dsd (
DataStructureDefinition
) – For “structure-specific” format`=``XML` messages only.
- class pandasdmx.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:
writer
: Convert sdmx
objects to other formats¶
writer.pandas
: Convert to pandas
objects¶
Changed in version 1.0: sdmx.to_pandas()
handles all types of objects, replacing the earlier, separate data2pandas
and structure2pd
writers.
to_pandas()
implements a dispatch pattern according to the type of obj.
Some of the internal methods take specific arguments and return varying values.
These arguments can be passed to to_pandas()
when obj is of the appropriate type:
|
Convert |
Convert |
|
Convert |
|
Convert |
|
Default return type for |
Other objects are converted as follows:
Component
The
id
attribute of theconcept_identity
is returned.DataMessage
The
DataSet
or data sets within the Message are converted to pandas objects. Returns:pandas.Series
orpandas.DataFrame
, if obj has only one data set.list of (Series or DataFrame), if obj has more than one data set.
dict
The values of the mapping are converted individually. If the resulting values are
str
or Series with indexes that share the same name, then they are converted to a Series, possibly with apandas.MultiIndex
. Otherwise, aDictLike
is returned.DimensionDescriptor
The
components
of the DimensionDescriptor are written.list
For the following obj, returns Series instead of a
list
:a list of
Observation
: the Observations are written usingwrite_dataset()
.a list with only 1
DataSet
(e.g. thedata
attribute ofDataMessage
): the Series for the single element is returned.a list of
SeriesKey
: the key values (but no data) are returned.
NameableArtefact
The
name
attribute of obj is returned.
- pandasdmx.writer.pandas.DEFAULT_RTYPE = 'rows'¶
Default return type for
write_dataset()
and similar methods. Either ‘compat’ or ‘rows’. See the ref:HOWTO <howto-rtype>.
- pandasdmx.writer.pandas.write_datamessage(obj: DataMessage, *args, rtype=None, **kwargs)[source]¶
Convert
DataMessage
.- Parameters:
rtype ('compat' or 'rows', optional) – Data type to return; default
DEFAULT_RTYPE
. See the HOWTO.kwargs – Passed to
write_dataset()
for each data set.
- Returns:
pandas.Series
orpandas.DataFrame
– if obj has only one data set.list of (
pandas.Series
orpandas.DataFrame
) – if obj has more than one data set.
- pandasdmx.writer.pandas.write_dataset(obj: ~pandasdmx.model.DataSet, attributes='', dtype=<class 'numpy.float64'>, constraint=None, datetime=False, dtypes_from_dsd=False, **kwargs)[source]¶
Convert
DataSet
.See the walkthrough for examples of using the datetime argument.
- Parameters:
obj (
DataSet
or iterable ofObservation
) –attributes (str) –
Types of attributes to return with the data. A string containing zero or more of:
'o'
: attributes attached to eachObservation
.'s'
: attributes attached to any (0 or 1)SeriesKey
associated with each Observation.'g'
: attributes attached to any (0 or more)GroupKey
associated with each Observation.'d'
: attributes attached to theDataSet
containing the Observations.
dtype (str or
numpy.dtype
or None) – Datatype for values. If None, do not return the values of a series. In this case, attributes must not be an empty string so that some attribute is returned.constraint (.ContentConstraint, optional) – If given, only Observations included by the constraint are returned.
datetime (bool or str or .Dimension or dict, optional) –
If given, return a DataFrame with a
DatetimeIndex
orPeriodIndex
as the index and all other dimensions as columns. Valid datetime values include:bool
: ifTrue
, determine the time dimension automatically by detecting aTimeDimension
.str
: ID of the time dimension.Dimension
: the matching Dimension is the time dimension.dict
: advanced behaviour. Keys may include:axis ({0 or ‘index’, 1 or ‘columns’}): axis on which to place the time dimension (default: 0).
freq (
True
orstr
orDimension
): producepandas.PeriodIndex
. Ifstr
, the ID of a Dimension containing a frequency specification. If a Dimension, the specified dimension is used for the frequency specification.Any Dimension used for the frequency specification does not appear in the returned DataFrame.
- Returns:
-
if attributes is not
''
, a data frame with one row per Observation,value
as the first column, and additional columns for each attribute;if datetime is given, various layouts as described above; or
if _rtype (passed from
write_datamessage()
) is ‘compat’, various layouts as described in the HOWTO.
pandas.Series
withpandas.MultiIndex
– Otherwise.
-
- pandasdmx.writer.pandas.write_itemscheme(obj: ItemScheme, locale='en')[source]¶
Convert
ItemScheme
.- Parameters:
locale (str, optional) – Locale for names to return.
- Return type:
- pandasdmx.writer.pandas.write_structuremessage(obj: StructureMessage, include=None, **kwargs)[source]¶
Convert
StructureMessage
.- Parameters:
- Returns:
Keys are StructureMessage attributes; values are pandas objects.
- Return type:
.DictLike
Todo
Support selection of language for conversion of
InternationalString
.
writer.xml
: Write to pandasdmx.ML¶
New in version 1.1.
See to_xml()
.
remote
: Access pandasdmx.REST web services¶
- class pandasdmx.remote.Session(proxies=None, stream=False, auth=None, cert=None, verify=True, **kwargs)[source]¶
requests.Session
subclass with optional caching.If requests_cache is installed, this class caches responses.
- class pandasdmx.remote.ResponseIO(response, tee=None)[source]¶
Buffered wrapper for
requests.Response
with optional file output.ResponseIO
wraps arequests.Response
object’s ‘content’ attribute, providing a file-like object from which bytes can beread()
incrementally.- Parameters:
response (
requests.Response
) – HTTP response to wrap.tee (binary, writable
io.BufferedIOBase
, orfsspec.core.OpenFile
) – orio.PathLike
, defaults to io.BytesIO. If tee is an open binary file, it is used to store the received data. If tee is a PathLike, it is passed toopen()
, . tee is exposed as self.tee and not closed, so this class may be instantiated in a with-context. The latter is also recommended if afsspec.core.OpenFile
is passed.
source
: Features of pandasdmx.data sources¶
This module defines Source
and some utility functions.
For built-in subclasses of Source used to provide sdmx
’s built-in support
for certain data sources, see Data sources.
- class pandasdmx.source.Source(*, id: str, api_id: str | None = None, url: HttpUrl | None = None, name: str, documentation: HttpUrl | None = None, headers: Dict[str, Any] = {}, resource_urls: Dict[str, HttpUrl] = {}, default_version: str = 'latest', data_content_type: DataContentType = DataContentType.XML, supports: Dict[str | Resource, bool] = {Resource.data: True})[source]¶
SDMX-IM RESTDatasource.
This class describes the location and features supported by an SDMX data source. Subclasses may override the hooks in order to handle specific features of different REST web services:
handle_response
(response, content)Handle response content of unknown type.
finish_message
(message, request, **kwargs)Postprocess retrieved message.
modify_request_args
(kwargs)Modify arguments used to build query URL.
- data_content_type: DataContentType¶
DataContentType
indicating the type of data returned by the source.
- finish_message(message, request, **kwargs)[source]¶
Postprocess retrieved message.
This hook is called by
Request.get()
after aMessage
object has been successfully parsed from the query response.See
estat.Source.finish_message()
for an example implementation.
- handle_response(response, content)[source]¶
Handle response content of unknown type.
This hook is called by
Request.get()
only when the content cannot be parsed as XML or JSON.See
estat.Source.handle_response()
andsgr.Source.handle_response()
for example implementations.
- modify_request_args(kwargs)[source]¶
Modify arguments used to build query URL.
This hook is called by
Request.get()
to modify the keyword arguments before the query URL is built.The default implementation handles requests for ‘structure-specific data’ by adding an HTTP ‘Accepts:’ header when a ‘dsd’ is supplied as one of the kwargs.
See
sgr.Source.modify_request_args()
for an example override.- Return type:
None
- supports: Dict[str | Resource, bool]¶
Mapping from
Resource
tobool
indicating support for SDMX REST API features. Two additional keys are valid:'preview'=True
if the source supports?detail=serieskeysonly
. Seepreview_data()
.'structure-specific data'=True
if the source can return structure- specific data messages.
- pandasdmx.source.add_source(info, id=None, override=False, **kwargs)[source]¶
Add a new data source.
The info expected is in JSON format:
{ "id": "ESTAT", "documentation": "http://data.un.org/Host.aspx?Content=API", "url": "http://ec.europa.eu/eurostat/SDMX/diss-web/rest", "name": "Eurostat", "supported": {"codelist": false, "preview": true} }
…with unspecified values using the defaults; see
Source
.- Parameters:
info (dict-like) – String containing JSON information about a data source.
id (str) – Identifier for the new datasource. If
None
(default), then info[‘id’] is used.override (bool) – If
True
, replace any existing data source with id. Otherwise, raiseValueError
.**kwargs – Optional callbacks for handle_response and finish_message hooks.
util
: Utilities¶
- class pandasdmx.util.BaseModel[source]¶
Bases:
BaseModel
Common settings for
pydantic.BaseModel
inpandasdmx
.
- class pandasdmx.util.DictLike(*args, **kwargs)[source]¶
Bases:
dict
,MutableMapping
[KT
,VT
]Container with features of a dict & list, plus attribute access.
- pandasdmx.util.compare(attr, a, b, strict: bool) bool [source]¶
Return
True
ifa.attr
==b.attr
.If strict is
False
,None
is permissible as a or b; otherwise,
- pandasdmx.util.dictlike_field()[source]¶
Shorthand for
pydantic.Field
withDictLike
default factory.
- pandasdmx.util.summarize_dictlike(dl, maxwidth=72)[source]¶
Return a string summary of the DictLike contents.
- pandasdmx.util.validate_dictlike(cls)[source]¶
Adjust cls so that its DictLike members are validated.
This is necessary because DictLike is a subclass of
dict
, and sopydantic
fails to call__get_validators__()
and register those on BaseModels which include DictLike members.
- pandasdmx.util.validator(*fields: unicode, pre: bool = False, each_item: bool = False, always: bool = False, check_fields: bool = True, whole: bool = None, allow_reuse: bool = False) Callable[[Callable[[...], Any]], AnyClassMethod] ¶
Decorate methods on the class indicating that they should be used to validate fields :param fields: which field(s) the method should be called on :param pre: whether or not this validator should be called before the standard validators (else after) :param each_item: for complex objects (sets, lists etc.) whether to validate individual elements rather than the
whole object
- Parameters:
always – whether this method and other validators should be called even if the value is missing
check_fields – whether to check that the fields actually exist on the model
allow_reuse – whether to track and raise an error if another validator refers to the decorated function