Skip to content
Home Data API

Free population data API

Plain JSON files with the figures shown on Glostats: live population, 25 indicators, rankings and cities for 238 countries and territories. No key, no sign-up. Free to reuse with a link.

No keyJSON and MarkdownOpen to every site (CORS)Live-figure formulas included

What the API contains

Static files at https://glostats.com/api/v1/
FileContents
/api/v1/index.jsonList of files and indicators, licence, changelog
/api/v1/countries.jsonEvery country: codes, names, continent, live-population parameters
/api/v1/world.jsonWorld population and this year's births and deaths, with every country's parameters
/api/v1/country/{KEY}.jsonEvery indicator of one country: value, unit, year, type, source, rank
/api/v1/country/{KEY}.mdThe same as a short Markdown table
/api/v1/indicator/{slug}.jsonOne ranking: every country with value, year, type and rank
/api/v1/indicator/{slug}.mdThe same as a short Markdown table
/api/v1/cities/{KEY}.jsonThe cities of one country: latest figure with its date and source, live estimate

KEY is the three-letter ISO 3166 code in capitals (TUR, USA, IND). Northern Cyprus has none; its key is turkish_republic_of_cyprus. slug is the ranking's address on the site (population, life-expectancy, …).

The 25 indicators in the API
SlugIndicator
populationPopulation (people)
population-growth-ratePopulation growth rate (% per year)
population-densityPopulation density (people per km²)
areaSurface area (km²)
birth-rateBirth rate (per 1,000 people per year)
death-rateDeath rate (per 1,000 people per year)
net-migration-rateNet migration (people per year)
urban-populationUrban population (people)
sex-ratioSex ratio (males per 100 females)
life-expectancyLife expectancy (years)
fertility-rateFertility rate (births per woman)
median-ageMedian age (years)
infant-mortalityInfant mortality (deaths per 1,000 live births)
population-under-15Population under 15 (% of population)
population-over-65Population aged 65+ (% of population)
unemploymentUnemployment rate (% of labor force)
electricity-productionElectricity production (kWh per year)
electricity-consumptionElectricity consumption (kWh per year)
oil-productionOil production (barrels per day)
energy-use-per-capitaEnergy use per capita (kWh per person per year)
renewable-energyRenewable electricity share (% of electricity)
forest-areaForest area (km²)
agricultural-landAgricultural land (km²)
freshwater-per-capitaRenewable freshwater (m³ per year)
water-stressWater stress (% of available freshwater)

Not in the API yet: GDP, GDP per capita, Inflation rate, CO₂ emissions, CO₂ emissions per capita, Internet users, Mobile subscriptions. Reuse of their source data (IMF, EDGAR, ITU) by others has not been cleared yet; the figures stay on the ranking pages.

Fields

Every file starts with the same fields: api, generated, docs, license, license_url, attribution, file. Each figure then has these fields:

