How to Use the API (Python and R)

Dear User,

Thank you for your query. What language are you using to pull the data? I would advise that you search "IMF API [data language] documentation" to find information on how to set up your query.

Additionally, please see here for the documentation on how to set up an API query using Json Restful:

To give you some general ideas of what it might look like for Python and R:

If you are using Python, the following is a good resource to use when setting up your query: 

In general, for setting up your query, the root of the URL that you want to retrieve data from is:

Following that root, you will need to add on additional details about what data you would like:

  • Data type: "CompactData" to retrieve data, "DataStructure" to retrieve series information, or "GenericMetadata" to get metadata. 
  • Database you would like to query: For example, International Financial Statistics ("IFS"), Balance of Payments ("BOP"), etc. 
  • Frequency: Annual ("A"), Quarterly ("Q"), Monthly ("M")
  • Specific Indicator interested in: For CPI this is " PCPI_IX"
So, if you want to query the IFS database for monthly CPI data for 2000-2001, you would want to use the URL: 

Alternatively, if you are using R, you can install the "imfr" package. The syntax for a data pull using this package generally looks like:

imf_data(database_id = , indicator = , country = , freq = , start = , end = )

You can find the documentation for the R imfr package here:

We hope you find this information useful. Should you have any further questions please feel free to contact us.


Data Dissemination and Client Services Team
Data Operations Division
Statistics Department
International Monetary Fund

Feedback and Knowledge Base