dr5hn/countries-states-cities-database

🌍 Discover our global repository of countries, states, and cities! 🏙️ Get comprehensive data in JSON, SQL, PSQL, SQLSERVER, MONGODB, SQLITE, XML, YAML, and CSV formats. Access ISO2, ISO3 codes, country code, capital, native language, timezones (for countries), and more. #countries #states #cities

Python

9,863

1,337 commits

updated Oct 12, 2026

See the code

README

banner

Countries States Cities Database

A comprehensive, community-maintained dataset of countries, states, counties, cities, and postcodes — published in 12 formats and free under the Open Database License (attribution required).

License: ODbL-1.0 GitHub stars release NPM PyPI

Total Regions : 6
Total Sub Regions : 22
Total Countries : 250
Total States/Regions/Municipalities : 5,299
Total Cities/Towns/Districts : 153,765
Total Postcodes : 844248 (125 countries)
Total Timezones : 427 (100% IANA coverage)
Last Updated On: October 10, 2026


Build & Launch Websites Faster with MakeMySiteLive Finding a remote job? Go check remotegig.in


The two managed products below are the fastest path to shipping. They're actively maintained, billed for sustainability, and back the rest of the ecosystem.

REST API — api.countrystatecity.in

Query countries, states, cities, and postcodes from any language. Free tier for prototyping; paid tiers for production.

curl https://api.countrystatecity.in/v1/countries/IN/states/MH/cities \
  -H "X-CSCAPI-KEY: $YOUR_API_KEY"

Python applications can use the official sync and async client:

pip install countrystatecity-api
export CSC_API_KEY="YOUR_API_KEY"
from countrystatecity import CountryStateCity

with CountryStateCity() as client:
    states = client.get_states_of_country("IN")
    print([state["name"] for state in states[:3]])

Get a free API key → · Compare plans · Documentation · Interactive playground · OpenAPI spec · Status

Export Tool — export.countrystatecity.in

Build tailored datasets in your browser — pick country, region, format, and field selection, then download.

Launch the Export Tool →


Other ways to use the data

NPM (JavaScript / TypeScript)
PackageGitHubNPM
@countrystatecity/countriesGitHubnpmjs.com
@countrystatecity/countries-browserGitHubnpmjs.com
@countrystatecity/currenciesGitHubnpmjs.com
@countrystatecity/timezonesGitHubnpmjs.com
@countrystatecity/translationsGitHubnpmjs.com
@countrystatecity/cliGitHubnpmjs.com
PyPI (Python)

Use countrystatecity-api for live, managed data. The suffixed packages are versioned offline snapshots.

PackageUseGitHubPyPI
countrystatecity-apiLive REST API clientGitHubpypi.org
countrystatecity-countriesOffline snapshotGitHubpypi.org
countrystatecity-timezonesOffline snapshotGitHubpypi.org
countrystatecity-currenciesOffline snapshotGitHubpypi.org
countrystatecity-translationsOffline snapshotGitHubpypi.org
countrystatecity-phonecodesOffline snapshotGitHubpypi.org
countrystatecity-regionsOffline snapshotGitHubpypi.org
countrystatecity-postal-codesOffline snapshotGitHubpypi.org
Direct download (gzipped exports)

Countries, states, counties, cities, and postcodes are separate datasets. Counties contain official intermediate administrative units; cities can link to them through a nullable county_id. See the county field shape and link rules.

Every format ships as a .gz asset on each GitHub Release.

curl -LO https://github.com/dr5hn/countries-states-cities-database/releases/latest/download/json-cities.json.gz
gunzip json-cities.json.gz
curl -LO https://github.com/dr5hn/countries-states-cities-database/releases/latest/download/json-counties.json.gz
gunzip json-counties.json.gz

Smaller reference files (countries, states, counties, schema) live in the repo. Use git clone --depth 1 for a fast clone.

Other packages and platforms

What's in the data

  • 250 countries · 5,329 states / regions · 8,366 counties · 153,513 cities · 840k+ postcodes across 125 countries
  • 19 languages of country and state names plus native script
  • 100% IANA timezone coverage for cities
  • Validated foreign keys on every contribution
  • Formats: JSON, MySQL, PostgreSQL, SQLite, SQL Server, MongoDB, XML, YAML, CSV, GeoJSON, TOON (LLM-optimised, ~40% fewer tokens than JSON), Parquet (columnar, analytics-ready)
FormatExport timeSizeCompressed
CSV1s40 MB9 MB
MongoDB dump1s30 MB20 MB
MySQL SQL3s86 MB22 MB
JSON4s271 MB18 MB
TOON5s23 MB20 MB
Parquet7s31 MB27 MB
GeoJSON8s208 MB24 MB
XML9s91 MB15 MB
YAML17s68 MB—
SQLite45s89 MB—

