Python client to download IMF World Economic Outlook (WEO) dataset as pandas dataframes.
- single country macroeconomic data and forecast,
- macro variables across countries for a given year,
- country-year panel for single macro variable.
Dataset releases (vintages) are available back to 2007, the reported data goes back to 1980, forecast is three years ahead.
The program is tested to run under Python 3.8. It may work well with Python version 3.6 and above.
pip install weo
Step 1. Download data
You need to save data as from IMF web site as local file. Specify year and release:
import weo weo.download(year=2020, release="Oct", filename="weo.csv")
You can access WEO releases starting October 2007 with this client. WEO is normally released in April and October, one exception is September 2011.
Release is referenced by number (
2) or by month (
'Sep' in 2011).
Your can list all years and releases available for download with
weo.all_releases(). Combine it to create local dataset of WEO vintages from 2007 to present:
from weo import all_releases for (year, release) in all_releases(): weo.download(year, release, directory='weo_data')
Note that folder 'weo_data' must exist for this script to run.
Step 2. Inspect data
WEO class to view and extract data.
WEO is a wrapper around a pandas dataframe that ensures proper data import and easier access and slicing of data.
Try code below:
from weo import WEO w = WEO("weo.csv")
What variables and measurements are inside?
# variable listing w.variables() # units w.units() w.units("Gross domestic product, current prices") # variable codes w.codes w.from_code("LUR") # countries w.countries("United") # Dataframe with United Arab Emirates, United Kingdom # and United States w.iso_code3("Netherlands") # 'NLD'
The dataset is year-country-variable-value cube, you can fix any dimension to get a table.
w.get("General government gross debt", "Percent of GDP") w.getc("NGDP_RPCH") w.country("DEU") w.fix_year(1994)
Plot a chart with the projected 12 largest economies in 2024 (current prices):
(w.gdp_usd(2024) .dropna() .sort_values() .tail(12) .plot .barh(title="GDP by country, USD billion (2024)") )
Get GDP per capita data from 2000 to 2020:
Alternative data sources
1. If you need the latest data as time series and not the vintages of WEO releases, and you know variables that you are looking for, dbnomics is a good choice:
from dbnomics import fetch_series_by_api_link ts1 = fetch_series_by_api_link("https://api.db.nomics.world/v22/" "series/IMF/WEO/DEU.NGDPRPC" "?observations=1")
2. Similar dataset, not updated since 2018, but with earlier years: https://github.com/datasets/imf-weo
- You can download the WEO file in command line with
curl -o weo.csv https://www.imf.org/-/media/Files/Publications/WEO/WEO-Database/2020/02/WEOOct2020all.xls
WEOOct2020all.xlsfrom the web site is really a CSV file, not an Excel file.
- There is an update of GDP figures in June 2020, but the file structure is incompatible with regular releases.
- Prior to 2020 the URL was similar to
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size weo-0.6.3-py3-none-any.whl (9.1 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size weo-0.6.3.tar.gz (9.4 kB)||File type Source||Python version None||Upload date||Hashes View|