FieldMeaning
valuethe figure; for a live figure, its value at the moment given in generated
unitthe unit of the value
yearthe year the figure refers to (null for a long-term average)
typewhat kind of figure it is (see below)
sourcekeys of the sources; the file's sources object names each one with its address and licence
rank, ofthe place in the ranking and the number of countries ranked
publishedfor a figure we derive (a live count, this year's estimate): the published figure it starts from, with its unit and year
livehow the figure keeps moving: the kind of calculation and its parameter (see Live figures)
pagethe page on Glostats that shows the figure

Types of figures

TypeMeaning
live-estimateour second-by-second extrapolation of official figures
observationthe source's published figure for a past year
estimatea modelled or derived figure for a past year (the source's model, or ours from published parts)
projectionthe source's projection for the current year
trendour extrapolation of the source's last years where it has not published the year yet

Examples

Replace TUR with any other key

curl

# one country, every indicator (JSON)
curl -s https://glostats.com/api/v1/country/TUR.json

# one ranking as a Markdown table
curl -s https://glostats.com/api/v1/indicator/life-expectancy.md

JavaScript

// the live population of a country, for any moment, from its file
const d = await (await fetch("https://glostats.com/api/v1/country/TUR.json")).json();

function livePopulation(p, t = Date.now()) {
  const y = new Date(t).getUTCFullYear();
  const i = Math.min(Math.max(y - p.jan1_year, 0), p.jan1.length - 2);
  const a = Date.UTC(p.jan1_year + i, 0, 1), b = Date.UTC(p.jan1_year + i + 1, 0, 1);
  return Math.floor(p.jan1[i] + (p.jan1[i + 1] - p.jan1[i]) * (t - a) / (b - a));
}
console.log(livePopulation(d.live.population));
console.log(d.indicators["life-expectancy"]);   // { value, unit, year, type, source, rank, … }

Python

import json, math, time, urllib.request
from datetime import datetime, timezone

req = urllib.request.Request("https://glostats.com/api/v1/country/TUR.json",
                             headers={"User-Agent": "my-app/1.0"})
d = json.load(urllib.request.urlopen(req))

def live_population(p, t_ms=None):
    t_ms = int(time.time() * 1000) if t_ms is None else t_ms
    y = datetime.fromtimestamp(t_ms / 1000, timezone.utc).year
    i = min(max(y - p["jan1_year"], 0), len(p["jan1"]) - 2)
    a = datetime(p["jan1_year"] + i, 1, 1, tzinfo=timezone.utc).timestamp() * 1000
    b = datetime(p["jan1_year"] + i + 1, 1, 1, tzinfo=timezone.utc).timestamp() * 1000
    return math.floor(p["jan1"][i] + (p["jan1"][i + 1] - p["jan1"][i]) * (t_ms - a) / (b - a))

print(live_population(d["live"]["population"]))

Live figures

How the files let you compute a figure for any second

A live population is not a count. It is the UN World Population Prospects 2024 (medium variant) population on 1 January of each year, joined by straight lines and read for the current second:

P(t) = jan1[i] + (jan1[i+1] − jan1[i]) × (t − T(i)) / (T(i+1) − T(i))

Here i is the current year minus jan1_year, T(i) is 1 January of that year at 00:00 UTC, and the figure shown is P(t) rounded down. per_second is the same slope per second, for reference.

Men and women: men = total × sex_ratio ÷ (100 + sex_ratio), rounded to the nearest person; women are the rest.

Births and deaths since 1 January (UTC): the mean of the population on 1 January and now, times the rate per 1,000 divided by 1,000, times the share of the year that has passed; rounded down.

The world is the sum of the countries, each rounded down first; world.json has every country's parameters.

Ranking rows that tick carry a live object with the country's parameters: pop is the population, share the population × param, dens the population ÷ param (the area in km²), ytd a year's figure × the share of the year gone.

Cities

A city's live estimate is floor(b × P(t) / base_population): b is the city's part of the country on base_date, so the cities and the rest of the country always add up to the country. The latest official figure is given with its date and source.

Türkiye now, computed in your browser from TUR.json: 88,025,916

Our pages, the embeddable counters and these files use the same formulas, so they show the same number in the same second.

Terms of use

Free to use, also commercially. Credit Glostats with a link to the page or file you used, for example: Source: Glostats (https://glostats.com/country/turkey/)

Free to reuse with a link to the source page (terms). The source data keep their own licences; each file lists them under sources.

Do not present the figures as official statistics: live figures are estimates, and every figure comes with its year and type.

Please go easy on the server

The files are static and change only when our data is rebuilt. Cache them for a day and keep to a few requests per second: the bot protection of our CDN may block bursts. For many countries at once, read countries.json or one ranking file instead of hundreds of country files.

Versions and changes

Addresses and field names under /api/v1/ do not change. New fields may be added. A field that changes meaning or disappears means a new version, /api/v2/, and v1 stays available for at least a year after it.

Other ways to get the data