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:

  1. 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.

  2. a resource object, i.e. a MaintainableArtefact: resource_type and resource_id are determined by the object’s class and id 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:

  1. {'GEO': ['EL', 'ES', 'IE']}: dict with dimension name(s) mapped to an iterable of allowable values.

  2. {'GEO': 'EL+ES+IE'}: dict with dimension name(s) mapped to strings joining allowable values with ‘+’, the logical ‘or’ operator for SDMX web services.

  3. '....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 retrieved Message from cache, or update the cache with a newly-retrieved Message.

dry_runbool, optional

If True, prepare and return a requests.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:

dsdDataStructureDefinition

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 the source 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 the source.

keystr or dict

For queries with resource_type=’data’. str values are not validated; dict values are validated using make_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.

resourceMaintainableArtefact 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:

Message or Request

The requested SDMX message or, if dry_run is True, the prepared request object.

Raises:

NotImplementedError

If the source does not support the given resource_type and force is not True.

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 corresponding Observations.

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

series_keys(flow_id, use_cache=True)[source]

Return all SeriesKey for flow_id.

Returns

list

session = None

Session for queries sent from the instance.

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.

view_doc()[source]

Open documentation website of the data source, if given, in a new browser tab. Otherwise, raise RuntimeError.

class pandasdmx.Resource(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Enumeration of SDMX-REST API resources.

Enum member

pandasdmx.model class

actualconstraint

ContentConstraint

agencyscheme

AgencyScheme

allowedconstraint

ContentConstraint

attachementconstraint

AttachmentConstraint

categorisation

Categorisation

categoryscheme

CategoryScheme

codelist

Codelist

conceptscheme

ConceptScheme

contentconstraint

ContentConstraint

data

DataSet

dataflow

DataflowDefinition

dataconsumerscheme

DataConsumerScheme

dataproviderscheme

DataProviderScheme

datastructure

DataStructureDefinition

organisationscheme

OrganisationScheme

provisionagreement

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.

classmethod from_obj(obj)[source]

Return an enumeration value based on the class of obj.

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, raise ValueError.

  • **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.read_url(url, **kwargs)[source]

Request a URL directly.

pandasdmx.to_pandas(obj, *args, **kwargs)[source]

Convert an SDMX obj to pandas object(s).

See pandasdmx.writer.pandas.

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 to sys.stderr. These include the web service query details (URL and headers) used by Request.

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, so data 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:

Parameters:

strict (bool, optional) – Passed to compare().

data: List[DataSet]

list of DataSet.

dataflow: DataflowDefinition

DataflowDefinition that contains the data.

observation_dimension: _AllDimensions | DimensionComponent | List[DimensionComponent] | None

The “dimension at observation level”.

property structure

DataStructureDefinition used in the dataflow.

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

class pandasdmx.message.Footer(*, severity: str | None = None, text: List[InternationalString] = [], code: int | None = None)[source]

Bases: BaseModel

Footer of an SDMX-ML message.

SDMX-JSON messages do not have footers.

code: int | None
compare(other, strict=True)[source]

Return True if self is the same as other.

Two Footers are the same if their code, severity, and text are equal.

Parameters:

strict (bool, optional) – Passed to compare().

severity: str | None
text: List[InternationalString]

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.

Parameters:

strict (bool, optional) – Passed to compare().

error: str | None

(optional) Error code for the message.

extracted: datetime | None

Date and time at which the data was extracted.

id: str | None

Identifier for the message.

prepared: datetime | None

Date and time at which the message was generated.

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.

sender: Agency | None

The Agency associated with the data Source.

source: InternationalString
test: bool
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

class Config[source]

Bases: object

arbitrary_types_allowed = True
compare(other, strict=True)[source]

Return True if self is the same as other.

Two Messages are the same if their header and footer compare equal.

Parameters:

strict (bool, optional) – Passed to compare().

footer: Footer | None

(optional) Footer instance.

header: Header

Header 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.

sdmx_schema_location: str | None
to_pandas(*args, **kwargs)[source]

Convert a Message instance to pandas object(s).

pandasdmx.writer.write() is called and passed the Message instance as first argument, followed by any args and kwargs.

See also

write()

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.

codelist: DictLike[str, Codelist]

Collection of Codelist.

compare(other, strict=True)[source]

Return True if self is the same as other.

Two StructureMessages compare equal if DictLike.compare() is True 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; if str, 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 to structure.

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:

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

id: str | None

Can be used to disambiguate multiple annotations for one AnnotableArtefact.

text: InternationalString

Content of the annotation.

title: str | None

Title, used to identify an annotation.

type: str | None

Specifies how the annotation is processed.

url: str | None

A link to external descriptive text.

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.AttributeRelationship[source]

Bases: BaseModel

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.

Parameters:

strict (bool, optional) – Passed to compare().

start_date: date | None
value: str | Code
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
category: Category | 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]