Contributing

The easiest way is the Community Manager — submit corrections through a web UI with end-to-end tracking.

To edit JSON directly:

  1. Fork and clone (git clone --depth 1).
  2. Edit files under contributions/cities/, contributions/states/, contributions/countries/, contributions/counties/, or contributions/postcodes/.
  3. Required for new cities: name, state_id, state_code, country_id, country_code, latitude, longitude. Optional: timezone, wikiDataId, native.
  4. Omit id, created_at, updated_at, flag — auto-managed on import.
  5. Open a pull request with a clear data source.
{
  "name": "San Francisco",
  "state_id": 1416,
  "state_code": "CA",
  "country_id": 233,
  "country_code": "US",
  "latitude": "37.77493",
  "longitude": "-122.41942",
  "timezone": "America/Los_Angeles",
  "wikiDataId": "Q62"
}

Contributions guide · Contribution guidelines · Multi-level territories policy · Administrative structure policy · The cities.type field

Don't edit the auto-generated directories (json/, csv/, xml/, yml/, sql/, etc.). They're rebuilt from MySQL on every release.


License and attribution

Licensed under the Open Database License (ODbL v1.0). Commercial use, modification, and redistribution all permitted. Attribution is required, and derivatives must be shared under the same license.

Data by Countries States Cities Database
https://github.com/dr5hn/countries-states-cities-database | ODbL v1.0

Support

If this project saves you time, please consider supporting its continued maintenance.

Sponsor on GitHub Buy a coffee

You can also plant a tree on behalf of the project.

Reach out: gadadarshan [at] gmail [dot] com

GitHub @dr5hn Twitter @dr5hn LinkedIn @dr5hn

Sponsors

Disclaimer

Community-maintained data may contain errors or lag behind geopolitical changes. Verify critical data with official sources. Report issues.


Repo Activity

Thanks to our contributors.

cities
countries
country
csv
geographical-data
psql
regions
state
states
world

dr5hn/countries-states-cities-database

🌍 Discover our global repository of countries, states, and cities! 🏙️ Get comprehensive data in JSON, SQL, PSQL, SQLSERVER, MONGODB, SQLITE, XML, YAML, and CSV formats. Access ISO2, ISO3 codes, country code, capital, native language, timezones (for countries), and more. #countries #states #cities

Python

9,863

1,337 commits

updated Oct 12, 2026

See the code

README

banner

Countries States Cities Database

A comprehensive, community-maintained dataset of countries, states, counties, cities, and postcodes — published in 12 formats and free under the Open Database License (attribution required).

License: ODbL-1.0 GitHub stars release NPM PyPI

Total Regions : 6
Total Sub Regions : 22
Total Countries : 250
Total States/Regions/Municipalities : 5,299
Total Cities/Towns/Districts : 153,765
Total Postcodes : 844248 (125 countries)
Total Timezones : 427 (100% IANA coverage)
Last Updated On: October 10, 2026


Build & Launch Websites Faster with MakeMySiteLive Finding a remote job? Go check remotegig.in


The two managed products below are the fastest path to shipping. They're actively maintained, billed for sustainability, and back the rest of the ecosystem.

REST API — api.countrystatecity.in

Query countries, states, cities, and postcodes from any language. Free tier for prototyping; paid tiers for production.

curl https://api.countrystatecity.in/v1/countries/IN/states/MH/cities \
  -H "X-CSCAPI-KEY: $YOUR_API_KEY"

Python applications can use the official sync and async client:

pip install countrystatecity-api
export CSC_API_KEY="YOUR_API_KEY"
from countrystatecity import CountryStateCity

with CountryStateCity() as client:
    states = client.get_states_of_country("IN")
    print([state["name"] for state in states[:3]])

Get a free API key → · Compare plans · Documentation · Interactive playground · OpenAPI spec · Status

Export Tool — export.countrystatecity.in

Build tailored datasets in your browser — pick country, region, format, and field selection, then download.

Launch the Export Tool →


Other ways to use the data

NPM (JavaScript / TypeScript)
PackageGitHubNPM
@countrystatecity/countriesGitHubnpmjs.com
@countrystatecity/countries-browserGitHubnpmjs.com
@countrystatecity/currenciesGitHubnpmjs.com
@countrystatecity/timezonesGitHubnpmjs.com
@countrystatecity/translationsGitHubnpmjs.com
@countrystatecity/cliGitHubnpmjs.com
PyPI (Python)

