Skip to main content

An IMF World Economic Outlook (WEO) API Client

Project description

World Economic Outlook

PyPI version License: MIT Supported Python versions

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.7+.

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" -save "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" -database "database.db" -table "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" -database "database.db" -table "weo" -save "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" -database "database.db" -table "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 -database "database.db" -table "weo" -format "csv" -output "weo.csv"

Export to JSON

db export -database "database.db" -table "weo" -format "json" -output "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.3.tar.gz (6.3 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.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: world_economic_outlook-0.0.3.tar.gz
  • Upload date:
  • Size: 6.3 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.3.tar.gz
Algorithm Hash digest
SHA256 e96b0e3f9231e907a8e4edfa24c65c06bd5d1490e194d7e0c2cf7afd7bcfbf79
MD5 b290e4480f69f25853bd6473e2ab004e
BLAKE2b-256 93b492b71c4b56198eaf391175b4ccd0f0def610919f4b8bebd9e6b563a156cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for world_economic_outlook-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9b7d18a14f96d89ecbab5076e2c0ad726fe6d4870da5861aec7d5e85a28bf87f
MD5 4b97fe5880df8a6b320fe0cae8bf6a69
BLAKE2b-256 68a4109bbc3ae2cb4ed99d5d829a24b688ac4c2b01cd14f68e94a2a7b602e639

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