Data sources  数据来源

SDMX distinguishes:  SDMX 区分:

  • a data provider —the original publisher or maintainer of statistical information and metadata.
    数据提供者——统计信息和元数据的原始发布者或维护者。

  • a data source —a specific web service that provides access to SDMX content via a standard API.
    一个数据源——一个特定的 Web 服务,通过标准 API 提供访问 SDMX 内容。

A single data source might aggregate and provide data or metadata from many data providers. Or, an agency might operate a data source that only contains information they provide themselves; in this case, the source and provider are matched one-to-one.
单个数据源可能会聚合并提供来自许多数据提供者的数据或元数据。或者,机构可能会运营一个数据源,该数据源仅包含他们自己提供的信息;在这种情况下,源和提供者是一对一的匹配。

sdmx has built-in support for a number of data sources, each identified with a string such as "ABS". Use list_sources() to list these, or see the file sources.json in the package source code.
sdmx 内置了对多种数据源的支持,每个数据源都用如 "ABS" 这样的字符串标识。使用 list_sources() 列出这些数据源,或者查看软件包源代码中的文件 sources.json

https://khaeru.github.io/sdmx displays a summary of every SDMX-REST API endpoint for every data source known to sdmx; this summary is updated daily by an automatic run of the test suite. Read the following sections, for more details on how the limitations and quirks of particular sources are handled.
https://khaeru.github.io/sdmx 显示每个已知 sdmx 数据源的每个 SDMX-REST API 端点的摘要;此摘要由测试套件的自动运行每日更新。阅读以下部分,了解如何处理特定来源的限制和怪癖。

sdmx also supports adding other data sources; see add_source() and Source.
sdmx 也支持添加其他数据源;请参阅 add_source()Source

Data source limitations
数据源限制

Each SDMX web service provides a subset of the full SDMX feature set, so the same request made to two different sources may yield different results, or an error message. In order to anticipate and handle these differences:
每个 SDMX Web 服务都提供完整 SDMX 功能集的一个子集,因此对两个不同源发出的相同请求可能会产生不同的结果,或者错误消息。为了预测和处理这些差异:

  1. add_source() accepts “data_content_type” and “supported” keys. For example:
    add_source() 接受“data_content_type” 和“supported” 键。例如:

    [
      {
        "id": "ABS",
        "data_content_type": "JSON"
      },
      {
        "id": "UNESCO",
        "supported": {"datastructure": false}
      },
    ]
    

    sdmx will raise NotImplementedError on an attempt to query the “datastructure” API endpoint of either of these data sources.
    sdmx 尝试查询这两个数据源的“datastructure” API 端点时,将引发 NotImplementedError

  2. sdmx.source includes adapters (subclasses of Source) with hooks used when querying sources and interpreting their HTTP responses. These are documented below, e.g. ABS, ESTAT, and SGR.
    sdmx.source 包含适配器( Source 的子类),其中包含在查询源和解释其 HTTP 响应时使用的钩子。这些在下面有文档记录,例如 ABS、ESTAT 和 SGR。

Handling and testing limitations and (un)supported endpoints
处理和测试限制以及(不)支持的端点

