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.2.tar.gz (6.8 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.2-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: world_economic_outlook-0.0.2.tar.gz
  • Upload date:
  • Size: 6.8 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.2.tar.gz
Algorithm Hash digest
SHA256 2cffd3227203332050ad81949973481fdcb79189eceaaa85248e1c5e80480b30
MD5 f5e0377fb4341a0b1fe3ba1101aeb27c
BLAKE2b-256 ee80c8110b1189e271501ec1ed8b724ea9bc10966e0d3836643756d22f354a30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for world_economic_outlook-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b9506abddfe0905102fbd7777187bcd9f7417be399e6329719d58b313fb9dbd8
MD5 4f49a47fefebcce28b64b8c4756879a0
BLAKE2b-256 9ddbee1c2ac968405c06d846324be9eb6cd152b68f6a99b21ba4173816357038

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