Comprehensive Guide to the World Bank API (WBAPI)

The World Bank API (WBAPI) is a powerful tool for accessing a vast array of economic and development data. This guide provides detailed information about the API’s endpoints, examples of how to use them, and practical applications.

Overview of Key Endpoints

The API allows users to retrieve data related to countries, indicators, regions, and more. Below is a detailed explanation of the primary endpoints:

1. Countries

  • Endpoint: /country
  • Description: Retrieves a list of all countries available in the World Bank database, including their codes and names.
  • Example Usage:
  GET http://api.worldbank.org/v2/country?format=json
  • Response Format: JSON, providing country details such as ID, name, and region.

2. Indicators

  • Endpoint: /indicator
  • Description: Accesses a comprehensive list of indicators that measure various economic, social, and environmental metrics.
  • Example Usage:
  GET http://api.worldbank.org/v2/indicator?format=json
  • Response Format: JSON, detailing indicator ID, name, and related metadata.

3. Data Retrieval

  • Endpoint: /data
  • Description: Fetches data for a specific indicator over time for a specific country or group of countries.
  • Example Usage:
  GET http://api.worldbank.org/v2/country/{country_code}/indicator/{indicator_id}?format=json
  • Replace {country_code} with the desired country code (e.g., BR for Brazil) and {indicator_id} with the specific indicator ID (e.g., NY.GDP.MKTP.CD for GDP).
  • Response Format: JSON, containing time series data for the specified indicator.

4. Series

  • Endpoint: /series
  • Description: Provides information on series, which can be analyzed for specific aspects of data over time.
  • Example Usage:
  GET http://api.worldbank.org/v2/series?format=json
  • Response Format: JSON, showing details about the series available.

5. Regions

  • Endpoint: /region
  • Description: Accesses a list of regions used by the World Bank for data classification.
  • Example Usage:
  GET http://api.worldbank.org/v2/region?format=json
  • Response Format: JSON, listing regions with IDs and names.

Example Queries

Here are some practical examples to demonstrate how to fetch specific data using the API:

GDP Data for Brazil

GET http://api.worldbank.org/v2/country/BR/indicator/NY.GDP.MKTP.CD?format=json

This call retrieves the GDP data for Brazil, showing historical values over time.

Population Data for India

GET http://api.worldbank.org/v2/country/IN/indicator/SP.POP.TOTL?format=json

This fetches population data for India, providing a time series of total population counts.

Using the API in Python

Here’s a simple example of how to use the World Bank API in a Python script:

import requests

# Example to get GDP data for Brazil
url = 'http://api.worldbank.org/v2/country/BR/indicator/NY.GDP.MKTP.CD?format=json'
response = requests.get(url)
data = response.json()

# Print the GDP data
for entry in data[1]:  # data[1] contains the actual data points
    print(f"Year: {entry['date']}, GDP: {entry['value']}")

Summary Table of Endpoints

EndpointDescriptionExample Usage
/countryList all countriesGET http://api.worldbank.org/v2/country?format=json
/indicatorAccess all indicatorsGET http://api.worldbank.org/v2/indicator?format=json
/dataFetch specific indicator dataGET http://api.worldbank.org/v2/country/{country_code}/indicator/{indicator_id}?format=json
/seriesInformation on seriesGET http://api.worldbank.org/v2/series?format=json
/regionList of regionsGET http://api.worldbank.org/v2/region?format=json

Conclusion

The World Bank API is a valuable resource for researchers, developers, and policymakers looking to access economic and social data globally. By utilizing the endpoints described in this guide, you can effectively gather data on various topics, aiding in research and analysis. For more detailed information, visit the official World Bank Data Help Desk

Edvaldo Guimrães Filho Avatar

Published by

Leave a comment