As of version 2.5.0, sdmx handles service limitations as follows. Please open an issue if the supported endpoints or behaviour of a particular service appear to have changed.
截至版本 2.5.0, sdmx 处理服务限制如下。如果某个服务的支持端点或行为似乎已更改,请提交一个问题。

  • source.Source.supports lists endpoints/resources that are not supported by any known web service.
    source.Source.supports 列出未被任何已知网络服务支持的终结点/ resources

  • sources.json contains supports: {"[resource]": false} for any endpoint where the service returns an HTTP 404 Not found response code. This means that the service fails to even give a proper 501 response (see below).
    sources.json 包含 supports: {"[resource]": false} ,对于任何服务返回 HTTP 404 未找到响应代码的端点。这意味着该服务甚至无法提供合适的 501 响应(请参阅下文)。

    Client.get() will refuse to query these sources at all, instead raising NotImplementedError. You can override this behaviour by giving force=True as an argument to get().
    Client.get() 将拒绝查询这些来源,而是引发 NotImplementedError 。您可以通过将 force=True 作为 get() 的参数来覆盖此行为。

  • The test suite (test_sources) includes notation of all endpoints for which services return 400 Bad syntax or 501 Not implemented response codes. sdmx will make an actual query to these endpoints, but raise built-in Python exceptions that can be caught and handled by user code:
    测试套件( test_sources )包含所有返回 400 错误语法或 501 未实现响应代码的服务端点的注释。 sdmx 将对这些端点进行实际查询,但会引发可由用户代码捕获和处理的内置 Python 异常:

    • For a 501 response code, NotImplementedError is raised.
      对于 501 响应码, NotImplementedError 被提升。

      This is behaviour fully compliant with the SDMX standard: the service accurately and honestly responds when a client makes a request that the server does not implement.
      这是完全符合 SDMX 标准的行为:当客户端请求服务器未实现的功能时,该服务会准确、诚实地做出回应。

    • For a 400 response code, HTTPError is raised.
      对于 400 响应代码, HTTPError 会被提升。

      Some of these “bad syntax” responses are erroneous: the service actually has a non-standard URL scheme or handling, different from the SDMX-REST standard. The Client is constructing a standards-compliant URL, but the service idiosyncratically rejects it. Handling these idiosyncrasies is currently out-of-scope for sdmx.
      其中一些“语法错误”的响应是错误的:该服务实际上具有非标准的 URL 方案或处理方式,不同于 SDMX-REST 标准。 Client 正在构建符合标准的 URL,但该服务却以特有的方式拒绝了它。目前, sdmx 的范围之外包括处理这些特性。

  • Because of the large number of services and endpoints, this matrix of support is only periodically updated. https://khaeru.github.io/sdmx includes all endpoints known to return a reply, even if the reply is an error message of some sort.
    由于服务和端点数量众多,此支持矩阵仅定期更新。https://khaeru.github.io/sdmx 包含所有已知会返回回复的端点,即使回复是某种类型的错误消息。

SDMX-JSON—only services
SDMX-JSON—仅服务

A key difference is between sources offering SDMX-ML and SDMX-JSON content. Although the SDMX-JSON 2.0 format (corresponding to SDMX 3.0) includes structure messages, many web services that return SDMX-JSON still do not provide such content or support structure queries; only data queries. The SDMX-REST standard specifies how services should respond to the HTTP Accepts: header and return either SDMX-ML or SDMX-JSON, but implementation of this feature is inconsistent across known sources.
关键区别在于提供 SDMX-ML 和 SDMX-JSON 内容的来源。尽管 SDMX-JSON 2.0 格式(对应于 SDMX 3.0)包含结构消息,但许多返回 SDMX-JSON 的 Web 服务仍然不提供此类内容或不支持结构查询;仅支持数据查询。SDMX-REST 标准规定了服务应如何响应 HTTP Accepts: 头并返回 SDMX-ML 或 SDMX-JSON,但已知来源对此功能的实现并不一致。

Where data structures are not available, sdmx cannot automatically construct keys. For such services, start by browsing the source’s website to identify a dataflow of interest. Then identify the key format and construct a key for the desired data request.
如果数据结构不可用, sdmx 无法自动构造键。对于此类服务,请先浏览源网站,识别感兴趣的数据流。然后确定键的格式并为所需的数据请求构造键。

ABS: Australian Bureau of Statistics (SDMX-ML)
澳大利亚统计局 (SDMX-ML)

SDMX-ML — Website  SDMX-ML — 网站

Added in version 2.10.0.  2.10.0 版本新增。

ABS_JSON: Australian Bureau of Statistics (SDMX-JSON)
澳大利亚统计局 (SDMX-JSON)

SDMX-JSON — Website  SDMX-JSON — 网站

class sdmx.source.abs_json.Source
sdmx.source.abs_json.Source
[source]  [源]

BBK: German Federal Bank
BBK :德国联邦银行

SDMX-ML — Website (en), (de)
SDMX-ML — 网站 (en),(de)

Added in version 2.5.0.  2.5.0 版本新增。

  • German name: Deutsche Bundesbank
    德国央行

  • The web service has some non-standard behaviour; see #82.
    该 Web 服务有一些非标准行为;请参阅 #82。

  • The version path component is not-supported for non-data endpoints. sdmx discards other values with a warning.
    非数据端点不支持版本路径组件。 sdmx 会丢弃其他值并发出警告。

  • Some endpoints, including codelist, return malformed URNs and cannot be handled with sdmx.
    某些端点,包括 codelist ,返回格式错误的 URN,无法使用 sdmx 处理。

