Skip to main content

Official Python SDK for Statistics of the World — free API for 490+ global economic indicators, 218 countries, 20+ years of history.

Project description

statisticsoftheworld

Official Python SDK for Statistics of the World — free API for 490+ global economic indicators across 218 countries with 20+ years of history.

Data sourced from IMF, World Bank, FRED, UN, and more.

Install

pip install statisticsoftheworld

With pandas support:

pip install statisticsoftheworld[pandas]

Quick Start

from sotw import SOTW

sotw = SOTW()

# List all countries
countries = sotw.countries()
for c in countries["data"][:5]:
    print(c["id"], c["name"])

# Get all indicators for Canada
canada = sotw.country("CAN")
for ind in canada["indicators"][:5]:
    print(ind["id"], ind["value"])

# GDP rankings — top 10
top10 = sotw.rankings("IMF.NGDPD", limit=10)
for entry in top10["data"]:
    print(f"#{entry['rank']} {entry['country']}: ${entry['value']:,.0f}")

# Historical GDP for Canada
history = sotw.history("IMF.NGDPD", "CAN")
for row in history["data"][-5:]:
    print(row["year"], row["value"])

Pandas Integration

from sotw import SOTW

sotw = SOTW()

# Historical data as DataFrame
df = sotw.history_df("IMF.NGDPD", "CAN")
print(df.tail())
#    year          value
# 20  2020  1.644037e+12
# 21  2021  2.001000e+12
# ...

# Rankings as DataFrame
df = sotw.rankings_df("SP.POP.TOTL", limit=10)
print(df)
#    rank countryId       country        value
# 0     1       CHN         China  1425893000.0
# 1     2       IND         India  1428628000.0
# ...

# All indicators for a country
df = sotw.country_df("USA")
print(df[["id", "value"]].head())

API Key (Optional)

Without a key you get 1,000 requests/day. For higher limits, get a free key at statisticsoftheworld.com/pricing:

sotw = SOTW(api_key="sotw_your_key_here")

API Reference

SOTW(api_key=None, base_url=None)

Create a new client.

Methods

Method Description
sotw.countries() List all 218 countries
sotw.country(id) Get a country with all indicator values
sotw.indicators() List all 490+ indicators
sotw.indicator(id) Get an indicator ranked across all countries
sotw.history(indicator, country) Get 20+ years of historical data
sotw.rankings(indicator, limit=None) Get countries ranked by indicator
sotw.history_df(indicator, country) Historical data as pandas DataFrame
sotw.rankings_df(indicator, limit=None) Rankings as pandas DataFrame
sotw.country_df(country_id) Country indicators as pandas DataFrame

Common Indicator IDs

ID Indicator
IMF.NGDPD GDP (nominal, USD)
SP.POP.TOTL Population
IMF.PCPIPCH Inflation rate (%)
SL.UEM.TOTL.ZS Unemployment rate (%)
SP.DYN.LE00.IN Life expectancy
NY.GDP.PCAP.CD GDP per capita

Links

License

MIT

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

statisticsoftheworld-1.0.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

statisticsoftheworld-1.0.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file statisticsoftheworld-1.0.0.tar.gz.

File metadata

  • Download URL: statisticsoftheworld-1.0.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for statisticsoftheworld-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2cdf497fa53f79f95767a86a875c2c536b0cdc2a9b1ebbd729d7a10ba7f0a5a1
MD5 15038c8a2b9a92bb2fee1fdeac0480ec
BLAKE2b-256 051ba772f797fe1d0f4e967fe2f8fe65df9b3bc71be3fad4b0664ca87cbedc10

See more details on using hashes here.

File details

Details for the file statisticsoftheworld-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for statisticsoftheworld-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e46960bc428403114db20a093b0a54ceac7fa9c9354b0b3fd5ccedb837b30b1
MD5 0edb86e2429e860824b0cf99adf61c28
BLAKE2b-256 6fa711130a9b3249ee84165cde039acd13dec410a505c31ed602c5b5cff0d817

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