Turn data API results into a checked, shareable table
Use the World Bank data API to fetch population records, convert JSON to CSV, check coverage and publish a documented public table.

Suppose you need a public table of population estimates for Australia, Canada and New Zealand from 2020 through 2024. A data API lets you request those records directly, rather than copy figures from individual web pages.
The useful result is not just a successful request. It is a checked CSV with one row per country-year, clear units and enough source information for readers to interpret it. This workflow uses the World Bank API, then prepares the file for publication in TablePage.
What is a data API?
A data API is a programmatic interface for retrieving or submitting structured data. An endpoint is the address your program calls; parameters specify the slice you want, such as countries and years. The response might contain JSON records rather than spreadsheet cells.
For publishing, distinguish two jobs:
- Source API: retrieves the observations you want to publish.
- Publishing API: uploads or queries a dataset on a publishing service.
Here, the World Bank supplies the observations. TablePage supplies the reader-facing page. Fetching source data does not automatically refresh a published page: treat retrieval, review and publication as separate actions.
1. Define the table before requesting data
Use this output structure:
| Column | Meaning |
|---|---|
country_code |
Three-letter country code |
country |
Country name |
year |
Observation year |
population |
Midyear population estimate, in persons |
The World Bank indicator SP.POP.TOTL, “Population, total,” counts residents regardless of legal status or citizenship and reports midyear estimates. It is not a count of citizens or an end-of-year population. Its indicator metadata also describes its providers and estimation limitations.
For three countries and five years, expect 15 distinct country-year records. A record with a missing value should remain visible as missing, not become zero.
2. Request the records and write a CSV
The World Bank’s V2 Indicators API requires no API key. Its documentation supports semicolon-separated country selections, colon-separated date ranges, JSON output and pagination through page and per_page. The default page size is 50 records. See API access and request parameters.
Save this as population_export.py and run it with python3 population_export.py. It uses only Python’s standard library.
import csv
import json
from datetime import datetime, timezone
from pathlib import Path
from urllib.request import urlopen
url = (
"https://api.worldbank.org/v2/country/can;aus;nzl/"
"indicator/SP.POP.TOTL"
"?date=2020:2024&format=json&per_page=100&source=2"
)
with urlopen(url, timeout=30) as response:
raw = response.read().decode("utf-8")
Path("population-response.json").write_text(raw, encoding="utf-8")
metadata, records = json.loads(raw)
if int(metadata["pages"]) != 1:
raise ValueError("More pages exist; retrieve them before exporting.")
if not records or len(records) != int(metadata["total"]):
raise ValueError("Unexpected record count.")
rows = [
[r["countryiso3code"], r["country"]["value"],
int(r["date"]), "" if r["value"] is None else r["value"]]
for r in records
]
expected = {(c, y) for c in ("AUS", "CAN", "NZL")
for y in range(2020, 2025)}
if len(rows) != 15 or {(r[0], r[2]) for r in rows} != expected:
raise ValueError("Duplicate or missing country-year records.")
with open("population.csv", "w", newline="", encoding="utf-8") as file:
writer = csv.writer(file)
writer.writerow(["country_code", "country", "year", "population"])
writer.writerows(sorted(rows, key=lambda r: (r[0], r[2])))
print("Retrieved UTC:", datetime.now(timezone.utc).isoformat())
print("Source last updated:", metadata.get("lastupdated"))
print("Wrote", len(rows), "rows to population.csv")
The response contains pagination metadata followed by observations. The script flattens the nested country fields, preserves null population values as blank cells and sorts the output explicitly. The API does not let callers control result ordering, according to its documentation.
This is deliberately a small, single-page export. If you expand the query and the pagination check fails, retrieve every page before writing the CSV; increasing the page size alone is not a completeness check.
3. Check the values and document the snapshot
As of October 29, 2026, the example API response contained 15 records and reported a source update date of October 8, 2026. Its 2024 values were:
| Country | Population, 2024 |
|---|---|
| Australia | 27,194,286 |
| Canada | 41,262,329 |
| New Zealand | 5,290,000 |
These are dated reference values, not fixed expectations for future downloads. Before publishing, check that population cells contain nonnegative numbers or documented blanks. Confirm that the CSV still has 15 data rows, separate from its header.
Keep the raw JSON, CSV, request parameters and retrieval timestamp together. The observation year, source update date and your retrieval date describe different things.
For the public description, record:
- Coverage: Australia, Canada and New Zealand; 2020–2024; one row per country-year.
- Measure: total resident population, midyear estimates, persons.
- Source: The World Bank, World Development Indicators,
SP.POP.TOTL, with the providers listed in the indicator metadata. - Changes made: selected countries and years, renamed columns and sorted rows; blanks represent unavailable values.
The indicator metadata lists CC BY-4.0. Include attribution, links to the metadata and World Bank reuse terms, and disclose your transformations. Those terms require acknowledgment of the World Bank and its data providers; access through an API is not a substitute for checking reuse rights.
4. Publish the reviewed file
TablePage supports CSV, TSV, XLSX and XLS uploads and generates a public dataset page with a filterable table. Upload the reviewed population.csv, then inspect the resulting page: verify the headers, country labels, year values, row count and missing-value handling before sharing its link.
Provide the source and definition notes alongside the shared table. Publish only data cleared for public release—never sensitive records or credentials.
If you later automate publication, keep the same review checks between retrieval and upload. Use the API usage guide for the publishing side and API change checks before refreshing an existing dataset.