Use countrystatecity-api for live, managed data. The suffixed packages are versioned offline snapshots.

PackageUseGitHubPyPI
countrystatecity-apiLive REST API clientGitHubpypi.org
countrystatecity-countriesOffline snapshotGitHubpypi.org
countrystatecity-timezonesOffline snapshotGitHubpypi.org
countrystatecity-currenciesOffline snapshotGitHubpypi.org
countrystatecity-translationsOffline snapshotGitHubpypi.org
countrystatecity-phonecodesOffline snapshotGitHubpypi.org
countrystatecity-regionsOffline snapshotGitHubpypi.org
countrystatecity-postal-codesOffline snapshotGitHubpypi.org
Direct download (gzipped exports)

Countries, states, counties, cities, and postcodes are separate datasets. Counties contain official intermediate administrative units; cities can link to them through a nullable county_id. See the county field shape and link rules.

Every format ships as a .gz asset on each GitHub Release.

curl -LO https://github.com/dr5hn/countries-states-cities-database/releases/latest/download/json-cities.json.gz
gunzip json-cities.json.gz
curl -LO https://github.com/dr5hn/countries-states-cities-database/releases/latest/download/json-counties.json.gz
gunzip json-counties.json.gz

Smaller reference files (countries, states, counties, schema) live in the repo. Use git clone --depth 1 for a fast clone.

Other packages and platforms

What's in the data

  • 250 countries · 5,329 states / regions · 8,366 counties · 153,513 cities · 840k+ postcodes across 125 countries
  • 19 languages of country and state names plus native script
  • 100% IANA timezone coverage for cities
  • Validated foreign keys on every contribution
  • Formats: JSON, MySQL, PostgreSQL, SQLite, SQL Server, MongoDB, XML, YAML, CSV, GeoJSON, TOON (LLM-optimised, ~40% fewer tokens than JSON), Parquet (columnar, analytics-ready)
FormatExport timeSizeCompressed
CSV1s40 MB9 MB
MongoDB dump1s30 MB20 MB
MySQL SQL3s86 MB22 MB
JSON4s271 MB18 MB
TOON5s23 MB20 MB
Parquet7s31 MB27 MB
GeoJSON8s208 MB24 MB
XML9s91 MB15 MB
YAML17s68 MB—
SQLite45s89 MB—

Contributing

The easiest way is the Community Manager — submit corrections through a web UI with end-to-end tracking.

To edit JSON directly:

  1. Fork and clone (git clone --depth 1).
  2. Edit files under contributions/cities/, contributions/states/, contributions/countries/, contributions/counties/, or contributions/postcodes/.
  3. Required for new cities: name, state_id, state_code, country_id, country_code, latitude, longitude. Optional: timezone, wikiDataId, native.
  4. Omit id, created_at, updated_at, flag — auto-managed on import.
  5. Open a pull request with a clear data source.
{
  "name": "San Francisco",
  "state_id": 1416,
  "state_code": "CA",
  "country_id": 233,
  "country_code": "US",
  "latitude": "37.77493",
  "longitude": "-122.41942",
  "timezone": "America/Los_Angeles",
  "wikiDataId": "Q62"
}

Contributions guide · Contribution guidelines · Multi-level territories policy · Administrative structure policy · The cities.type field

Don't edit the auto-generated directories (json/, csv/, xml/, yml/, sql/, etc.). They're rebuilt from MySQL on every release.


License and attribution

Licensed under the Open Database License (ODbL v1.0). Commercial use, modification, and redistribution all permitted. Attribution is required, and derivatives must be shared under the same license.

Data by Countries States Cities Database
https://github.com/dr5hn/countries-states-cities-database | ODbL v1.0

Support

If this project saves you time, please consider supporting its continued maintenance.

Sponsor on GitHub Buy a coffee

You can also plant a tree on behalf of the project.

Reach out: gadadarshan [at] gmail [dot] com

GitHub @dr5hn Twitter @dr5hn LinkedIn @dr5hn

Sponsors

Disclaimer

Community-maintained data may contain errors or lag behind geopolitical changes. Verify critical data with official sources. Report issues.


Repo Activity

Thanks to our contributors.

cities
countries
country
csv
geographical-data
psql
regions
state
states
world

Project health

Overall

3.8/10

Maintained

10/10

Code review

0/10
OpenSSF Scorecard

Significant stargazers

(top 24 of 36)

Jesse Gumm

121 followers · starred Dec 2024

Aleen

405 followers · starred Aug 2024

Joao Grassi

134 followers · starred Nov 2021

Andrew Chen Wang

118 followers · starred Mar 2025