class sdmx.source.bbk.Source
sdmx.source.bbk.Source
[source]  [源]

Work around non-standard behaviour of the BBK: German Federal Bank web service.
规避 BBK(德国联邦银行)网络服务的非标准行为。

modify_request_args(kwargs)
修改请求参数(kwargs)
[source]  [源]

Modify arguments used to build query URL.
修改用于构建查询 URL 的参数。

This hook is called by Client.get() to modify the keyword arguments before the query URL is built.
此钩子由 Client.get() 调用,用于修改查询 URL 生成之前的关键字参数。

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.
默认实现通过在提供“dsd”作为关键字参数之一时添加 HTTP “接受:” 头来处理对“结构特定数据”的请求。

See sgr.Source.modify_request_args() for an example override.
请参阅 sgr.Source.modify_request_args() 查看示例覆盖。

Return type  返回类型:

None

BIS: Bank for International Settlements
国际清算银行

SDMX-ML — WebsiteAPI reference
SDMX-ML — 网站 — API 参考

Added in version 2.5.0.  2.5.0 版本新增。

ECB: European Central Bank
欧洲中央银行

SDMX-ML — Website  SDMX-ML — 网站

  • Supports categorisations of data-flows.
    支持数据流的分类。

  • Supports preview_data and series-key based key validation.
    支持预览数据和系列键基于的密钥验证。

Changed in version 2.10.1: As of 2023-06-23 the ECB source is part of an “ECB Data Portal” that replaces an earlier “ECB Statistical Data Warehouse (SDW)” (documentation still available). The URL in sdmx is updated. Text on the ECB website (above) states that the previous URL (in sdmx ≤ 2.10.0) should continue to work until about 2024-06-23.
版本 2.10.1 中更改:截至 2023 年 6 月 23 日,ECB 数据源已成为“ECB 数据门户”的一部分,取代了之前的“ECB 统计数据仓库 (SDW)”(文档仍可获得)。 sdmx 中的 URL 已更新。ECB 网站上的文字(上面)指出,之前的 URL(在 sdmx ≤ 2.10.0)应该在 2024 年 6 月 23 日左右继续有效。

ILO: International Labour Organization
国际劳工组织

SDMX-ML — Website  SDMX-ML — 网站

Changed in version 2.15.0: Sometime before 2024-04-26, the base URL of this source changed from https://www.ilo.org/sdmx/rest to https://sdmx.ilo.org/rest. The “SDMX query builder” at the above URL reflects the change, but the documentation still shows the old URL, and there does not appear to have been any public announcement about the new URL, retirement of the old URL, etc. Thanks @SebaJeku for the tip (#177).
版本 2.15.0 中更改:在 2024 年 4 月 26 日之前,此源的基础 URL 从 https://www.ilo.org/sdmx/rest 更改为 https://sdmx.ilo.org/rest 。 上述 URL 的“SDMX 查询生成器”已反映了此更改,但文档仍然显示旧 URL,并且似乎没有关于新 URL、旧 URL 退役等的任何公开公告。感谢 @SebaJeku 的提示 (#177)。

IMF: International Monetary Fund’s “SDMX Central” source
国际货币基金组织“SDMX 中心”来源

SDMX-ML — Website  SDMX-ML — 网站

  • Subset of the data available on http://data.imf.org.
    http://data.imf.org 网站上可用数据的一个子集。

  • Supports series-key-only and hence dataset-based key validation and construction.
    支持仅序列键,因此基于数据集的键验证和构建。

INEGI: National Institute of Statistics and Geography (Mexico)
INEGI :国家统计与地理研究所(墨西哥)

SDMX-ML — Website.  SDMX-ML — 网站

  • Spanish name: Instituto Nacional de Estadística y Geografía.
    西班牙名称:国家统计与地理研究所。

INSEE: National Institute of Statistics and Economic Studies (France)
INSEE :法国国家统计与经济研究所