Bases: Item[Category]

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]

Bases: Item[Code]

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

concept_identity: Concept | None
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:

Parameters:

strict (bool, optional) – Passed to compare() and IdentifiableArtefact.compare().

components: List[CT]
get(id) CT[source]

Return the component with the given id.

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 of auto_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 if components is overridden in a subclass of ComponentList.

class pandasdmx.model.ComponentValue(*, value_for: Component, value: Any = None)[source]

Bases: BaseModel

value: Any
value_for: Component
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]

Bases: Item[Concept]

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

class Config[source]

Bases: object

validate_assignment = False
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.

email: List[str]
name: InternationalString
org_unit: InternationalString
responsibility: InternationalString
telephone: str | None
uri: List[str]
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.

iter_keys(obj: DataStructureDefinition | DataflowDefinition, dims: List[str] = []) Generator[Key, None, None][source]

Iterate over keys.

A warning is logged if obj is not already explicitly associated to this ContentConstraint, i.e. present in content.

to_query_string(structure)[source]
class pandasdmx.model.CubeRegion(*, included: bool = True, member: Dict[Dimension, MemberSelection] = {})[source]

Bases: BaseModel

included: bool
member: Dict[Dimension, MemberSelection]
to_query_string(structure)[source]
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

related_to: AttributeRelationship | None
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

included: bool
key_value: Dict[Component, ComponentValue]

Mapping from Component to ComponentValue comprising the key.

class pandasdmx.model.DataKeySet(*, included: bool, keys: List[DataKey] = [])[source]

Bases: BaseModel

included: bool

True if the keys are included in the Constraint; False if they are excluded.

keys: List[DataKey]

DataKeys appearing in the set.

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.

Parameters:

strict (bool, optional) – Passed to compare().

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
valid_from: str | 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, and group_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 new Concepts and Codelists, created to represent all the values observed across keys for each dimension.

Parameters:

keys (iterable of Key) – or of subclasses such as SeriesKey or GroupKey.

group_dimensions: DictLike[str, GroupDimensionDescriptor]

Mapping from GroupDimensionDescriptor.id to GroupDimensionDescriptor.

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’s dimensions, and

  • values are ‘+’-delimited str containing allowable values, or iterables of str, 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 its data_content_region , including only the values appearing in key.

Return type:

ContentConstraint

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:
Returns:

An instance of key_cls.

Return type:

Key

Raises:

KeyError – If any of the keys of values is not a Dimension or Attribute in the DSD.

measures: MeasureDescriptor

A 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.

structure: DataStructureDefinition
class pandasdmx.model.Datasource(*, url: str)[source]

Bases: BaseModel

url: str
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

order: int | None
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 a list (ordered) of Dimension, MeasureDimension, and/or TimeDimension.

assign_order()[source]

Assign the DimensionComponent.order attribute.

The Dimensions in components are numbered, starting from 1.

classmethod from_key(key)[source]

Create a new DimensionDescriptor from a key.

For each KeyValue in the key:

Parameters:

key (Key or GroupKey or SeriesKey) –

order_key(key)[source]

Return a key ordered according to the DSD.

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

