Skip to main content

WorldPopPy README

A Python client for downloading, merging, and processing WorldPop raster data.

WorldPopPy provides a programmatic interface to the WorldPop open data archive.

WorldPop offers global, gridded datasets on population dynamics, night-light emissions, topography, and much more. These datasets are typically distributed as individual files per country. WorldPopPy abstracts the process of data discovery, retrieval, and preprocessing. Users query data by Area of Interest (AoI). The library automatically identifies the necessary country rasters, downloads them, and merges them into a unified dataset. For an area that spans several countries, such as a river basin or a border region, a single call to wp_raster replaces finding, downloading, merging, and clipping country files by hand.

See the Example Gallery below for a visual overview of the library's capabilities.

Key Features

  • Fetch data for any region by passing country codes or names, bounding boxes, GeoDataFrames, shapely geometries, or vector files.
  • Built-in memory optimisations for massive country rasters: read only what your AoI needs, and process large areas lazily with Dask.
  • Easy handling of time-series through integration with xarray.
  • Provenance metadata on every result (source datasets, references, processing history).
  • Parallel data downloads with automatic retry logic, local caching, and dry-run support.
  • Searchable data manifest, allowing you to quickly find WorldPop products of interest.

Installation

pip install worldpoppy

Or, in a project managed with uv:

uv add worldpoppy

Quickstart

Example 1: Merging Population Rasters for Several Countries

import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm

from worldpoppy import wp_raster, clean_axes, plot_country_borders

# Fetch & Merge Data
# `wp_raster` returns an xarray.DataArray ready for analysis and plotting.
countries = ['THA', 'KHM', 'LAO', 'VNM']
pop_data = wp_raster(
    product_name='pop_g2_1km_r25a',  # Low-res. pop. estimates (Global 2 series)
    aoi=countries, years=2024
)

# Plot (Log-scale) 
# We use fillna(0) to represent areas without population and +1 to avoid log(0).
(pop_data.fillna(0) + 1).plot(norm=LogNorm(), cmap='inferno', size=6)

plot_country_borders(countries, edgecolor='white', linewidth=0.5)
clean_axes(title=f"Lower Mekong Region (2024):\n{pop_data.sum() / 1e6:.1f}M People")
plt.show()
Population in the Lower Mekong Region, 2024

Example 2: Built-in Support for Time-series

import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm

from worldpoppy import wp_raster, bbox_from_location, clean_axes

# Fetch Two Years of Night-light Data for Sihanoukville (Cambodia)
ntl_data = wp_raster(
    product_name="ntl_viirs_g2",
    aoi=bbox_from_location("Sihanoukville Special Economic Zone", width_km=45),
    years=['first', 'last']  # Request first & last available year 
)

# Plot: Xarray can create a facet grid by year
p = (ntl_data + 1).plot(
    col="year", figsize=(10, 5),
    subplot_kws={"facecolor": "#c8d3dc"},  # sea (no data) in light grey-blue
    cmap="inferno", vmax=50, norm=LogNorm(),
    add_colorbar=False  # Remove since radiance units are not intuitive
)

p.fig.suptitle('Night-light Growth in Sihanoukville', fontsize=12, fontweight='bold')
p.fig.subplots_adjust(top=0.875)
clean_axes(p)
plt.show()
Night lights in Sihanoukville, 2015-2023

1. Visualising Night Lights


Quickly fetch, merge, and reproject night-light data for North and South Korea.

2. Analysing Population Growth


Visualise 10-year population change along the coast of West Africa.

3. Exploring the Catalogue


Find all population products available for a country and compare them side by side.

4. Automatic Memory Optimisation


Use any shapely geometry as the AoI. Only the cells near it are read, reducing memory load for large country rasters (here: about 0.8 GB instead of 84 GB).

5. Manual Memory Optimisation


Manually pre-clip a country raster to any box, e.g. without remote islands (here: 2 GB instead of 10 GB).

6. Lazy Merging with Dask


