imf_reader.weo.api
IMF World Economic Outlook (WEO) API client.
Attributes
Functions
|
Fetch mapping of Version tuples to API version strings. |
|
Fetch all available WEO versions from the IMF API. |
|
Fetch a codelist from the IMF API and return as a code->label mapping. |
|
Align the schema of the DataFrame to match the old SDMX format. |
|
Inner cached fetch — keyed on a resolved (month, year) tuple. |
|
Fetch WEO data for a specific version. |
Module Contents
- imf_reader.weo.api.SCALE_LABELS
- imf_reader.weo.api.SCALE_MULTIPLIERS
- imf_reader.weo.api._fetch_version_mapping() dict[imf_reader.weo.Version, str]
Fetch mapping of Version tuples to API version strings.
Results are cached for 1 hour to avoid redundant HTTP calls (F10).
- Returns:
Dict mapping (month, year) tuples to API version strings. e.g. {(“October”, 2025): “9.0.0”, (“April”, 2025): “6.0.0”}
- imf_reader.weo.api.get_weo_versions() list[imf_reader.weo.Version]
Fetch all available WEO versions from the IMF API.
- Returns:
List of Version tuples (month, year) sorted newest first. e.g. [(“October”, 2025), (“April”, 2025)]
- imf_reader.weo.api._fetch_codelist(agency: str, codelist_id: str) dict[str, str]
Fetch a codelist from the IMF API and return as a code->label mapping.
Results are cached locally to avoid repeated API calls.
- Parameters:
agency – The agency ID (e.g., “IMF”, “IMF.RES”)
codelist_id – The codelist ID (e.g., “CL_UNIT”, “CL_WEO_COUNTRY”)
- Returns:
Dict mapping codes to their labels.
- imf_reader.weo.api._align_schema(df: pandas.DataFrame) pandas.DataFrame
Align the schema of the DataFrame to match the old SDMX format.
Renames columns, adds label columns for codes, and fixes data types.
- Parameters:
df – DataFrame from API.
- Returns:
DataFrame with old-style column names, labels, and correct data types.
- imf_reader.weo.api._get_weo_data_cached(version: imf_reader.weo.Version) pandas.DataFrame
Inner cached fetch — keyed on a resolved (month, year) tuple.
Splitting the cache from the public
get_weo_dataensures thatversion=Noneis mapped to the current latest release before the cache lookup. Otherwise the wrapper would cache underNonefor 7 days and keep serving the previous release even after the version-mapping TTL (1 hour) sees a new one.
- imf_reader.weo.api.get_weo_data(version: imf_reader.weo.Version | None = None) pandas.DataFrame
Fetch WEO data for a specific version.
Data is cached locally to avoid repeated API calls. Use clear_cache() to clear.
- Parameters:
version – Version tuple (month, year) e.g. (“April”, 2025). If None, uses latest.
- Returns:
DataFrame with WEO data.