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.
Metadata
Release files for imfFetcher 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| imffetcher-1.0.0.tar.gz | 13.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| imffetcher-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.4 kB
Release files / imffetcher-1.0.0.tar.gz
| Download URL | imffetcher-1.0.0.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
564cfab36558b75b02ab9bf9e8bf19afa9aa6b3803d1bc7287da09b0c4580eb6
|
|
BLAKE2b-256 checksum How to use checksums |
f61879984facdde3d15beb8ffa4edb3218839e34c729ddaf2e27d36242e3e9b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.2
|
Release files / imffetcher-1.0.0-py3-none-any.whl
| Download URL | imffetcher-1.0.0-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2c3e2e3c1a22d077bb06d20246ee334a0f8bdd976b98e73314f79c9274df11a
|
|
BLAKE2b-256 checksum How to use checksums |
1d609d713377e6695d31904c0c85641df58ddb2dde3f7e0c6d11374a9d6416ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.2
|
Security for imfFetcher 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.