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: https://datahelp.imf.org/knowledgebase/articles/667681-json-restful-web-service


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: http://www.bd-econ.com/imfapi1.html 

In general, for setting up your query, the root of the URL that you want to retrieve data from is:  http://dataservices.imf.org/REST/SDMX_XML.svc/

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:

  http://dataservices.imf.org/REST/SDMX_XML.svc/CompactData/IFS/M..PCPI_IX.?startPeriod=2000&endPeriod=2001 


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: https://cran.r-project.org/web/packages/imfr/imfr.pdf


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

Sincerely,

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


Feedback and Knowledge Base