SDMX-ML — Website (en), (fr)
SDMX-ML — 网站 (en),(fr)

  • French name: Institut national de la statistique et des études économiques.
    法国名称:国家统计与经济研究机构。

  • Known issue(s) with this data source:
    此数据源存在的问题:

    • #205: as of 2024-11-12 some structures, for instance urn:sdmx:…DataStructure=FR1:CNA-2014-PIB(1.0), include concept_identity references that do not exist, for instance urn:sdmx:…Concept=FR1:CONCEPTS_INSEE(1.0).TIME_PERIOD and urn:sdmx:…Concept=FR1:CONCEPTS_INSEE(1.0).OBS_VALUE. From v2.20.0, reader.xml.v21 discards such invalid references, leaving .concept_identity = None.
      #205:截至 2024 年 11 月 12 日,某些结构,例如 urn:sdmx:…DataStructure=FR1:CNA-2014-PIB(1.0) ,包含不存在的引用,例如 urn:sdmx:…Concept=FR1:CONCEPTS_INSEE(1.0).TIME_PERIODurn:sdmx:…Concept=FR1:CONCEPTS_INSEE(1.0).OBS_VALUE 。从 v2.20.0 开始, reader.xml.v21 会丢弃此类无效引用,留下 .concept_identity = None

class sdmx.source.insee.Source[source]  [源]
modify_request_args(kwargs)
修改请求参数(kwargs)
[source]  [源]

Supply explicit provider agency ID for INSEE.
为 INSEE 提供明确的供应商机构 ID。