class Config[source]

Bases: object

extra = 'forbid'
type: FacetType
value: str | None
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 Config[source]

Bases: object

extra = 'forbid'
decimals: int | None
end_time: datetime | None
end_value: str | None
interval: float | None
is_sequence: bool | None
max_length: int | None
max_value: float | None
min_length: int | None
min_value: float | None
pattern: str | None
start_time: datetime | None
start_value: float | None
time_interval: timedelta | None
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.

attachment_constraint: bool | None
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
id: str | 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 Config[source]

Bases: object

extra = 'forbid'
agency: str
id: str
scheme_id: str
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, and urn.

Parameters:

strict (bool, optional) – Passed to compare().

id: str

Unique identifier of the object.

uri: str | None

Universal resource identifier that may or may not be resolvable.

urn: str | None

Universal resource name. For use in SDMX registries; all registered objects have a URN.

urn_group: Dict
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.

localizations: Dict[str, str] = {}
localized_default(locale=None)[source]

Return the string in locale if not empty, or else the first defined.

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]

append_child(other: IT)[source]
child: List[IT]
get_child(id) IT[source]

Return the child with the given id.

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’.

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 a dict for the items attribute, in which the keys are the id of the Item.

Because this may change in future versions of pandaSDMX, user code should not access items directly. Instead, use the getattr() 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:

Parameters:

strict (bool, optional) – Passed to compare() and MaintainableArtefact.compare().

classmethod convert_to_dict(v)[source]
extend(items: Iterable[IT])[source]

Extend the ItemScheme with members of items.

Parameters:

items (iterable of Item) – Elements must be of the same class as items.

get_hierarchical(id: str) IT[source]

Get an Item by its hierarchical_id.

is_partial: bool | None
items: Dict[str, IT]

Members of the ItemScheme. Both ItemScheme and Item are abstract classes. Concrete classes are paired: for example, a Codelist contains Codes.

setdefault(obj=None, **kwargs) IT[source]

Retrieve the item name, or add it with kwargs and return it.

The returned object is a reference to an object in the ItemScheme, and is of the appropriate class.

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:
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
get_values()[source]
order(value=None)[source]
values: DictLike[str, KeyValue]

Individual KeyValues that describe the key.

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.

id: str
value: Any

The actual value.

value_for: Dimension | None
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:

Parameters:

strict (bool, optional) – Passed to compare() and VersionableArtefact.compare().

is_external_reference: bool | None

True if the content of the object is held externally; i.e., not the current Message.

is_final: bool | None

True if the object is final; otherwise it is in a draft state.

maintainer: Agency | None

Association to the Agency responsible for maintaining the object.

service_url: str | None

URL of an SDMX-compliant web service from which the object can be retrieved.

structure_url: str | None

URL of an SDMX-ML document containing the object.

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

included: bool
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.

values_for: Component
class pandasdmx.model.MemberValue(*, value: str, cascade_values: bool | None = None)[source]

Bases: SelectionValue

cascade_values: bool | None
value: str
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:

Parameters:

strict (bool, optional) – Passed to compare() and IdentifiableArtefact.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:

Parameters:

strict (bool, optional) – Passed to compare().

property dim
dimension: Key | None

Key for dimension(s) varying at the observation level.

group_keys: Set[GroupKey]

sdmx extension not in the IM.

property key

Return the entire key, including KeyValues at the series level.

series_key: SeriesKey | None
value: Any | Code | None

Data value.

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]

contact: List[Contact]
class pandasdmx.model.OrganisationScheme[source]

Bases: object

SDMX-IM abstract OrganisationScheme.

pandasdmx.model.PACKAGE = {<class 'pandasdmx.model.AgencyScheme'>: 'base', <class 'pandasdmx.model.DataProviderScheme'>: 'base', <class 'pandasdmx.model.DataProvider'>: 'base', <class 'pandasdmx.model.Agency'>: '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.Concept'>: 'conceptscheme', <class 'pandasdmx.model.ConceptScheme'>: 'conceptscheme', <class 'pandasdmx.model.DataflowDefinition'>: 'datastructure', <class 'pandasdmx.model.StructureUsage'>: 'datastructure', <class 'pandasdmx.model.DataStructureDefinition'>: 'datastructure', <class 'pandasdmx.model.ContentConstraint'>: 'registry', <class 'pandasdmx.model.ProvisionAgreement'>: 'registry'}

