-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[Feature] Refactor IMF for SDMX 3 #7282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
deeleeramone
wants to merge
28
commits into
develop
Choose a base branch
from
feature/refactor-imf
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
breaking_change
bug
Bugs and bug fixes
enhancement
Enhancement
feature
New feature
platform
OpenBB Platform
refactor
Refactor code
v4
PRs for v4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR resolves #7266
It includes a set of metadata, a router with utility functions and an
apps.jsonendpoint, as well as unit tests for the underlying helper functions.It also adds
imfas a provider to:obb.economy.cpiIt also touches tests related the
openbb-platform-apiexpected -> result definitions.The integrations test collector has been updated to scan provider extensions and the
integrationfolder, if it exists.Here is a test script used while developing the hierarchical tables logic.
Info Notice
From the README file:
This package provides everything you need - endpoints, tools, and metadata - to access and explore the entirety of https://data.imf.org, without any previous experience working with it.
Installation
Install from PyPI with:
Then build the Python static assets by running:
Quick Start
The fastest way to get started is by connecting to the OpenBB Workspace as a custom backend.
Start Server
This starts the FastAPI server over localhost on port 6900.
Add to Workspace
See the documentation here for more details.
Click to Open App
Once added, click on the app to open the dashboard.
The dashboard contains widgets with metadata and information, as well ones for exploring and retrieving the data.
Implementation Details
IMF is a SDMX API, and they organize their data by "dataflows". You can think of these as databases.
Each one has their own definitions for parameters and output. Some definitions are shared, others are domain-specific.
In SDMX, query models are expressed as dimensions, and data models as attributes.
The extension comes with a base level of metadata used for normalizing, translating, and validating inputs and outputs.
When mapping requires a code list that is not included, a network request is made to retrieve it.
User input is validated by calling the constraints API for each dimension.
The cached metadata contains all the potential values for parameters,
but the availability of each is determined by other choices - country, frequency, etc.
When making the actual request for data, parameters are tested for compatibility in the sequence defined by the data structure definition.
Invalid parameter combinations are returned as helpful error messages with descriptions of what went wrong and what the valid choices are.
The output converts ID codes into human-readable labels, and includes dataset and series metadata in a separate object.
Indicators
In this library, we refer to indicators as "indicator-like" dimensions within individual dataflows.
It includes dimensions like
COICOP_1999, so items such as CPI All Items, or Clothing and footwear,are considered.
The IMF codes for these values -
_T,CP01, etc. - are used to construct ticker-like symbols.Presentation Tables
Presentation tables are built from hierarchical code lists defining the parent-child relationship
between individual series.
Internally, table IDs are prefixed with
H_- i.e,H_BOP_BOP_AGG_STANDARD_PRESENTATION.The symbology allows entering references to tables, or indicators.
Symbology
The Open Data Platform generally refers to all time series IDs as a
symbol.Requesting time series data or presentation tables requires a symbol constructed from
the dataflow ID and the indicator-like dimensions, split with
::.CPI::CPIreturns all series forCPIunder theTYPE_OF_INDEXdimension.CPI::CPI_CP01returns just component of CPI, Food and non-alcoholic beverages.The symbol mapper matches the items after
::intelligently to its corresponding dimension.Entering,
CPI::CP01, gets the same result as,CPI::CPI_CP01.CPI::CPI__Treturns just the top-level, All Items.CPI::H_CPI_BY_COMPONENTreturns the entire presentation table, Consumer Price Index (CPI) by Component.Use,
obb.imf_utils.list_tables(), for a list of tables and their symbol.Use,
obb.economy.available_indicators(provider='imf', query='), to search for, or list all, individual time series and symbols.This example lists all the indicators in the CPI and PI dataflows.
... {'symbol_root': 'CP01', 'symbol': 'CPI::CP01', 'description': 'Food and non-alcoholic beverages', 'agency_id': 'IMF.STA', 'dataflow_id': 'CPI', 'dataflow_name': 'Consumer Price Index (CPI)', 'structure_id': 'DSD_CPI', 'dimension_id': 'COICOP_1999', 'long_description': 'Food and non-alcholoic beverages consumer price index is produced using prices related to food items and non-alcoholic beverages such as fresh produce, packaged foods, and beverages excluding alcoholic drinks, aggregated by their respective consumer expenditure weights.', 'member_of': ['CPI::H_CPI_BY_COMPONENT']}, ...Coverage
All data available from https://data.imf.org/en/Data-Explorer can be retrieved, via
obb.economy.indicators(provider='imf', **kwargs).Additionally, there are endpoints for some Port Watch items (not part of the Data Explorer).
The extension creates a router path,
imf_utils, that exposes utility functions for UI integrations and metadata lookup.Endpoints
obb.economy.available_indicatorsobb.economy.indicatorsobb.economy.cpiobb.economy.direction_of_tradeobb.economy.shipping.chokepoint_infoobb.economy.shipping.chokepoint_volumeobb.economy.shipping.port_infoobb.economy.shipping.port_volumeobb.imf_utils.get_dataflow_dimensionsobb.imf_utils.list_dataflow_choicesobb.imf_utils.list_dataflowsobb.imf_utils.list_port_id_choicesobb.imf_utils.list_table_choicesobb.imf_utils.list_tablesobb.imf_utils.presentation_tableobb.imf_utils.presentation_table_choices"Choices" endpoints are utilized by OpenBB Workspace to populate widget dropdown menus.