Downloads
25,185
Last updated
Data file
1
Size
1.34 MB
Format
csv
License
CC-BY-4.0

world-cities

List of major cities of the world (more than 15,000 inhabitants, plus capitals and seats of government of any size), from GeoNames. Each city is identified by its name, country, first-level region (subcountry) and GeoNames id.

badge

Major cities of the world

A list of the major cities of the world, with the country and the first-level region each city is in. The data comes from GeoNames.

Column definitions and types are in datapackage.json.

Data

data/world-cities.csv has one row per city. It lists cities with more than 15,000 inhabitants, plus capitals and seats of government, which can be smaller (for example Hamilton, the capital of Bermuda).

ColumnMeaning
nameName of the city (the GeoNames name, in UTF-8, so it can contain accents and non-Latin letters), for example Düsseldorf
countryCountry name. These are the ISO 3166-1 official short names, for example Russian Federation, Viet Nam, Bolivia, Plurinational State of. Kosovo is added by the script
subcountryName of the first-level region of the country, in ASCII, for example North Rhine-Westphalia. This is a state in the United States, and the major administrative area in other countries. See admin1 on the GeoNames website
geonameidGeoNames id of the city. This is the primary key

Known limitations

  • subcountry is empty for cities that have no first-level region in GeoNames. This includes cities that are a whole state, such as Singapore and Vatican City. It is empty, not N/A. By default pandas reads an empty cell as missing (NaN). To keep empty strings instead: pd.read_csv("data/world-cities.csv", keep_default_na=False).
  • The name of a city is not unique within a country and subcountry. Some combinations of country, subcountry and name appear more than once. Use geonameid to identify a city.
  • country uses the ISO names, which are not always the everyday names. For example Vatican City is Holy See (Vatican City State).

Data sources

Changes made to the source data: from cities15000.txt the script keeps only the name, the GeoNames id, the country and the first-level region. The country code is replaced by the country name from pycountry. The first-level region code is replaced by the region's ASCII name from admin1CodesASCII.txt. All other columns (coordinates, population, alternate names, time zone and so on) are removed. The name Kosovo is added by the script for the GeoNames code XK, which pycountry does not know.

Not endorsed by, or affiliated with, GeoNames, pycountry or the iso-codes project.

Preparation

Python 3.12 .github/workflows/actions.yml

The script needs Python 3.12 and the packages in scripts/requirements.txt (requests, pycountry, pandas and frictionless). Install them and run the script from the repository root:

pip install -r scripts/requirements.txt
python scripts/process.py

The script downloads the two GeoNames files and writes data/world-cities.csv.

A GitHub workflow rebuilds the data on the 1st of every month (at 00:00 UTC) and on every push to main. It validates datapackage.json with Frictionless and commits data/world-cities.csv if it changed.

License

The city data comes from GeoNames and is licensed under the Creative Commons Attribution 4.0 International License. If you use it, credit GeoNames with a link, say which licence applies, and say that the data was changed (see the changes listed under Data sources). GeoNames provides the data "as is" without warranty or any representation of accuracy, timeliness or completeness. A link back or credit to Lexman and the Open Knowledge Foundation is also appreciated. See also ATTRIBUTION.txt.

The country names come from pycountry, which is licensed under the LGPL-2.1 and includes iso-codes data (LGPL-2.1-or-later). ISO says its publications are protected by copyright. We could not establish whether this affects short country names, and the LGPL is a software licence. We found nothing that puts LGPL terms on this CSV, so we think the risk is low, but the position is unclear.

All source code is licensed under the MIT licence.

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.

  1. Fetch datapackage.json to inspect schema and resources
  2. Download data resources listed in datapackage.json
  3. Read README.md for full context
/core/world-cities/7 files
  • .gitattributeshttps://datahub.io/core/world-cities/_r/-/.gitattributes
  • .gitignorehttps://datahub.io/core/world-cities/_r/-/.gitignore
  • ATTRIBUTION.txthttps://datahub.io/core/world-cities/_r/-/ATTRIBUTION.txt
  • LICENSEhttps://datahub.io/core/world-cities/_r/-/LICENSE
  • README.mddocumentationhttps://datahub.io/core/world-cities/_r/-/README.md
  • data/world-cities.csvhttps://datahub.io/core/world-cities/_r/-/data/world-cities.csv
  • datapackage.jsonmetadata & schemahttps://datahub.io/core/world-cities/_r/-/datapackage.json