World Bank in Python All docs

World Bank API in Python

Two ways to read World Bank indicators from Python. The World Bank's own API is free and needs no key. APIFor serves the same World Development Indicators behind the key you already use for other datasets.

With the official API

The wbgapi package wraps the World Bank API. Pass an indicator code, a country code and a year range.

worldbank.py
import wbgapi as wb

df = wb.data.DataFrame("SP.POP.TOTL", "BRA", time=range(2015, 2026))
print(df)

With APIFor

One GET request with requests. Country is the two-letter ISO code, and indicator is the World Bank code.

apifor_indicators.py
import os
import requests

r = requests.get(
    "https://api.apifor.dev/v1/indicators",
    params={"country": "BR", "indicator": "SP.POP.TOTL", "limit": 100},
    headers={"x-api-key": os.environ["APIFOR_API_KEY"]},
    timeout=30,
)
r.raise_for_status()
for row in r.json()["data"]:
    print(row["year"], row["value"])

In the snapshot, the latest value for Brazil is 212,812,405 people (2025).

Want a DataFrame? pandas.DataFrame(r.json()["data"]) works on the same response. Each request uses one credit. Filters and paging are in the indicators reference.

Which one to use

Use the official API if World Bank data is all you need. Use APIFor if you also pull holidays, postal codes or other datasets and want one key and one response shape, or if an AI agent calls it over MCP.