WBData - World Bank Data Client
WBData is a Python library designed to simplify access to data from the World Bank's Indicators API. It provides an intuitive interface for searching indicators, countries, topics, and sources, and for retrieving time-series data. The current version is 1.1.0, with recent releases indicating active maintenance and regular updates.
Warnings
- breaking The 1.0.0 release introduced significant architectural changes, renaming many functions and arguments for consistency and clarity. Code written for pre-1.0.0 versions will likely break.
- breaking Version 1.1.0 dropped support for older, End-of-Life Python versions, now requiring Python >=3.10. Additionally, version 0.3.0 previously dropped support for Python <= 3.5.
- gotcha Prior to v1.0.0, date arguments exclusively required `datetime.datetime` objects. Since v1.0.0, string representations for years, months, or quarters are also accepted, which can lead to different interpretations of date ranges.
- breaking The `display` argument in search functions (e.g., `search_indicator`, `search_country`) was removed in v0.3.0. These functions now return lists that pretty-print as tables when directly expressed in a shell or notebook.
Install
-
pip install wbdata
Imports
- wbdata
import wbdata
Quickstart
import wbdata
import datetime
# Define the date range from 2000 to 2010
data_date = datetime.datetime(2000, 1, 1), datetime.datetime(2010, 1, 1)
# Define countries using their ISO2 codes
countries = ["FR", "DE", "IT"]
# Define indicators with human-readable aliases
indicators = {"NY.GDP.PCAP.CD": "GDP per Capita", "SP.POP.TOTL": "Total Population"}
# Get data as a Pandas DataFrame
df = wbdata.get_dataframe(indicators, country=countries, data_date=data_date)
print("\n--- Sample Data (GDP per Capita, Total Population) ---")
print(df.head())
# Get information about a specific indicator
print("\n--- Indicator Info for GDP per Capita ---")
indicators_info = wbdata.get_indicator("NY.GDP.PCAP.CD")
for key, value in indicators_info.items():
print(f"{key}: {value}")
# Search for indicators containing 'population'
print("\n--- Search Results for 'population' ---")
population_indicators = wbdata.search_indicator("population")
# In an interactive shell or notebook, printing the list directly would show a table
print(f"Found {len(population_indicators)} indicators matching 'population'. Showing first 3:\n{population_indicators[:3]}")