Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.9k
🌍 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
License
dr5hn/countries-states-cities-database
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Full Database of city state country available in JSON, MYSQL, PSQL, SQLITE, SQLSERVER, XML, YAML, MONGODB & CSV format.All Countries, States & Cities are Covered & Populated with Different Combinations & Versions.
- ✅Most Comprehensive - 151,024+ cities from 250 countries with timezone & multilingual support (19 languages)
- ✅Multiple Integration Options - NPM/PyPI packages, REST API, Export Tool, or direct downloads
- ✅Production Ready - Trusted by thousands of developers, monthly updates
- ✅Every Format You Need - JSON, SQL, MongoDB, CSV, XML, YAML - use what fits your stack
- ✅100% Free & Open Source - ODbL licensed, no usage restrictions, developer-friendly
Save hundreds of hours collecting and maintaining geographical data. Get accurate, structured, ready-to-use data right now.
📦 Clone Tip: Use
git clone --depth 1for faster cloning (~1.2GB vs 5.4GB full history)
- CSC Platform Ecosystem •Integration Methods •Official Packages
- API •Export Tool •Available Formats
- Demo •Insights •Architecture
- Performance •License •Contributing
- Platforms •Support
Easily access all the tools and services in the Countries States Cities platform:
| Tool | Description | Link |
|---|---|---|
| NPM Package | Official JavaScript/TypeScript package | @countrystatecity/countries |
| Documentation | Complete API documentation and guides | docs.countrystatecity.in |
| Demo Database | Browse the full database online | demo.countrystatecity.in |
| API Service | Programmatic access to countries, states, cities | countrystatecity.in |
| Export Tool | Export data in multiple formats | export.countrystatecity.in |
| Update Tool | Submit and track data change requests | manager.countrystatecity.in |
| Status Page | Real-time service uptime and incidents | status.countrystatecity.in |
| Method | Setup | Best For | Offline | Cost |
|---|---|---|---|---|
| NPM/PyPI Package | < 1 min | JS/TS/Python apps, offline use | ✅ | Free |
| REST API | < 5 min | Production apps, real-time data, any language | ❌ | Free tier + paid |
| Export Tool | < 2 min | Custom datasets, specific regions | ❌ | Free + credits |
| Direct Download | Immediate | SQL databases, one-time imports, legacy systems | ✅ | Free |
npm install @countrystatecity/countries
Features: Zero dependencies, TypeScript support, offline-first, tree-shakeable
import{Country,State,City}from'@countrystatecity/countries';constusStates=State.getStatesOfCountry('US');
pip install countrystatecity
Features: Easy-to-use Python interface, works with Django/Flask, offline data access
fromcountrystatecityimportCountry,State,Cityus_states=State.get_states_of_country('US')
📖PyPI Package · 📂GitHub
Dedicated timezone data package for JavaScript/TypeScript applications:
npm install @countrystatecity/timezones
🎉 IntroducingREST API for Countries States Cities Database.
Export Tool - Convert and download data in your preferred format
Features: Multiple formats, flexible selection, custom filtering by region/country, bulk downloads, real-time processing
- JSON
- MYSQL
- PSQL
- SQLITE
- SQLSERVER
- MONGODB
- XML
- YAML
- CSV
Note: DuckDB format is available via manual conversion from SQLite files. See theExport to DuckDB section for instructions.
| File | JSON | MYSQL | PSQL | SQLITE | SQLSERVER | MONGODB | XML | YAML | CSV |
|---|---|---|---|---|---|---|---|---|---|
| Regions | ✅🗜️ | ✅🗜️ | ✅ | ✅ | ✅ | ✅ | ✅🗜️ | ✅ | ✅🗜️ |
| Subregions | ✅🗜️ | ✅🗜️ | ✅ | ✅ | ✅ | ✅ | ✅🗜️ | ✅ | ✅🗜️ |
| Countries | ✅🗜️ | ✅🗜️ | ✅ | ✅ | ✅ | ✅ | ✅🗜️ | ✅ | ✅🗜️ |
| States | ✅🗜️ | ✅🗜️ | ✅ | ✅ | ✅ | ✅ | ✅🗜️ | ✅ | ✅🗜️ |
| Cities | ✅🗜️ | ✅🗜️ | ✅ | ✅ | ✅ | ✅ | ✅🗜️ | ✅ | ✅🗜️ |
| Country+States | ✅🗜️ | NA | NA | NA | NA | NA | NA | NA | NA |
| Country+Cities | ✅🗜️ | NA | NA | NA | NA | NA | NA | NA | NA |
| Country+State+Cities/World | ✅🗜️ | ✅🗜️ | ✅ | ✅ | ✅ | ✅ | NA | NA | NA |
Legend: ✅ = Available | 🗜️ = Compressed (.gz) version also available
https://dr5hn.github.io/countries-states-cities-database/
Total Regions : 6
Total Sub Regions : 22
Total Countries : 250
Total States/Regions/Municipalities : 5,038
Total Cities/Towns/Districts : 151,024
Total Timezones : 423 (97.9% IANA coverage)
Last Updated On : 18th Oct 2025
Two-phase build system: JSON (version control) → MySQL (canonical) → All export formats
📝 contributions/ → [Python Import] → 🗄️ MySQL → [PHP Export] → 📦 json/, csv/, xml/, sql/, etc.For Contributors: Edit JSON files incontributions/ → Submit PR → GitHub Actions auto-generates all exports (no local setup needed!)
For Maintainers: MySQL as single source of truth, dynamic schema detection, one command to regenerate all formats
For Users: All formats guaranteed in sync, compressed downloads available (.gz)
How to import MongoDB database?
# First extract the tar.gz filetar -xzvf world-mongodb-dump.tar.gz# Then restore the MongoDB dumpmongorestore --host localhost:27017 --db world mongodb-dump/world
Want to export the database to DuckDB format? You can easily convert the existing SQLite files to DuckDB format using our conversion script.
First, install DuckDB Python package:
pip install duckdb
Use the provided conversion script to convert SQLite files to DuckDB format:
# Convert the complete world databasepython3 bin/scripts/export/import_duckdb.py --input sqlite/world.sqlite3 --output duckdb/world.db# Convert individual table databasespython3 bin/scripts/export/import_duckdb.py --input sqlite/regions.sqlite3 --output duckdb/regions.dbpython3 bin/scripts/export/import_duckdb.py --input sqlite/subregions.sqlite3 --output duckdb/subregions.dbpython3 bin/scripts/export/import_duckdb.py --input sqlite/countries.sqlite3 --output duckdb/countries.dbpython3 bin/scripts/export/import_duckdb.py --input sqlite/states.sqlite3 --output duckdb/states.dbpython3 bin/scripts/export/import_duckdb.py --input sqlite/cities.sqlite3 --output duckdb/cities.db
The conversion script will create DuckDB database files that maintain the same structure and data as the original SQLite files, optimized for analytical workloads.
| Format | Export Time | World DB Size | Compressed (.gz) |
|---|---|---|---|
| CSV | ~1s | 45 MB | 9 MB (fastest) |
| JSON | ~4s | 161 MB | 18 MB |
| MongoDB | ~1s | 140 MB | - |
| SQL | ~3s | 180 MB | 22 MB |
| SQLite | ~45s | 85 MB | - |
| XML | ~9s | 220 MB | 15 MB |
| YAML | ~17s | 195 MB | - |
- Countries: ~50ms | States: ~180ms | Cities by State: ~80ms | Search: ~120ms
- Contributors: Git + text editor (no local setup needed)
- Maintainers: PHP 8.0+, MySQL 5.7+, Python 3.8+, 4GB RAM, 10GB disk
- End Users: No requirements - just download!
Open Database License (ODbL) - 100% free and open source!
✅ Use commercially, modify freely, share openly • 📝 Just give credit and keep derivatives open
Quick Attribution:
Data by Countries States Cities Databasehttps://github.com/dr5hn/countries-states-cities-database | ODbL v1.0🛠️ Easy Way:CSC Update Tool
Use our web tool to browse, search, and submit data change requests with a streamlined review process.
- Fork & clone:
git clone --depth 1 https://github.com/YOUR_USERNAME/countries-states-cities-database.git - Edit files in
contributions/directory (cities, states, or countries) - Omit
id,created_at,updated_at,flagfields (auto-managed) - Include required fields:
name,state_id,state_code,country_id,country_code,latitude,longitude - Submit PR with clear description and data source
Example city:
{"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"}📖Full guide:contributions/README.md |Contribution Guidelines
Note: Only edit JSON incontributions/ - GitHub Actions auto-generates all export formats!
As always, thanks to our amazing contributors!
Made withcontrib.rocks.
Contribute towards better earthbuy the world a tree
Find and use this dataset across the web - choose the platform that fits your workflow:
| Platform | Best For | Access |
|---|---|---|
| 📊Kaggle Dataset | Data science, ML projects, notebooks | Download on Kaggle |
| 🗃️Data.world | Data collaboration, business analytics | View on Data.world |
| 📦NPM Registry | JavaScript/TypeScript developers | npm install @countrystatecity/countries |
| 🐙GitHub | Contributors, raw files, issue tracking | View Repository |
| 🌍API Service | Production apps, real-time access | Get API Key |
| 🛠️Export Tool | Custom exports, specific formats | Launch Tool |
| 📊Status Page | Service uptime monitoring, incidents | Check Status |
Suggestions & Feedbacks are Most Welcomegadadarshan[at]gmail[dot]comWhile we strive for accuracy, this community-maintained database may contain errors or not reflect latest geopolitical changes. Users should verify critical data with official sources and use at their own discretion. Licensed under ODbL - seeLICENSE for details.
Report issues:GitHub Issues
That's all Folks. Enjoy! 🌍
About
🌍 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
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.



