API Access
Access dataset files directly from scripts, code, or AI agents.
Browse dataset files
API Access
Access dataset files directly from scripts, code, or AI agents.
Each file has a stable URL (r-link) that you can use directly in scripts, apps, or AI agents. These URLs are permanent and safe to hardcode.
Start with these files — they give you everything you need to understand and access the dataset.
- 1. Fetch datapackage.json to inspect schema and resources
- 2. Download data resources listed in datapackage.json
- 3. Read README.md for full context
Data Files
Explore with AIunsd-citypopulation-year-both
| Field | Type | Description |
|---|---|---|
| Country or Area | string | Country or area, as named by the UN. |
| Year | integer | Reference year of the figure. |
| Area | string | Part of the city covered, for example Total. |
| Sex | string | Both Sexes in the first file; Female or Male in the second. |
| City | string | City name, as given by the UN (often in capitals). |
| City type | string | City proper or Urban agglomeration. |
| Record Type | string | Kind of record, for example Estimate - de jure or Census - de facto - complete tabulation. |
| Reliability | string | Reliability of the figure, for example Final figure, complete or Provisional figure. |
| Source Year | integer | Year of the source the figure was taken from. |
| Value | number | Population. A few figures have a decimal part. |
| Value Footnotes | string | Footnote numbers for this figure, separated by commas (for example 4,5); empty when there is none. The numbers are explained in the footnotes file that goes with the data file. |
Download
Download CSVAbout
- City population for both sexes, one row per figure.
- Last updated
- 15 October 2026
- Total rows
- ...
- Format
- CSV
- File size
- 4.63 MB
unsd-citypopulation-year-both-footnotes
| Field | Type | Description |
|---|---|---|
| footnoteSeqID | string | Footnote number, as used in the Value Footnotes column of the matching data file. |
| Footnote | string | Text of the footnote. |
Download
Download CSVAbout
- Footnotes for the figures in unsd-citypopulation-year-both.csv.
- Last updated
- 15 October 2026
- Total rows
- ...
- Format
- CSV
- File size
- 28.9 kB
unsd-citypopulation-year-fm
| Field | Type | Description |
|---|---|---|
| Country or Area | string | Country or area, as named by the UN. |
| Year | integer | Reference year of the figure. |
| Area | string | Part of the city covered, for example Total. |
| Sex | string | Both Sexes in the first file; Female or Male in the second. |
| City | string | City name, as given by the UN (often in capitals). |
| City type | string | City proper or Urban agglomeration. |
| Record Type | string | Kind of record, for example Estimate - de jure or Census - de facto - complete tabulation. |
| Reliability | string | Reliability of the figure, for example Final figure, complete or Provisional figure. |
| Source Year | integer | Year of the source the figure was taken from. |
| Value | number | Population. A few figures have a decimal part. |
| Value Footnotes | string | Footnote numbers for this figure, separated by commas (for example 4,5); empty when there is none. The numbers are explained in the footnotes file that goes with the data file. |
Download
Download CSVAbout
- City population for females and males, one row per figure.
- Last updated
- 15 October 2026
- Total rows
- ...
- Format
- CSV
- File size
- 7.33 MB
unsd-citypopulation-year-fm-footnotes
| Field | Type | Description |
|---|---|---|
| footnoteSeqID | string | Footnote number, as used in the Value Footnotes column of the matching data file. |
| Footnote | string | Text of the footnote. |
Download
Download CSVAbout
- Footnotes for the figures in unsd-citypopulation-year-fm.csv.
- Last updated
- 15 October 2026
- Total rows
- ...
- Format
- CSV
- File size
- 27.5 kB
About this dataset
City population
Population of cities by year, for both sexes and for females and males, from the UN Statistics Division (UNSD Demographic Statistics). The figures come from national statistical offices through the UN Demographic Yearbook.
Column definitions and types are in datapackage.json.
Data
data/unsd-citypopulation-year-both.csvhas the figures for both sexes.data/unsd-citypopulation-year-fm.csvhas the figures for females and males, one row each.- Each data file has a footnotes file next to it:
data/unsd-citypopulation-year-both-footnotes.csvanddata/unsd-citypopulation-year-fm-footnotes.csv.
Columns of the two data files:
| Column | Meaning |
|---|---|
Country or Area | Country or area, as named by the UN, for example Åland Islands |
Year | Reference year of the figure |
Area | Part of the city covered, for example Total |
Sex | Both Sexes in the first file; Female or Male in the second |
City | City name as given by the UN, often in capitals, for example MARIEHAMN |
City type | City proper or Urban agglomeration |
Record Type | Kind of record, for example Estimate - de jure or Census - de facto - complete tabulation |
Reliability | For example Final figure, complete or Provisional figure |
Source Year | Year of the source the figure was taken from |
Value | Population. A few figures have a decimal part, for example 11911.5 |
Value Footnotes | Footnote numbers for the figure, separated by commas (for example 4,5). Empty when there is none |
Columns of the footnotes files: footnoteSeqID (the footnote number) and Footnote (its text).
Known limitations
- The same city can have several rows for the same year, from different sources. They differ in
Record Type,ReliabilityorSource Year. Choose one before you count or compare. - A city can be listed both as
City properand asUrban agglomeration. The agglomeration normally includes the city proper, so adding the two counts people twice. - Footnote numbers belong to one file. Number
4in the first file does not mean the same as number4in the second. The UN can also number its footnotes differently each time the data is exported, so a number can change when the data is rebuilt. Always use the footnotes file that was committed with the data file. Value Footnotescan hold several numbers in one cell (4,5). Split it on commas before you look the numbers up.- All fields are in quotes and lines end with a carriage return and a line feed (
\r\n), as in the UN export. Any CSV reader handles this. - With pandas:
pd.read_csv("data/unsd-citypopulation-year-both.csv").Year,Source YearandValueare numbers.
Data sources
- UN data: UNSD Demographic Statistics, table "City population by sex, city and city type". It provides all figures and footnotes. Licence: the UN data conditions of use. They say all data and metadata may be copied freely, duplicated and further distributed, provided UN data is cited as the reference.
Changes made to the source data: the UN export has a table of footnotes at its end. The update script moves that table into its own footnotes file. Nothing else in the figures is changed.
Not endorsed by, or affiliated with, the United Nations.
Preparation
You need Python 3.12 or greater. To rebuild the data from the repository root:
pip install -r scripts/requirements.txt
python scripts/process.py
The script downloads the two tables from UN data, moves the footnotes into their own files and records the date of the last UN update in last_updated in datapackage.json. It stops with an error if the UN site does not return the files it expects.
A GitHub workflow runs the script on the first day of January, March, May, July, September and November, and when started by hand. It commits data/ and datapackage.json if they changed.
The data is also published on datahub.io.
License
The UN data conditions of use allow the figures and footnotes to be copied, duplicated and further distributed free of charge, as long as UN data is cited as the reference. See ATTRIBUTION.txt.
The maintainers offer this package under the Open Data Commons Public Domain Dedication and License (PDDL) 1.0. That applies to their own work: the update script, the column definitions and the file layout. It does not replace the UN conditions of use.