This web service accepts either “ALL” or “FR1” as a provider agency ID for structure endpoints, but not “INSEE” (see #21).
此网络服务接受“ALL”或“FR1”作为结构端点的提供机构 ID,但不接受“INSEE”(见#21)。

This hook sets the provider to “ALL” for structure queries if it is not given explicitly.
如果未明确指定,此挂钩会将提供者设置为“ALL”,以进行结构查询。

ISTAT: National Institute of Statistics (Italy)
ISTAT :意大利国家统计局

SDMX-ML — Website (en), (it)
SDMX-ML — 网站 (en),(it)

  • Italian name: Istituto Nazionale di Statistica.
    意大利名称:国家统计研究所。

  • Similar server platform to Eurostat, with similar capabilities.
    与欧盟统计局类似的服务器平台,功能相似。

  • Distinct API endpoints are available for:
    不同的 API 端点可用:

    • 2010 Agricultural census  2010 年农业普查

    • 2011 Population and housing census
      2011 年人口普查

    • 2011 Industry and services census
      2011 年行业和服务业普查

    …see the above URLs for details.
    请参阅以上网址了解更多详情。

LSD: National Institute of Statistics (Lithuania)
LSD :立陶宛国家统计局

SDMX-ML — Website  SDMX-ML — 网站

  • Lithuanian name: Lietuvos statistikos.
    立陶宛名称:立陶宛统计局

  • This web service returns the non-standard HTTP content-type “application/force-download”; sdmx replaces it with “application/xml”.
    此 Web 服务返回非标准 HTTP 内容类型“application/force-download”; sdmx 将其替换为“application/xml”。

NB: Norges Bank (Norway)
NB :挪威央行(挪威)

SDMX-ML — Website  SDMX-ML — 网站

  • Few data flows, so do not use category scheme.
    数据流少,所以不要使用类别方案。

  • It is unknown whether NB supports series-keys-only.
    目前尚不清楚 NB 是否支持仅系列键。

NBB: National Bank of Belgium (Belgium)
NBB :比利时国家银行(比利时)

SDMX-JSON — Website — API documentation (en)
SDMX-JSON — 网站 — API 文档 (en)

  • French name: Banque Nationale de Belgique.
    法国名字:比利时国家银行。

  • Dutch name: Nationale Bank van België.
    荷兰名称:比利时国家银行。

  • As of 2020-12-13, this web service (like STAT_EE) uses server software that serves SDMX-ML 2.0 or SDMX-JSON. Since sdmx does not support SDMX-ML 2.0, the package is configured to use the JSON endpoint.
    截至 2020 年 12 月 13 日,此 Web 服务(例如 STAT_EE)使用服务器软件,提供 SDMX-ML 2.0 或 SDMX-JSON。由于 sdmx 不支持 SDMX-ML 2.0,该软件包配置为使用 JSON 端点。

  • The web service returns a custom HTML error page rather than an SDMX error message for certain queries or an internal error. This appears as: ValueError: can't determine a SDMX reader for response content type 'text/html; charset=utf-8'
    某些查询或内部错误时,Web 服务会返回自定义 HTML 错误页面,而不是 SDMX 错误消息。这显示为: ValueError: can't determine a SDMX reader for response content type 'text/html; charset=utf-8'

OECD: Organisation for Economic Cooperation and Development (SDMX-ML)
经合组织(SDMX-ML)

SDMX-ML — Website, documentation
SDMX-ML — 网站、文档

  • As of 2023-08-14, the site includes a disclaimer that “This is a public beta release. Not all data is available on this platform yet, as it is being progressively migrated from https://stats.oecd.org.”
    截至 2023 年 8 月 14 日,该网站包含一份声明,指出“这是一次公开测试版发布。由于数据正在逐步从 https://stats.oecd.org 迁移过来,目前平台上并非所有数据都可用。”

  • The OECD website describes an older SDMX-ML API, but this is an implementation of SDMX 2.0, which is not supported by sdmx (see SDMX standard versions 2.0, 2.1, and 3.0).
    经合组织网站描述了旧版 SDMX-ML API,但这其实是一个 SDMX 2.0 的实现,而 sdmx 不支持它(请参阅 SDMX 标准版本 2.0、2.1 和 3.0)。

class sdmx.source.oecd.Source(id: str, url: str, name: str, headers: dict[str, ~typing.Any] = <factory>, data_content_type: ~sdmx.source.DataContentType = DataContentType.XML, versions: set[~sdmx.format.Version] = <factory>, supports: dict[str | ~sdmx.rest.common.Resource, bool] = <factory>)[source]  [源]
modify_request_args(kwargs)
修改请求参数(kwargs)
[source]  [源]

Supply explicit provider agency ID for OECD.
为经合组织提供明确的供应商机构 ID。

The structures and data flows from this provider use a variety of agency IDs—for example “OECD.SDD.TPS”—to identify a specific the organizational unit within the OECD that is responsible for each object. Queries requesting structures or data with agency ID “OECD” (strictly) may return few or zero results.
该提供商的结构和数据流使用各种机构 ID(例如“OECD.SDD.TPS”)来识别 OECD 内负责每个对象的特定组织单位。查询要求包含机构 ID“OECD”(严格)的结构或数据可能会返回很少或零个结果。

This hook sets the provider to “ALL” for structure queries if it is not given explicitly.
如果未明确指定,此挂钩会将提供者设置为“ALL”,以进行结构查询。

Added in version 2.12.0.  2.12.0 版本新增。

OECD_JSON: Organisation for Economic Cooperation and Development (SDMX-JSON)
经济合作与发展组织 (SDMX-JSON)

SDMX-JSON — Website  SDMX-JSON — 网站

Changed in version 2.12.0: Renamed from OECD.
版本 2.12.0 中更改:从 OECD 重命名。

sdmx.source.oecd_json.Client(*args, **kwargs) sdmx.client.Client[source]  [源]

Work around OECD_JSON legacy SSL issues.
解决 OECD_JSON 遗留的 SSL 问题。

As of 2023-08-16 the OECD_JSON data source uses an old, insecure version of SSL/TLS that—with default SSL configuration on properly patched systems—raises a SSLError “UNSAFE_LEGACY_RENEGOTIATION_DISABLED”.
截至 2023 年 8 月 16 日,OECD_JSON 数据源使用旧的、不安全的 SSL/TLS 版本,该版本——在经过正确修补的系统上使用默认的 SSL 配置——会引发 SSLError “UNSAFE_LEGACY_RENEGOTIATION_DISABLED” 错误。

This function creates a Client using the workaround described at https://stackoverflow.com/a/71646353/ to allow connecting to this data source.
此函数使用 https://stackoverflow.com/a/71646353/中描述的解决方法创建一个 Client ,从而允许连接到该数据源。

Warning  警告

Using this workaround disables SSL configuration that is intended to mitigate against man-in-the-middle attacks as described in CVE-2009-3555. Use with caution: in particular, do not change the Source.url to use with data sources other than OECD_JSON.
使用此变通方法会禁用旨在防范中间人攻击的 SSL 配置,如 CVE-2009-3555 所述。请谨慎使用:特别是,不要将 Source.url 用于除 OECD_JSON 之外的其他数据源。

class sdmx.source.oecd_json.HTTPSAdapter(ssl_context=None, **kwargs)[source]  [源]

HTTPAdapter with custom SSLContext.
使用自定义的 SSLContext

SGR: SDMX Global Registry
SGR :SDMX 全球注册表

SDMX-ML — Website  SDMX-ML — 网站

class sdmx.source.sgr.Source
sdmx.source.sgr.Source
[source]  [源]
handle_response(response, content)
处理响应(response, 内容)
[source]  [源]

SGR responses do not specify content-type; set it directly.
SGR 响应不指定内容类型;直接设置。

modify_request_args(kwargs)
修改请求参数(kwargs)
[source]  [源]

SGR is a data source but not a data provider.
SGR 是数据源,但不是数据提供者。

Override the agency argument by setting agency='all' to retrieve all data republished by SGR from different providers.
通过将 agency='all' 设置为检索 SGR 从不同提供商重新发布的所有数据来覆盖 agency 参数。

SPC: Pacific Data Hub DotStat by the Pacific Community (SPC)
太平洋数据中心 DotStat,由太平洋共同体(SPC)提供

SDMX-ML — API documentationWeb interface
SDMX-ML — API 文档 — Web 接口

  • French name: Communauté du Pacifique
    太平洋岛国社区

STAT_EE: Statistics Estonia (Estonia)
STAT_EE :爱沙尼亚统计局(爱沙尼亚)

SDMX-JSON — Website (et) — API documentation (en), (et)
SDMX-JSON — 网站 (et) — API 文档 (en),(et)

  • Estonian name: Eesti Statistika.
    爱沙尼亚名称:爱沙尼亚统计.

  • As of 2023-05-19, the site displays a message:
    截至 2023 年 5 月 19 日,该网站显示一条消息:

    From March 2023 onwards, data in this database are no longer updated! Official statistics can be found in the database at andmed.stat.ee.
    从 2023 年 3 月起,此数据库中的数据不再更新!官方统计数据可在 andmed.stat.ee 数据库中找到。

    The latter URL indicates an API is provided, but it is not an SDMX API, and thus not supported.
    后一个 URL 指示提供了一个 API,但它不是 SDMX API,因此不受支持。

  • As of 2020-12-13, this web service (like NBB) uses server software that serves SDMX-JSON or SDMX-ML 2.0. The latter is not supported by sdmx (see SDMX standard versions 2.0, 2.1, and 3.0).
    截至 2020 年 12 月 13 日,此网络服务(例如 NBB)使用服务器软件,提供 SDMX-JSON 或 SDMX-ML 2.0。后者不受 sdmx 支持(请参阅 SDMX 标准版本 2.0、2.1 和 3.0)。

UNESCO: UN Educational, Scientific and Cultural Organization
联合国教科文组织

SDMX-ML — Website  SDMX-ML — 网站

  • Free registration required; user credentials must be provided either as parameter or HTTP header with each request.
    需要免费注册;每个请求都需要提供用户凭证,作为参数或 HTTP 头。

Warning  警告

An issue with structure-specific datasets has been reported. It seems that Series are not recognized due to some oddity in the XML format.
已报告结构特定数据集存在问题。似乎由于 XML 格式的某些奇异之处,Series 未被识别。

UNICEF: UN Children’s Fund
联合国儿童基金会

SDMX-ML or SDMX-JSON — API documentationWeb interfaceData browser
SDMX-ML 或 SDMX-JSON——API 文档——Web 界面——数据浏览器

  • This source always returns structure-specific messages for SDMX-ML data queries; even when the HTTP header Accept: application/vnd.sdmx.genericdata+xml is given.
    此源始终会针对 SDMX-ML 数据查询返回结构特定消息;即使给定 HTTP 头 Accept: application/vnd.sdmx.genericdata+xml

  • UNICEF also serves data for the Countdown to 2030 initiative under a data flow with the ID CONSOLIDATED. The structures can be obtained by giving the provider argument to a structure query, and then used to query the data:
    联合国儿童基金会还在“2030 年可持续发展议程”倡议下,通过 ID CONSOLIDATED 的数据流提供数据。可以通过向结构查询提供者参数来获取结构,然后用于查询数据:

    import sdmx
    
    UNICEF = sdmx.Client("UNICEF")
    
    # Use the dataflow ID to obtain the data structure definition
    dsd = UNICEF.dataflow("CONSOLIDATED", provider="CD2030").structure[0]
    
    # Use the DSD to construct a query for indicator D5 (“Births”)
    client.data("CONSOLIDATED", key=dict(INDICATOR="D5"), dsd=dsd)
    
  • The example query from the UNICEF API documentation (also used in the sdmx test suite) returns XML like:
    联合国儿童基金会 (UNICEF) API 文档中的示例查询(也用于 sdmx 测试套件)返回类似 XML 的内容:

    <mes:Structure structureID="UNICEF_GLOBAL_DATAFLOW_1_0" namespace="urn:sdmx:org.sdmx.infomodel.datastructure.Dataflow=UNICEF:GLOBAL_DATAFLOW(1.0):ObsLevelDim:TIME_PERIOD" dimensionAtObservation="TIME_PERIOD">
      <com:StructureUsage>
        <Ref agencyID="UNICEF" id="GLOBAL_DATAFLOW" version="1.0"/>
      </com:StructureUsage>
    </mes:Structure>
    

    Contrary to this, the corresponding DSD actually has the ID DSD_AGGREGATE, not GLOBAL_DATAFLOW. To retrieve the DSD—which is necessary to parse a data message—first query this data flow by ID, and select the DSD from the returned message:
    与此相反,相应的 DSD 实际上具有 ID DSD_AGGREGATE ,而不是 GLOBAL_DATAFLOW 。要检索 DSD(解析数据消息所必需的)——首先通过 ID 查询此数据流,然后从返回的消息中选择 DSD:

    In [1]: import sdmx
    
    In [2]: msg = sdmx.Client("UNICEF").dataflow("GLOBAL_DATAFLOW")
    
    In [3]: msg
    Out[3]: 
    <sdmx.StructureMessage>
      <Header>
        id: 'IREF735911'
        prepared: '2024-12-16T18:26:33+00:00'
        receiver: <Agency not_supplied>
        sender: <Agency UNICEF>
        source: 
        test: False
      response: <Response [200]>
      Codelist (46): CL_CONF_STATUS CL_SEX CL_UNIT_MULT CL_ADMIN_LEVEL CL_A...
      ConceptScheme (1): UNICEF_CONCEPTS
      ContentConstraint (1): CONSTR_SEX
      DataflowDefinition (1): GLOBAL_DATAFLOW
      AgencyScheme (3): SDMX:AGENCIES UNICEF:AGENCIES UNICEF:DATA_PROVIDERS
      ProvisionAgreement (1): GLOBAL_DATAFLOW_UNICEF_UNICEF
      DataStructureDefinition (1): DSD_AGGREGATE
    
    In [4]: dsd = msg.structure[0]
    

    The resulting object dsd can be passed as an argument to a Client.get() data query. See the sdmx test suite for an example.
    生成的 dsd 对象可以作为参数传递给 Client.get() 数据查询。请参阅 sdmx 测试套件以获取示例。

UNSD: United Nations Statistics Division
联合国统计司

SDMX-ML — Website  SDMX-ML — 网站

  • Supports preview_data and series-key based key validation.
    支持预览数据和系列键基于的密钥验证。

WB: World Bank Group “World Integrated Trade Solution”
世界银行集团“世界一体化贸易解决方案”

SDMX-ML — Website  SDMX-ML — 网站

WB_WDI: World Bank Group “World Development Indicators”
世界银行集团“世界发展指标”

SDMX-ML — Website  SDMX-ML — 网站

  • This web service also supports SDMX-JSON. To retrieve messages in this format, pass the HTTP Accept: header described on the service website.
    此 Web 服务还支持 SDMX-JSON。要检索此格式的消息,请传递服务网站上描述的 HTTP Accept: 头。

Source API  源 API

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.
此模块定义 Source 和一些实用函数。有关用于提供 sdmx 对某些数据源的内置支持的 Source 的内置子类,请参阅数据源。

class sdmx.source.Source  sdmx.source.Source[source]  [源]

SDMX-IM RESTDatasource.  SDMX-IM RESTDatasource

This class describes the location and features supported by an SDMX REST API data source/web service.
这个类描述了 SDMX REST API 数据源/Web 服务支持的位置和功能。

It also provides three hooks, with default implementations. Subclasses may override the hooks in order to handle specific features of different REST web services:
它还提供三个钩子,并附带默认实现。子类可以覆盖钩子以处理不同 REST Web 服务的特定功能:

handle_response(response, content)
handle_response (回复,内容)

Handle response content of unknown type.
处理未知类型的响应内容。

finish_message(message, request, **kwargs)
finish_message (消息,请求,**kwargs)

Postprocess retrieved message.
后处理检索到的消息。

modify_request_args(kwargs)   modify_request_args (关键字参数)

Modify arguments used to build query URL.
修改用于构建查询 URL 的参数。

This class should not be instantiated directly. Instead, use add_source(), and then create a new Client with the corresponding source ID.
此类不应直接实例化。请使用 add_source() ,然后创建具有相应源 ID 的新 Client

data_content_type: DataContentType = 3[source]  [源]

DataContentType indicating the type of data returned by the source.
DataContentType 表示源数据返回的数据类型。

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

Postprocess retrieved message.
后处理检索到的消息。

This hook is called by Client.get() after a Message object has been successfully parsed from the query response.
该钩子由 Client.get() 调用,在从查询响应中成功解析了 Message 对象之后。

See estat.Source.finish_message() for an example implementation.
请参阅 estat.Source.finish_message() 了解示例实现。

get_url_class() type[sdmx.rest.common.URL][source]  [源]

Return a class for constructing URLs for this Source.
返回一个用于构造此源的 URL 的类。

  • If versions includes only SDMX 3.0.0, return v30.URL.
    如果 versions 只包含 SDMX 3.0.0,则返回 v30.URL

  • If versions includes SDMX 2.1, return v21.URL.
    如果 versions 包含 SDMX 2.1,则返回 v21.URL

  • Raise an exception for other versions that are not supported.
    对于不支持的 versions ,抛出异常。

handle_response(response: Response, content: IOBase) tuple[Response, IOBase]
处理响应(response:Response, content:IOBase) → 元组[Response,IOBase]
[source]  [源]

Handle response content of unknown type.
处理未知类型的响应内容。

This hook is called by Client.get() only when the content cannot be parsed as XML or JSON.
此钩子仅在内容无法解析为 XML 或 JSON 时由 Client.get() 调用。

See estat.Source.handle_response() and sgr.Source.handle_response() for example implementations.
请见 estat.Source.handle_response()sgr.Source.handle_response() 查看示例实现。

headers: dict[str, Any]  headers: 字典[字符串, 任何类型][source]  [源]

Additional HTTP headers to supply by default with all requests.
默认情况下,所有请求都应提供的额外 HTTP 头。

id: str[source]  [源]

id of the DataProvider.
idDataProvider

modify_request_args(kwargs)
修改请求参数(kwargs)
[source]  [源]

Modify arguments used to build query URL.
修改用于构建查询 URL 的参数。

This hook is called by Client.get() to modify the keyword arguments before the query URL is built.
此钩子由 Client.get() 调用,用于修改查询 URL 生成之前的关键字参数。

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.
默认实现通过在提供“dsd”作为关键字参数之一时添加 HTTP “接受:” 头来处理对“结构特定数据”的请求。

See sgr.Source.modify_request_args() for an example override.
请参阅 sgr.Source.modify_request_args() 查看示例覆盖。

Return type  返回类型:

None

name: str[source]  [源]

Human-readable name of the data source.
数据源的易读名称。

supports: dict[str | Resource, bool]
支持:dict[str|资源,布尔]
[source]  [源]

Mapping from Resource values to bool indicating support for SDMX-REST endpoints and features. If not supplied, the defaults from SDMX_ML_SUPPORTS are used.
Resource 值到 bool 的映射,指示对 SDMX-REST 端点和功能的支持。如果未提供,则使用 SDMX_ML_SUPPORTS 中的默认值。

Two additional keys are valid:
还有两个有效键:

  • "preview"=True if the source supports ?detail=serieskeysonly. See preview_data().
    如果源支持 ?detail=serieskeysonly 。请参阅 preview_data()

  • "structure-specific data"=True if the source can return structure- specific data messages.
    如果源头能够返回结构化数据消息。

url: str[source]  [源]

Base URL (API entry point) for queries.
查询的基准 URL(API 入口点)。

versions: set[Version]  versions:set[版本][source]  [源]

.Version["2.1"] only.   .Version["2.1"]

Type  类型:

SDMX REST API version(s) supported. Default
支持的 SDMX REST API 版本。默认

sdmx.source.list_sources()[source]  [源]

Return a sorted list of valid source IDs.
返回一个已排序的有效源 ID 列表。

These can be used to create Client instances.
这些可以用来创建 Client 个实例。

sdmx.source.load_package_sources()[source]  [源]

Discover all sources listed in sources.json.
发现 sources.json 中列出的所有来源。