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.4.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.4-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: world_economic_outlook-0.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 bc2ae3a5fdac2bb2759e046c5d45056cf4ad7ad7dcc5f360cdf9d987bf31c61e
MD5 7953688e0f5243eac90e61a7a715317f
BLAKE2b-256 62c7d475d2ed23cafaecd8f9dd4f86a74d3389dff486b2b9178a34d85b2c8504

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for world_economic_outlook-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 373477e7b6264b913319503570cc9c6bb5c01ad63838b03331acbf3c6f31b13c
MD5 0830c4f539d7e0e8fbdb0a30299d5a4e
BLAKE2b-256 4ca297fe3c52635a8286b742799d645d61a3f3c87b28df298d56548bd0d74926

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