dr5hn/countries-states-cities-database
dr5hn/countries-states-cities-database has 9,996 GitHub stars and 3,050 forks. GitHot measured +7 stars in 24 hours and +48 in 7 days. Last checked 2026-11-11 15:54 UTC. Last push 2026-11-04.
🌍 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
Measured star growth
- in 24h
- +7
- in 7 days
- +48
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Original
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).
Total Regions : 6
Total Sub Regions : 22
Total Countries : 250
Total States/Regions/Municipalities : 5,299
Total Cities/Towns/Districts : 153,765
Total Postcodes : 728556 (117 countries)
Total Timezones : 427 (100% IANA coverage)
Last Updated On: November 03, 2026
Recommended for production
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.
Other ways to use the data
NPM (JavaScript / TypeScript)
| Package | GitHub | NPM |
|---|---|---|
@countrystatecity/countries |
GitHub | npmjs.com |
@countrystatecity/countries-browser |
GitHub | npmjs.com |
@countrystatecity/currencies |
GitHub | npmjs.com |
@countrystatecity/timezones |
GitHub | npmjs.com |
@countrystatecity/translations |
GitHub | npmjs.com |
@countrystatecity/cli |
GitHub | npmjs.com |
PyPI (Python)
Use countrystatecity-api for live, managed data. The suffixed packages are versioned offline snapshots.
| Package | Use | GitHub | PyPI |
|---|---|---|---|
countrystatecity-api |
Live REST API client | GitHub | pypi.org |
countrystatecity-countries |
Offline snapshot | GitHub | pypi.org |
countrystatecity-timezones |
Offline snapshot | GitHub | pypi.org |
countrystatecity-currencies |
Offline snapshot | GitHub | pypi.org |
countrystatecity-translations |
Offline snapshot | GitHub | pypi.org |
countrystatecity-phonecodes |
Offline snapshot | GitHub | pypi.org |
countrystatecity-regions |
Offline snapshot | GitHub | pypi.org |
countrystatecity-postal-codes |
Offline snapshot | GitHub | pypi.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
- Database browser — query and explore live data
- Encyclopedia — country profiles and insights
- Community Manager — submit corrections via web UI
- CLI — terminal access
- Kaggle · Data.world
What's in the data
- 250 countries · 5,329 states / regions · 14,058 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)
| Format | Export time | Size | Compressed |
|---|---|---|---|
| CSV | 1s | 40 MB | 9 MB |
| MongoDB dump | 1s | 30 MB | 20 MB |
| MySQL SQL | 3s | 86 MB | 22 MB |
| JSON | 4s | 271 MB | 18 MB |
| TOON | 5s | 23 MB | 20 MB |
| Parquet | 7s | 31 MB | 27 MB |
| GeoJSON | 8s | 208 MB | 24 MB |
| XML | 9s | 91 MB | 15 MB |
| YAML | 17s | 68 MB | — |
| SQLite | 45s | 89 MB | — |
Contributing
The easiest way is the Community Manager — submit corrections through a web UI with end-to-end tracking.
To edit JSON directly:
- Fork and clone (
git clone --depth 1). - Edit files under
contributions/cities/,contributions/states/,contributions/countries/,contributions/counties/, orcontributions/postcodes/. - Required for new cities:
name,state_id,state_code,country_id,country_code,latitude,longitude. Optional:timezone,wikiDataId,native. - Omit
id,created_at,updated_at,flag— auto-managed on import. - Open a pull request with a clear data source. If it removes, repurposes or restores ids, include its reviewed
ledger events keyed by
event_prin that same PR. TheLedger migrationscheck validates the merge preview; all ids must be final at that preview.
{
"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 ·
Data versioning ·
Disputed and special territories ·
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
Some records also carry names or points copied from open sources that ask for credit: GeoNames (CC BY 4.0), © OpenStreetMap contributors (ODbL 1.0) and Wikidata (CC0). Points are selected per record and rounded to eight decimals; the per-record source ledgers are in .github/fixes-docs/ledgers/. Official registers matched to records (categories, codes and unit names) also ask for credit:
- Statistical Office of the Slovak Republic, register of spatial units REGPJ (CC BY 4.0)
- Geodetska uprava Republike Slovenije (GURS), register of spatial units RPE, 13 October 2026 (CC BY 4.0)
- Maa- ja Ruumiamet, administrative and settlement division, 2 September 2026 (public data terms)
- Central Statistics Office and Tailte Éireann, Census 2022 built-up areas (CC BY 4.0)
- Stats NZ, territorial authorities and urban-rural areas 2026 (CC BY 4.0): this work is based on Stats NZ data licensed for reuse under CC BY 4.0
- Ville de Luxembourg, quartiers on data.public.lu (CC BY 4.0)
- Ministry for Development of Communities and Territories of Ukraine, Codifier of administrative-territorial units and territories of territorial communities (KATOTTG), 7 July 2026 (CC BY 4.0): names and codes matched to records; CSC romanised the names under Cabinet of Ministers Resolution 55 (2010)
- Statistics South Africa, Census 2011 main places, distributed by UCT Libraries: main-place codes and classes matched to records; the mapping to
typeis CSC's
Country names in some languages follow Unicode CLDR 48.2: Copyright © 2015-2024 Unicode, Inc., under the Unicode License v3, whose notice must travel with copies.
Source credits and notices for 63 sources are in .github/licenses/SOURCES.txt; export releases attach it with the other notices. The register also identifies 233 sources whose redistribution basis remains under review. Keep the applicable credits and notices when redistributing the data.
Support
If this project saves you time, please consider supporting its continued maintenance.
You can also plant a tree on behalf of the project.
Reach out: gadadarshan [at] gmail [dot] com
Sponsors
Disclaimer
Community-maintained data may contain errors or lag behind geopolitical changes. Verify critical data with official sources. Report issues.
Thanks to our contributors.
Explore related projects
Asabeneh/30-Days-Of-Python
The 30 Days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days. This challenge may take more than 100 days. Follow your own pace. These videos may help too: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,560 starsgrafana/grafana
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
77,830 starsredis/redis
For developers, who are building real-time data-driven applications, Redis is the preferred, fastest, and most feature-rich cache, data structure server, and document and vector query engine.
77,395 starsapache/superset
Apache Superset is a Data Visualization and Data Exploration Platform
75,473 stars
