Package: weo
weo-readerThis is a Python client to downloadIMF World Economic Outlook Reportdataset aspandasdataframes by release dates. You can explore:single country macroeconomic data and forecast,macro variables across countries for a given year,country-year panel for single macro variable.Dataset releases (vintages)Dataset releases (vintages) are available back to 2007, the reported data goes back to 1980, forecast is three years ahead.ReleaseDateLatest confirmedApril 2022FirstOctober 2007Confirmed release is tested to be processed withweo.
Usually, if something breaks in a new release users raise anissue here.InstallThe program is tested to run with Python 3.7.13 (as in Google Colab) and higher.To install:pip install weoLatest version:pip install git+https://github.com/epogrebnyak/weo-reader.gitFirst glanceGet US inflation forecast from April 2022 semiannual WEO release.fromweoimportdownload,WEOpath,url=download(2022,1)# weo_2022_1.csv 18.8Mb# Downloaded 2022-Apr WEO datasetdf_cpi=WEO(path).inflation()print(df_cpi.USA.tail(8))#         USA# 2020  1.549# 2021  7.426# 2022  5.329# 2023  2.337# 2024  2.096# 2025  1.970# 2026  1.983# 2027  2.017Step 1. Download dataSave data from IMF web site as local file. Specify year
and release:importweoweo.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:number1or2;month'Apr'or'Oct', and'Sep'in 2011.Your can list all years and releases available for download withweo.all_releases().
Combine to create local dataset of WEO vintages from 2007 to present:importpathlibimportweo# create folderpathlib.Path("weo_data").mkdir(parents=False,exist_ok=True)# download all releasesfor(year,release)inweo.all_releases():weo.download(year,release,directory="weo_data")Step 2. Inspect dataUseWEOclass to view and extract data.WEOis a wrapper around a pandas dataframe that ensures proper data import and easier access and slicing of data across time-country-variable dimensions.Try code below:fromweoimportWEOw=WEO("weo.csv")What variables and measurements are inside?# variable listingw.variables()# unitsw.units()w.units("Gross domestic product, current prices")# variable codesw.codesw.from_code("LUR")# countriesw.countries("United")# Dataframe with United Arab Emirates, United Kingdom# and United Statesw.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:w.gdp_pc_usd(start_year=2000,end_year=2020)Code documentationweopackage documentation ishere.Alternative data sources1. 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:https://db.nomics.world/IMF/WEOhttps://db.nomics.world/IMF/WEOAGGExample:fromdbnomicsimportfetch_series_by_api_linkts1=fetch_series_by_api_link("https://api.db.nomics.world/v22/""series/IMF/WEO:latest/DEU.PCPI""?observations=1")More on DBnomics:DBnomics Web APIIntroduction to DBnomics in Python2. Similar dataset, not updated since 2018, but with earlier years thanweo-reader:https://github.com/datasets/imf-weoDevelopment notesYou can download the WEO file in command line withcurlcommand:curl -o weo.csv https://www.imf.org/-/media/Files/Publications/WEO/WEO-Database/2020/02/WEOOct2020all.xlsWEOOct2020all.xlsfrom the web site is really a CSV file, not an Excel file.There is an update of GDP figures inJune 2020, but the file structure is incompatible with regular releases.Prior to 2020 the URL structure was similar tohttps://www.imf.org/external/pubs/ft/weo/2019/02/weodata/WEOOct2019all.xls