Merge the elevation rasters of six countries lazily with Dask (here: an 11 GB grid in about 2.8 GB of memory).

Working with Results

wp_raster returns an xarray.DataArray with geospatial metadata (handled by rioxarray). Results can therefore be analysed with xarray and saved as a GeoTIFF:

pop_data.rio.to_raster("mekong_pop_2024.tif")

Results are always in the coordinate reference system of WorldPop's source rasters (WGS84, EPSG:4326), whatever the CRS of the area of interest. To reproject a result, use wp_warp. For counts such as population, use resampling='sum' to approximately preserve totals:

from worldpoppy import wp_warp

pop_warped = wp_warp(pop_data, to_crs="EPSG:32647", res=1_000, resampling="sum")

To combine results for different products or areas of interest (e.g., population and elevation), align one result to the other first:

elevation = elevation.rio.reproject_match(pop_data)

The cell coordinates of such results can differ by tiny floating-point amounts, and xarray, which matches cells by exactly equal coordinates, would silently drop the cells that differ.

Every result carries WorldPop's recommended citations, the licence, and a processing history in its attributes. Importantly, these attributes describe the result as returned by WorldPopPy. After you select data or compute new values with xarray, some attributes no longer match the data (e.g., after selecting one year of a multi-year result, wpy_years still lists all years). If you save such results, e.g. to pass the files on, update or drop these attributes first. The metadata guide describes all attributes, and the metadata example shows how to handle them.

Finding Data

To simplify data discovery, WorldPopPy organises WorldPop's thousands of raw files into curated data products with a consistent naming scheme. For example, pop_g2_r25a denotes population counts (pop) from WorldPop's Global 2 series (g2), 2025 alpha release (r25a). Products cover population counts, night lights, elevation, land cover, and climate variables, among others, and many are available for several years. Use show_supported_data_products for an overview, with a short description, the spatial resolution, and whether a data product covers several years or is static. The overview can be filtered by keyword, country, or year:

from worldpoppy import show_supported_data_products

# Print data products related to "population" from the Global 2 series 
show_supported_data_products(keywords=["population", "global2"])

# Print static (single-year) data products available for Brazil
show_supported_data_products(static_only=True, iso3_codes="BRA")

Alternatively, you can also get the library's full data manifest as a pandas DataFrame:

from worldpoppy import wp_manifest

mdf = wp_manifest()
mdf.head()

To see which years and countries a data product covers, use get_product_info:

from worldpoppy import get_product_info

info = get_product_info("ntl_viirs_g2")
sorted(info["years"])  # -> [2015, 2016, ..., 2023]

WorldPop organises its data by country, and WorldPopPy identifies countries by their three-letter ISO codes (ISO 3166-1 alpha-3, e.g., "KEN" for Kenya). These codes select countries in wp_raster, wp_manifest, show_supported_data_products, and plot_country_borders. To look up a country's code, search for (part of) its name. The result lists all matching countries, exact matches first:

from worldpoppy import find_country_code

find_country_code("ivory")
#   iso3           name matched_name
# 0  CIV  Côte d'Ivoire  Ivory Coast

wp_raster also accepts country names (e.g., aoi="Kenya") if they match exactly one country, and reports the code it used. Ambiguous names such as "Congo" raise an error that lists the candidates.

Documentation

Utilities

WorldPopPy includes helper functions to manage the local cache and download bandwidth.

1. Managing the Cache

Downloaded rasters are cached locally by default. You can change the location by setting the WORLDPOPPY_CACHE_DIR environment variable.

from worldpoppy import purge_cache, get_cache_dir

# Print the cache directory
print(get_cache_dir())

# Check the size of the local cache (deletes nothing; see 'total_size_mb')
print(purge_cache(dry_run=True))

# Delete all downloaded rasters (keeps the cached country borders)
purge_cache(dry_run=False)

# Delete everything, incl. the country borders (rebuilt automatically when needed)
purge_cache(dry_run=False, keep_country_borders=False)