The SDMX-IM defines ‘packages’; these are used in URNs.

class pandasdmx.model.Period(*, is_inclusive: bool, period: datetime)[source]

Bases: BaseModel

is_inclusive: bool
period: datetime
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

end: Period
start: Period
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

class Config[source]

Bases: object

extra = 'forbid'
enumerated: ItemScheme | None
non_enumerated: List[Facet]
class pandasdmx.model.SelectionValue[source]

Bases: BaseModel

SDMX-IM SelectionValue.

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.

group_keys: Set[GroupKey]

sdmx extension not in the IM.

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

structure: Structure | None
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.

pandasdmx.model.TimeKeyValue

alias of KeyValue

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:

Parameters:

strict (bool, optional) – Passed to compare() and NameableArtefact.compare().

valid_from: str | None

Date from which the version is valid.

valid_to: str | None

Date from which the version is superseded.

version: str | None

A version string following an agreed convention.

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, returns MeasureDescriptor.

pandasdmx.model.value_for_dsd_ref(kind, args, kwargs)[source]

Maybe replace a string ‘value_for’ in kwargs with a DSD reference.

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.

classmethod detect(content)[source]

Detect whether the reader can handle content.

Returns:

True if the reader can handle the content.

Return type:

bool

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() calls nameable(), which in turn calls identifiable(), 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 to True. 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_resolved_ref(cls_or_name: Type | str)[source]

Pop a reference to cls_or_name and resolve it.

pop_single(cls_or_name: Type | str)[source]

Pop a single object from the stack for cls_or_name and return.

push(stack_or_obj, obj=None)[source]

Push an object onto a stack.

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:

Message

resolve(ref)[source]

Resolve the Reference instance ref, returning the referred object.

stash(*stacks)[source]

Temporarily hide all objects in the given stacks.

suffixes: List[str] = ['.xml']

List of file name suffixes handled by the reader.

unstash()[source]

Restore the objects hidden by the last stash() call to their stacks.

Calls to stash() and unstash() should be matched 1-to-1; if the latter outnumber the former, this will raise KeyError.

static validate_message(msg, schema_dir=None)[source]

Validate msg against XML schemas. These must be installed first. See the docs on pandasdmx.api.install_schemas() and pandasdmx.api.Request.validate().

Returns whatever lxml.etree.XMLSchema.validate returns

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.

classmethod detect(content)[source]

Detect whether the reader can handle content.

Returns:

True if the reader can handle the content.

Return type:

bool

read_dataset(root, ds_key)[source]
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:

Message

read_obs(root, series_key=None, base_key=None)[source]
suffixes: List[str] = ['.json']

List of file name suffixes handled by the reader.

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 in READERS 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]
content_types: List[str] = []

List of HTTP content types handled by the reader.

classmethod detect(content: bytes) bool[source]

Detect whether the reader can handle content.

Returns:

True if the reader can handle the content.

Return type:

bool

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:

Message

suffixes: List[str] = []

List of file name suffixes handled by the reader.

classmethod supports_content_type(value: str) bool[source]

True if the reader can handle content/media type value.

classmethod supports_suffix(value: str) bool[source]

True if the reader can handle files with suffix value.

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:

pandasdmx.writer.pandas.write_dataset(obj[, ...])

Convert DataSet.

pandasdmx.writer.pandas.write_datamessage(...)

Convert DataMessage.

pandasdmx.writer.pandas.write_itemscheme(obj)

Convert ItemScheme.

pandasdmx.writer.pandas.write_structuremessage(obj)

Convert StructureMessage.

pandasdmx.writer.pandas.DEFAULT_RTYPE

