Skip to main content

Enterprise-grade Async Python Client for World Bank Data360 API

Project description

wbgapi360: World Bank Data Client for Humans & AI

PyPI version Python License: MIT Build Status Status

wbgapi360 is a high-performance Python client designed to interact with the World Bank's Data APIs. It bridges the gap between traditional econometric analysis and modern Artificial Intelligence workflows.

This library is engineered with a Hybrid Architecture: it provides a synchronous, blocking API for human analysts (similar to pandas or matplotlib) and an asynchronous Model Context Protocol (MCP) server for AI Agents (such as Claude or OpenAI).


Project Philosophy & Attribution

Unofficial Client

This software is an independent open-source project. It is not affiliated, associated, authorized, endorsed by, or in any way officially connected with The World Bank Group. The official World Bank website can be found at worldbank.org.

Inspiration & Legacy

This project is built upon the conceptual foundation laid by Tim Herzog (tgherzog) and his pioneering work with the original wbgapi.

While wbgapi set the standard for Pythonic access to World Bank data, wbgapi360 was built from the ground up to address two new challenges in the modern era:

  1. AI Integration: Native support for LLM function calling via MCP.
  2. Smart Search: Heuristic ranking algorithms to disambiguate indicators (e.g., distinguishing "GDP" from "Education Expenditure as % of GDP").

We acknowledge and thank Tim for establishing the developer-friendly patterns that inspired this library's human interface.


Installation

The library is available on PyPI.

# Core installation (Lightweight)
pip install wbgapi360

# With Visualization support (adds Matplotlib/Seaborn)
pip install wbgapi360[visual]

# With Mapping support (adds GeoPandas - Heavy dependency)
pip install wbgapi360[map]

Usage Guide: For Analysts (Python)

The human interface is designed to be intuitive, synchronous, and safe for Jupyter Notebooks.

1. Smart Search (Semantic)

Finding the right indicator among 16,000+ options is difficult. wbgapi360 uses a heuristic ranking system.

import wbgapi360 as wb

# Search for "inflation" - automatically ranks "Consumer Price Index" above obscure sub-metrics
results = wb.search("inflation") # Returns top 10 matches

for r in results[:3]:
    print(f"[{r['code']}] {r['name']}")
    # Output:
    # [FP.CPI.TOTL.ZG] Inflation, consumer prices (annual %)
    # [FP.CPI.TOTL] Consumer price index (2010 = 100)
    # [NY.GDP.DEFL.KD.ZG] Inflation, GDP deflator (annual %)

2. Robust Data Retrieval

Fetch data with automatic ID correction and intelligent time window handling.

# Fetch GDP Growth for USA, China, and Peru (Last 10 years)
df = wb.get_data(
    indicator="NY.GDP.MKTP.KD.ZG", 
    economies=["USA", "CHN", "PER"],
    years=10,
    labels=True,      # Adds 'Country Name' column
    as_frame=True     # Returns pandas DataFrame instead of JSON
)

print(df.head())

3. Advanced Analysis: Trends & Statistics

Quickly assess the economic trajectory of a country without writing boilerplate pandas code.

# Analyze the trend of Foreign Direct Investment in Chile
stats = wb.analyze_trend(
    indicator="BX.KLT.DINV.CD.WD", 
    economy="CHL", 
    years=20
)

# Returns a rich JSON with growth rates, volatility, and direction
# {
#   "statistics": {
#     "avg_annual_growth_pct": 5.2,
#     "volatility": 1240000000,
#     "trend_direction": "increasing"
#   }
# }

4. Professional Visualization

Generate Financial Times-style charts ready for publication.

# 1. Fetch Data
data = wb.get_data("NY.GDP.PCAP.CD", ["CHL", "PER", "COL", "MEX"], years=15)

# 2. Plot Trend
wb.plot(
    chart_type="trend", 
    data=data, 
    title="Pacific Alliance: GDP per Capita",
    subtitle="Current US$ (2010-2025)",
    save_path="pacific_gdp.png"
)

Usage Guide: For AI Agents (MCP)

This library implements the Model Context Protocol (MCP), allowing AI agents (like Claude or Custom GPTs) to autonomously interact with World Bank data using high-level tools.

1. Configuration (Claude Desktop)

Add the following to your claude_desktop_config.json:

{
  "mcpServers": {
    "worldbank": {
      "command": "uv",
      "args": [
        "--directory",
        "C:/path/to/mcp_wbgapi360",
        "run",
        "wbgapi360"
      ]
    }
  }
}

2. Available Tools

The Agent receives a toolkit optimized for economic reasoning:

Tool Description Signature
search_indicators Semantic search. Finds the best matching indicator codes. (query: str) -> List[Indicator]
get_data Fetches time-series data for analysis. (indicator_code: str, economies: List[str], years: int)
compare_countries Comparison logic. Fetches and normalizes data for multiple countries. (economies: List[str], indicators: List[str])
analyze_trend Returns statistical descriptive metadata (growth, volatility). (indicator: str, economy: str)
rank_countries Returns a sorted leaderboard for a given indicator. (indicator: str, region: str, top_n: int)
plot_chart Generates a visualization file from data. (chart_type: str, data: json)

3. Example Prompts

Once connected, you can ask the Agent complex economic questions:

"Compare the GDP growth volatility between Peru and Chile over the last 20 years. Who has been more stable?"

  • Agent Action: Calls analyze_trend for both countries and compares the volatility metric.

"Create a bar chart ranking the top 10 Latin American countries by Inflation."

  • Agent Action: Calls rank_countries(indicator="FP.CPI.TOTL.ZG", region="latam") then plot_chart(chart_type="bar", ...).

"Is there a correlation between Literacy Rate and GDP per Capita in Africa?"

  • Agent Action: Calls compare_countries with both indicators for African nations, then plot_chart(chart_type="scatter").

Visualization Gallery

The library supports specific chart types optimized for economic data:

Type Description Use Case
Trend Multi-line time series GDP Growth over time
Bar Horizontal ranked bars Comparing GINI index across countries
Column Vertical categorical bars Exports by region
Scatter Correlation plot Life Expectancy vs. GDP per Capita
Map Choropleth map Global population density (Requires geopandas)

Author

Maykol Medrano
Applied Economist Policy Data Scientist
Email: mmedrano2@uc.cl


License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wbgapi360-0.2.1.tar.gz (47.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wbgapi360-0.2.1-py3-none-any.whl (48.5 kB view details)

Uploaded Python 3

File details

Details for the file wbgapi360-0.2.1.tar.gz.

File metadata

  • Download URL: wbgapi360-0.2.1.tar.gz
  • Upload date:
  • Size: 47.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for wbgapi360-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5d58147a11f3d7f351b7a085b20a6a17ecb367afc3d9f05505ad38b1ba72c108
MD5 fd12629b452483bfddaca8bbc02155d1
BLAKE2b-256 d035502cd1675f1f1c760a3a37553933a88f0f1f393af4ff6fed4aeb51db71e7

See more details on using hashes here.

File details

Details for the file wbgapi360-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: wbgapi360-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 48.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for wbgapi360-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 06c96293dc3987f287694cddc9c9645e9231bfcb6a28f0b78962534715cdbac7
MD5 939f63241e99e189e86a889c1b53f534
BLAKE2b-256 84161241f5ed41d81e54387327b3daf0f8341627210a77967c2cda8ad4de8ba5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page