What the API contains
https://glostats.com/api/v1/| File | Contents |
|---|---|
/api/v1/index.json | List of files and indicators, licence, changelog |
/api/v1/countries.json | Every country: codes, names, continent, live-population parameters |
/api/v1/world.json | World population and this year's births and deaths, with every country's parameters |
/api/v1/country/{KEY}.json | Every indicator of one country: value, unit, year, type, source, rank |
/api/v1/country/{KEY}.md | The same as a short Markdown table |
/api/v1/indicator/{slug}.json | One ranking: every country with value, year, type and rank |
/api/v1/indicator/{slug}.md | The same as a short Markdown table |
/api/v1/cities/{KEY}.json | The 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
| Slug | Indicator |
|---|---|
population | Population (people) |
population-growth-rate | Population growth rate (% per year) |
population-density | Population density (people per km²) |
area | Surface area (km²) |
birth-rate | Birth rate (per 1,000 people per year) |
death-rate | Death rate (per 1,000 people per year) |
net-migration-rate | Net migration (people per year) |
urban-population | Urban population (people) |
sex-ratio | Sex ratio (males per 100 females) |
life-expectancy | Life expectancy (years) |
fertility-rate | Fertility rate (births per woman) |
median-age | Median age (years) |
infant-mortality | Infant mortality (deaths per 1,000 live births) |
population-under-15 | Population under 15 (% of population) |
population-over-65 | Population aged 65+ (% of population) |
unemployment | Unemployment rate (% of labor force) |
electricity-production | Electricity production (kWh per year) |
electricity-consumption | Electricity consumption (kWh per year) |
oil-production | Oil production (barrels per day) |
energy-use-per-capita | Energy use per capita (kWh per person per year) |
renewable-energy | Renewable electricity share (% of electricity) |
forest-area | Forest area (km²) |
agricultural-land | Agricultural land (km²) |
freshwater-per-capita | Renewable freshwater (m³ per year) |
water-stress | Water 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:
| Field | Meaning |
|---|---|
value | the figure; for a live figure, its value at the moment given in generated |
unit | the unit of the value |
year | the year the figure refers to (null for a long-term average) |
type | what kind of figure it is (see below) |
source | keys of the sources; the file's sources object names each one with its address and licence |
rank, of | the place in the ranking and the number of countries ranked |
published | for a figure we derive (a live count, this year's estimate): the published figure it starts from, with its unit and year |
live | how the figure keeps moving: the kind of calculation and its parameter (see Live figures) |
page | the page on Glostats that shows the figure |
Types of figures
| Type | Meaning |
|---|---|
live-estimate | our second-by-second extrapolation of official figures |
observation | the source's published figure for a past year |
estimate | a modelled or derived figure for a past year (the source's model, or ours from published parts) |
projection | the source's projection for the current year |
trend | our extrapolation of the source's last years where it has not published the year yet |
Examples
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
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.
- November 2026: first release.
Other ways to get the data
- CSV files of every ranking: CSV downloads.
- Live counters for your site: Embed a live counter.
- For AI assistants: llms.txt describes the site and these files in plain text.
- Errors or questions: Contact.