Getting World Bank data in Python

The World Bank API (api.worldbank.org/v2) is free and needs no key: ask for country/US;DE/indicator/NY.GDP.PCAP.CD with format=json and you get yearly values. Without format=json it answers in XML, and results are paged, so set per_page high. In Python you can use requests directly or the wbgapi package; our World Bank Indicators API also accepts plain names like "gdp_per_capita" for $0.003 per call.

Try it free World Bank Data API — GDP, population, inflation, $0.003 · $0.003 / call

Plain requests, done right

The answer is a two-item list: paging metadata first, then the rows. If the indicator or country is wrong, you get a list with a message instead, so check for it before unpacking.

import requests

url = "https://api.worldbank.org/v2/country/US;DE/indicator/NY.GDP.PCAP.CD"
meta, rows = requests.get(url, params={
    "format": "json", "date": "2019:2024", "per_page": 1000,
}, timeout=20).json()

for r in rows:
    print(r["countryiso3code"], r["date"], r["value"])  # value can be None

Common traps

Libraries

wbgapi is a well-maintained Python package for this API that returns pandas DataFrames and lets you search indicators by keyword. pandas-datareader also has a World Bank module. Both are free; use them when you work in notebooks and want tables.

One call with friendly names

Our API maps 27 plain names to World Bank codes (population, gdp, gdp_per_capita, inflation, unemployment, life_expectancy, co2, gini, internet_users and more) and still accepts any raw code. Up to 10 countries or groups per call, by ISO code or name, for a year or a range of up to 70 years (the latest 10 if you leave it out). Each country also gets its latest year that has a value, which saves the null-hunting step.

# pay_session: requests session wrapped by your x402 v2 client ($0.003 a call)
res = pay_session.post("https://iamai.markets/api/x402/services/eEZ1GNIsSe4N", json={
    "countries": ["US", "DE"], "indicator": "gdp_per_capita", "years": "2019:2024",
}, timeout=30).json()["result"]
for s in res["series"]:
    print(s["name"], s["latest"])

The product

Questions

Does the World Bank API need a key?

No. It is open, and the data is under CC BY 4.0, so credit the World Bank when you publish it.

Why is 2025 missing?

Most indicators are published with a delay of a year or more. The value comes back as null until it is filled in.

Is the paid API faster or more complete?

No, it reads the same World Bank API. It saves the code lookup, paging and null handling.

Related

Updated 2026-12-02