imf_reader.weo.reader

Main interface to the WEO database.

Functions

validate_version(→ imf_reader.weo.Version)

Validate the version

gen_latest_version(→ imf_reader.weo.Version)

Generates the latest expected version based on the current date as a tuple of month and year

roll_back_version(→ imf_reader.weo.Version)

Roll back version to the previous version

_fetch(→ pandas.DataFrame)

Helper function which handles caching and fetching the data from the IMF website

fetch_data(→ pandas.DataFrame)

Fetch WEO data

Module Contents

imf_reader.weo.reader.validate_version(version: tuple) imf_reader.weo.Version

Validate the version

Make sure that it is a tuple of month and year and the month is either April or October.

Parameters:

version – The version to validate

Returns:

A tuple of the month and year

imf_reader.weo.reader.gen_latest_version() imf_reader.weo.Version

Generates the latest expected version based on the current date as a tuple of month and year

Returns:

A tuple of the latest month and year

imf_reader.weo.reader.roll_back_version(version: imf_reader.weo.Version) imf_reader.weo.Version

Roll back version to the previous version

This function rolls back the version passed to the expected previous version. If the version is April 2024 it will roll back to October 2023. If the version is October 2023 it will roll back to April 2023.

Parameters:

version – The version to roll back

Returns:

The rolled back version

imf_reader.weo.reader._fetch(version: imf_reader.weo.Version) pandas.DataFrame

Helper function which handles caching and fetching the data from the IMF website

Parameters:

version – The version of the WEO data to fetch

Returns:

A pandas DataFrame containing the WEO data

imf_reader.weo.reader.fetch_data(version: imf_reader.weo.Version | None = None) pandas.DataFrame

Fetch WEO data

By default, this function fetched data for the latest WEO publication. If a specific publication version is required, the version can be passed as a tuple of month and year. WEO data is released in April and October each year. For the version month, the month must be either “April” or “October” This function caches the data for faster access and to prevent multiple requests to the IMF website. To clear the cache, use the clear_cache function.

e.g. >>> fetch_data() # fetches the latest data >>> fetch_data((“April”, 2024)) # fetches the data for April 2024

Parameters:

version – The version of the WEO data to fetch as a tuple eg `(“April”, 2023). By default, the latest version is fetched.

Returns:

A pandas DataFrame containing the WEO data