Skip to main content

An IMF World Economic Outlook (WEO) API Client

Project description

World Economic Outlook

PyPI version License: MIT Python

Easily fetch IMF World Economic Outlook (WEO) data.

world-economic-outlook is a Python library and CLI tool for downloading, saving, and processing World Economic Outlook (WEO) data from the International Monetary Fund (IMF). It provides a convenient interface for managing WEO data, saving it locally, and pushing it to a database.


Features

  • Download WEO data for a specific vintage (e.g., "2025 April").
  • Save the downloaded data as an .xls file.
  • Push data to a SQLite database.
  • Command-line interface (CLI) for all major actions.
  • Programmatic API for automation and scripting.
  • Wrapper class for flexible workflows.

Installation

Requires Python 3.9+.

Install the published package:

pip install world-economic-outlook

Or install the library and its dependencies using pip:

pip install -r requirements.txt

Quick Start

Programmatic Usage

Using the WEO Wrapper

This example demonstrates how to use the WEO wrapper class to download, push to a database, and save WEO data:

from world_economic_outlook import WEO

weo = WEO()
weo.download("2025 April")  # Download the data for the specified vintage
weo.push("database.db", "weo")  # Push the data to a SQLite database table
weo.save("weo.xls")  # Save the data as an .xls file

Using the download Function

This example demonstrates how to use the download function to download WEO data and either save it to a file, push it to a database, or both in a single call:

from world_economic_outlook import download

download("2025 April", save_path="weo.xls", database="database.db", table="weo")
  • vintage: The vintage string (e.g., '2025 April').
  • save_path: (Optional) Path to save the WEO data as a file.
  • database and table: (Optional) Push the data to a SQLite database.

Command-Line Interface (CLI)

The CLI provides a convenient way to interact with the WEO Downloader and is installed with the package.

Download and Save Data

This example downloads WEO data for a specific vintage and saves it as an .xls file:

weo download "2025 April" -s "2025_April.xls"

Push Data to a Database

This example downloads WEO data and pushes it directly to a SQLite database table:

weo download "2025 April" -d "database.db" -t "weo"

Perform All Actions

This example downloads WEO data, saves it as an .xls file, and pushes it to a database in one command:

weo download "2025 April" -d "database.db" -t "weo" -s "2025_April.xls"

Help

For more details, run:

weo --help

Useful Tools

simple-sqlite3

The simple-sqlite3 library is used in this project to interact with SQLite databases. Make sure you have already created the database and table by running the weo CLI to download the data:

weo download "2025 April" -d "database.db" -t "weo"

Below are some useful commands for exporting data from your SQLite database to different file formats such as CSV and JSON.

Export to CSV

db export -d "database.db" -t "weo" -f "weo.csv"

Export to JSON

db export -d "database.db" -t "weo" -f "weo.json"

Fetching Data

This example shows how to fetch all database records for Brazil.

from simple_sqlite3 import Database

db = Database("database.db")

table = db.table("weo")

sql = """SELECT * WHERE iso = 'BRA'"""

results = table.query(sql)

print(results)

Example Output (from print(results)):

[   ...
    {
        "units": "National currency",
        "estimate": 0,
        "scale": "Billions",
        "weo_subject_code": "NGDP_R",
        "value": "522.938",
        "iso": "BRA",
        "subject_descriptor": "Gross domestic product, constant prices",
        "country": "Brazil",
        "vintage": "2025 April",
        "estimates_start_after": 2024,
        "year": 1980
    },
    {
        "units": "National currency",
        "estimate": 0,
        "scale": "Billions",
        "weo_subject_code": "NGDP_R",
        "value": "499.93",
        "iso": "BRA",
        "subject_descriptor": "Gross domestic product, constant prices",
        "country": "Brazil",
        "vintage": "2025 April",
        "estimates_start_after": 2024,
        "year": 1981
    },
    ...
]

More Fetch Conditions

This example shows how to fetch database records for Real GDP Growth for Brazil and Mexico in 2020 and 2021 from the 2025 April WEO.

from simple_sqlite3 import Database

db = Database("database.db")

table = db.table("weo")

sql = """ 
    SELECT year, value, country, weo_subject_code
    WHERE iso IN ('MEX', 'BRA')
    AND year BETWEEN 2020 AND 2021
    AND vintage='2025 April'
    AND weo_subject_code = 'NGDP_RPCH'
"""

results = table.query(sql)

print(results)

Example Output (from print(results)):

[
    {
        "year": 2020,
        "value": "-3.277",
        "country": "Brazil",
        "weo_subject_code": "NGDP_RPCH"
    },
    {
        "year": 2021,
        "value": "4.763",
        "country": "Brazil",
        "weo_subject_code": "NGDP_RPCH"
    },
    {
        "year": 2020,
        "value": "-8.354",
        "country": "Mexico",
        "weo_subject_code": "NGDP_RPCH"
    },
    {
        "year": 2021,
        "value": "6.048",
        "country": "Mexico",
        "weo_subject_code": "NGDP_RPCH"
    }
]

License

This project is developed by Rob Suomi and licensed under the MIT License.
See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

world_economic_outlook-0.0.5.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

world_economic_outlook-0.0.5-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file world_economic_outlook-0.0.5.tar.gz.

File metadata

  • Download URL: world_economic_outlook-0.0.5.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for world_economic_outlook-0.0.5.tar.gz
Algorithm Hash digest
SHA256 5028e61b50a3f1926ad625b761b9a3111943aaf80109af1d4e6bd978b2a88685
MD5 5dff793fdd73d694ec8391b9d941dad9
BLAKE2b-256 c4022517e8ed5828587fe0d50c32a81799fac31bb32bd0931a420038ea216230

See more details on using hashes here.

File details

Details for the file world_economic_outlook-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for world_economic_outlook-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 418015ff6a6d7a7a26309c4a6d786444881525e3723e573325c18834211d6a05
MD5 53076ce9b4bbc618656c9615ac96df69
BLAKE2b-256 1372ab0b7dc4ca1847b50897a7e57bd8beade998cf0429d1ac1b8537a8fa2509

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page