bblocks.import_tools.debt

Submodules

Classes

DebtIDS

Import data from the World Bank's International Debt Statistics database.

Functions

get_dsa(→ pandas.DataFrame)

Extract DSA _data from the

Package Contents

class bblocks.import_tools.debt.DebtIDS

Bases: bblocks.import_tools.common.ImportData

Import data from the World Bank’s International Debt Statistics database.

To use this object, first create an instance of it. Then use the load_data method to load indicators. One or more indicators can be loaded at a time, and a starting and end year must be specified.

If the data has not been downloaded before, it will be downloaded from the World Bank API. If the data has been downloaded before, it will be loaded from the local data folder.

To get a DataFrame, use the get_data method. You can get the data for one or more, or for all indicators at once.

To update the data, use the update_data method. This will download the latest data from the World Bank API and overwrite the local data.

  • To get a list of available indicators, use the get_available_indicators method.

  • To get a list of available debt service indicators, use the debt_service_indicators method.

  • To get a list of available debt stocks indicators, use the debt_stocks_indicators method.

__post_init__()

Set the path to the data folder and create it if it doesn’t exist

_check_stored_data(indicator: str, start_year: int, end_year: int) str | bool

Check if the data is already stored locally

This also checks if the years requested are inside another file.

Parameters:
  • indicator (str) – The indicator to check

  • start_year (int) – The start year of the data

  • end_year (int) – The end year of the data

Returns:

The filename of the data if it exists bool: False if the data doesn’t exist

Return type:

str

static _indicator_parameters(indicator: str) tuple[str, int, int]

Get the indicator, start year and end year from the indicator name.

classmethod get_available_indicators() dict

Get a dictionary of all available indicators in the IDS database.

classmethod debt_service_indicators(detailed_category: bool = True) dict

Get a dictionary of Debt Service indicators in the IDS database.

classmethod debt_stocks_indicators(detailed_category: bool = True) dict

Get a dictionary of Debt Service indicators in the IDS database.

_get_indicator(indicator: str, start_year: int, end_year: int) bblocks.import_tools.common.ImportData

Get data for an indicator. This method is not meant to be accessed directly. Instead, use the .get_data() method.

Parameters:

indicator – The indicator to get. They must be in the IDS format (e.g. DT.DOD.DECT.CD). To view all available indicators, call .get_available_indicators().

Returns:

The same object to allow chaining of methods

load_data(indicators: str | list, start_year: int, end_year: int) bblocks.import_tools.common.ImportData

Load the data for an indicator or a list of indicators.

Parameters:
  • indicators – The indicator(s) to load. They must be in the IDS format (e.g. DT.DOD.DECT.CD). To view all available indicators, call .get_available_indicators().

  • start_year – The first year to include in the data

  • end_year – The last year to include in the data

update_data(reload_data: bool = True) bblocks.import_tools.common.ImportData

Update the data for all loaded indicators.

get_data(indicators: str | list = 'all', **kwargs) pandas.DataFrame

Get the data for an indicator or a list of indicators.

Parameters:

indicators – The indicator(s) to get. They must be in the IDS format (e.g. DT.DOD.DECT.CD). To get all available indicators, set indicators=”all”.

Returns:

A pandas dataframe with the requested data.

bblocks.import_tools.debt.get_dsa(update=False, local_path: str = None) pandas.DataFrame

Extract DSA _data from the

Extract the most recent Debt Sustainability Assessment (DSA) _data for PRGT-Eligible Countries from the IMF website. URL = https://www.imf.org/external/Pubs/ft/dsa/DSAlist.pdf

Parameters:
  • local_path – where the downloaded PDF will be stored

  • update (bool) – if True, updates the _data from the IMF website. Otherwise it loads the _data from the local file. If a local file does not exist, the _data will be extracted from the website.

Returns:

pandas dataframe with country, latest publication date, and risk of debt distress