Skip to main content

Interacts with the International Monetary Fund API (SDMX 3.0) to retrieve macroeconomic data.

Project description

imfFetcher

Interacts with the International Monetary Fund API (SDMX 3.0) to retrieve macroeconomic data.

Requirements & Installation:

  • Dependencies: httpx, pandas, nest_asyncio

  • To install, run:

    pip install imfFetcher==1.0.0
    

Example:

An IMFInstance is the entry point for accessing IMF datasets:

import imfFetcher

# Create an instance of IMFInstance:
instance = imfFetcher.IMFInstance()
# <IMFInstance object>

Each dataset provided by the IMF (e.g., CPI, National Economic Accounts, World Economic Outlook) is represented by a distinct dataflow. You can list available dataflows via the dataflows attribute:

# List available dataflows:
dataflows = instance.dataflows
DataflowID DataflowName DataflowVersion DataflowAgencyID StructureID StructureVersion StructureAgencyID
FD Fiscal Decentralization (FD) 6.0.0 IMF.STA DSD_FD 6.0+.0 IMF.STA
CPI Consumer Price Index (CPI) 3.0.1 IMF.STA DSD_CPI 3.0+.0 IMF.STA
FAS Financial Access Survey (FAS) 4.0.0 IMF.STA DSD_FAS 4.0+.0 IMF.STA
ER Exchange Rates (ER) 4.0.1 IMF.STA DSD_ER_PUB 4.0+.0 IMF.STA
... ... ... ... ... ... ...
ITG International Trade in Goods (ITG) 4.0.0 IMF.STA DSD_ITG 4.0+.0 IMF.STA
ANEA National Economic Accounts (NEA), Annual Data 6.0.1 IMF.STA DSD_ANEA 8.0+.0 IMF.STA
APDREO Asia and Pacific Regional Economic Outlook (APDREO) 6.0.0 IMF.APD DSD_APDREO 6.0+.0 IMF.APD
WEO World Economic Outlook (WEO) 6.0.0 IMF.RES DSD_WEO 6.0+.0 IMF.RES

Once you’ve chosen a dataflow, initialize a Dataflow object:

# Select the Consumer Price Index (CPI) dataflow:
dataflow = instance.Dataflow('CPI')
# <Dataflow object>

This object exposes all relevant metadata, including available dimensions (e.g., country, index type, frequency) for refining queries. Retrieve dimensions via:

# Get dimensions metadata:
dimensions = dataflow.dimensions
ConceptID ConceptAgencyID ConceptScheme ConceptVersion ConceptPosition ConceptName DimensionName DimensionDescription CodelistAgencyID CodelistID CodelistVersion
0 IMF CS_MASTER_DATA 1.0+.0 0 COUNTRY Country The country or region for which the data are reported IMF CL_COUNTRY 1.0+.0
1 IMF CS_MASTER_DOMAIN 1.0+.0 1 INDEX_TYPE Index type Type of index prices IMF CL_INDEX_TYPE 2.0+.0
2 IMF CS_MASTER_DOMAIN 1.0+.0 2 COICOP_1999 Expenditure Category Classification of Individual Consumption According to Purpose (COICOP), revision 1999 IMF CL_COICOP_1999 1.0+.0
3 IMF.STA CS_CPI 3.0+.0 3 TYPE_OF_TRANSFORMATION Transformation type Specific calculations applied to raw price data IMF.STA CL_CPI_TYPE_OF_TRANSFORMATION 3.0+.0
4 IMF CS_MASTER_SYSTEM 1.0+.0 4 FREQ Frequency Frequency of the reported data IMF CL_FREQ 1.0+.0

For each dimension, fetch valid values—use both dimensions_available_values (a pandas.DataFrame) and _dimensions_available_values (a dict):

avail = dataflow._dimensions_available_values
{
  'COICOP_1999': [
    {'ID': 'CP01', 'Name': 'Food and non-alcoholic beverages'},
    ...
    {'ID': '_T',   'Name': 'All Items'}
  ],
  'COUNTRY': [
    {'ID': 'USA', 'Name': 'United States'},
    {'ID': 'CAN', 'Name': 'Canada'},
    {'ID': 'GBR', 'Name': 'United Kingdom'},
    ...
  ],
  'FREQUENCY': [
    {'ID': 'A', 'Name': None},
    {'ID': 'M', 'Name': None},
    {'ID': 'Q', 'Name': None}
  ],
  'INDEX_TYPE': [
    {'ID': 'CPI',  'Name': 'Consumer Price Index'},
    {'ID': 'HICP', 'Name': 'Harmonised Index of Consumer Prices'}
  ],
  'TYPE_OF_TRANSFORMATION': [
    {'ID': 'IX',          'Name': 'Index'},
    {'ID': 'YOY_PCH_PA_PT','Name': 'Year-over-year percent change'},
    ...
  ]
}

Copy and adjust the query template:

# Build query parameters template:
qpar = dataflow.query_params_dict_template.copy()
# {
#   'COUNTRY': '*',
#   'INDEX_TYPE': '*',
#   'COICOP_1999': '*',
#   'TYPE_OF_TRANSFORMATION': '*',
#   'FREQUENCY': '*'
# }

Set filters:

qpar['COUNTRY']              = ['USA', 'CAN', 'GBR']  # United States, Canada, United Kingdom
qpar['INDEX_TYPE']           = 'CPI'                   # Consumer Price Index
qpar['COICOP_1999']          = '_T'                    # All items
qpar['TYPE_OF_TRANSFORMATION']= 'IX'                    # Index transformation
qpar['FREQUENCY']            = 'M'                     # Monthly frequency

Execute the query and clean results:

data = dataflow.query(qpar).dropna()
Date CAN GBR USA
1955-01-01 14.1 4.859513 12.244589
... ... ... ...
2025-04-01 163.4 137.700 147.116

Shape: 844 rows × 3 columns

Note: If the IMF API returns multiple tables, the query method outputs a dict of DataFrames, one per table.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imffetcher-1.0.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imffetcher-1.0.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file imffetcher-1.0.0.tar.gz.

File metadata

  • Download URL: imffetcher-1.0.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.2

File hashes

Hashes for imffetcher-1.0.0.tar.gz
Algorithm Hash digest
SHA256 564cfab36558b75b02ab9bf9e8bf19afa9aa6b3803d1bc7287da09b0c4580eb6
MD5 6ba954a8260d1c447c78c479b231ce75
BLAKE2b-256 f61879984facdde3d15beb8ffa4edb3218839e34c729ddaf2e27d36242e3e9b8

See more details on using hashes here.

File details

Details for the file imffetcher-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: imffetcher-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.2

File hashes

Hashes for imffetcher-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2c3e2e3c1a22d077bb06d20246ee334a0f8bdd976b98e73314f79c9274df11a
MD5 9ce676c75d5ad854485d55cbbd682fc7
BLAKE2b-256 1d609d713377e6695d31904c0c85641df58ddb2dde3f7e0c6d11374a9d6416ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page