2. Download Dry Run

To estimate the size of a request before downloading, use the download_dry_run flag:

from worldpoppy import wp_raster

# Prints a summary of files to be downloaded without fetching them
wp_raster(
    product_name='pop_g1', 
    aoi=['CAN', 'USA'], 
    years='all', 
    download_dry_run=True
)

Data Usage & Attribution

WorldPopPy is a client for accessing data; it does not host or own the data. WorldPopPy is an independent project and is not affiliated with or endorsed by WorldPop. Please note the following points regarding data provenance and citation:

  1. Curated "Product Names": The product names used by this library (e.g., pop_g1_alt or pop_g2_alt) are specific to WorldPopPy; WorldPop does not use them. When citing data, please refer to WorldPop's official dataset titles (see api_entry_title below).

  2. Know Your Data: While this library makes downloading and pre-processing easy, we strongly encourage you to understand what you are downloading. WorldPop datasets are often the result of complex modelling. Always check the summary_url provided in the manifest for details and further notes. To keep the load on WorldPop's servers low, WorldPopPy does not request the file listing of every raster dataset when building the manifest. Instead, we infer download and summary URLs from URL patterns, based on one sample dataset per data series, and only spot-check the results. If a summary link does not work, the official dataset title (api_entry_title) helps to find the page on WorldPop's website.

from worldpoppy import wp_manifest

# Select country entries for one "product" using its curated WorldPopPy alias
mdf = wp_manifest(product_name='pop_g2_alt', iso3_codes='AFG')

# Inspect the raw metadata for one raster file (sourced from the WorldPop API)
row = mdf.iloc[0]

print(f"Source File Name:       {row.dataset_name}")
print(f"Official Dataset Title: {row.api_entry_title}")
print(f"Official Data Category: {row.api_series_category}")
print(f"Dataset Summary:        {row.summary_url}")  # Read this before using data!
print("-----")

# > The internal fields below are for data discovery in WorldPopPy
print(f"Library Product Name:   {row.product_name}")
print(f"Multi-year Product?     {row.multi_year}")
print(f"Library Product Notes:  {row.product_notes}")
  1. Cite the Source: If you use this data, please cite its original creators (WorldPop). The scientific credit belongs to them. Note that the recommended citation style can differ between datasets, so be sure to check the summary_url for details.

Acknowledgements

WorldPopPy is inspired by the World Bank's BlackMarblePy package, which provided the blueprint for this library's download module and informed the API design.

Licence

This project is licensed under the Mozilla Public License. See LICENSE.txt for details.

Metadata

Release files for WorldPopPy 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for WorldPopPy 0.5.0
File Size Uploaded Provenance Actions
worldpoppy-0.5.0.tar.gz 7.8 MB Without provenance Details for worldpoppy-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for WorldPopPy 0.5.0
File Interpreter ABI Platform Actions
worldpoppy-0.5.0-py3-none-any.whl Python 3 none any Details for worldpoppy-0.5.0-py3-none-any.whl

Total release size: 15.5 MB

Release files / worldpoppy-0.5.0.tar.gz

Download URL worldpoppy-0.5.0.tar.gz
Size 7.8 MB
Tags Source
SHA-256 checksum
How to use checksums
62d9162b096aadfbacf4439b0c32650ee7dcf2314ead455b461a0008451be0af
BLAKE2b-256 checksum
How to use checksums
cf6445335f06484d3a5e4b1171b855965db5002335f1906ce7344535a3194136
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"21.3","id":"virginia","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / worldpoppy-0.5.0-py3-none-any.whl

Download URL worldpoppy-0.5.0-py3-none-any.whl
Size 7.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
82a669711842c01ac486e7687b6ed5a3792eae016f821894d4ffb928cef5d33c
BLAKE2b-256 checksum
How to use checksums
3f3daa2b05e6a53320c7d87cd13654625137129da71bc3a240bebc97ddcebf67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"21.3","id":"virginia","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for WorldPopPy 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page