Default return type for write_dataset() and similar methods.

Other objects are converted as follows:

Component

The id attribute of the concept_identity is returned.

DataMessage

The DataSet or data sets within the Message are converted to pandas objects. Returns:

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 a pandas.MultiIndex. Otherwise, a DictLike is returned.

DimensionDescriptor

The components of the DimensionDescriptor are written.

list

For the following obj, returns Series instead of a list:

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:
Returns:

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 of Observation) –

  • attributes (str) –

    Types of attributes to return with the data. A string containing zero or more of:

    • 'o': attributes attached to each Observation .

    • '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 the DataSet 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 or PeriodIndex as the index and all other dimensions as columns. Valid datetime values include:

    • bool: if True, determine the time dimension automatically by detecting a TimeDimension.

    • str: ID of the time dimension.

    • Dimension: the matching Dimension is the time dimension.

    • dict: advanced behaviour. Keys may include:

      • dim (Dimension or str): the time dimension or its ID.

      • axis ({0 or ‘index’, 1 or ‘columns’}): axis on which to place the time dimension (default: 0).

      • freq (True or str or Dimension): produce pandas.PeriodIndex. If str, 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:

  • pandas.DataFrame

    • 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 with pandas.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:

pandas.Series

pandasdmx.writer.pandas.write_structuremessage(obj: StructureMessage, include=None, **kwargs)[source]

Convert StructureMessage.

Parameters:
  • obj (.StructureMessage) –

  • include (iterable of str or str, optional) – One or more of the attributes of the StructureMessage ( ‘category_scheme’, ‘codelist’, etc.) to transform.

  • kwargs – Passed to write() for each attribute.

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 a requests.Response object’s ‘content’ attribute, providing a file-like object from which bytes can be read() incrementally.

Parameters:
  • response (requests.Response) – HTTP response to wrap.

  • tee (binary, writable io.BufferedIOBase, or fsspec.core.OpenFile) – or io.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 to open(), . 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 a fsspec.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.

documentation: HttpUrl | None

documentation URL of the data source

finish_message(message, request, **kwargs)[source]

Postprocess retrieved message.

This hook is called by Request.get() after a Message 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() and sgr.Source.handle_response() for example implementations.

id: str

ID of the data source

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

name: str

Human-readable name of the data source

supports: Dict[str | Resource, bool]

Mapping from Resource to bool indicating support for SDMX REST API features. Two additional keys are valid:

  • 'preview'=True if the source supports ?detail=serieskeysonly. See preview_data().

  • 'structure-specific data'=True if the source can return structure- specific data messages.

url: HttpUrl | None

Base URL for queries

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, raise ValueError.

  • **kwargs – Optional callbacks for handle_response and finish_message hooks.

pandasdmx.source.list_sources()[source]

Return a sorted list of valid source IDs.

These can be used to create Request instances.

pandasdmx.source.load_package_sources()[source]

Discover all sources listed in sources.json.

util: Utilities

class pandasdmx.util.BaseModel[source]

Bases: BaseModel

Common settings for pydantic.BaseModel in pandasdmx.

class Config[source]

Bases: object

copy_on_model_validation = 'none'
validate_assignment = True
class pandasdmx.util.DictLike(*args, **kwargs)[source]

Bases: dict, MutableMapping[KT, VT]

Container with features of a dict & list, plus attribute access.

compare(other, strict=True)[source]

Return True if self is the same as other.

Two DictLike instances are identical if they contain the same set of keys, and corresponding values compare equal.

Parameters:

strict (bool, optional) – Passed to compare() for the values.

copy()[source]

Return a copy of the DictLike.

pandasdmx.util.compare(attr, a, b, strict: bool) bool[source]

Return True if a.attr == b.attr.

If strict is False, None is permissible as a or b; otherwise,

pandasdmx.util.dictlike_field()[source]

Shorthand for pydantic.Field with DictLike default factory.

pandasdmx.util.only(iterator: Iterator) Any[source]

Return the only element of iterator, or None.

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 so pydantic 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