Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🌍 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

NotificationsYou must be signed in to change notification settings

dr5hn/countries-states-cities-database

banner

🌍 Countries States Cities Database

License: ODbL-1.0GitHub starsGitHub forksreleasesize

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.

Why Choose This Database?

  • 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: Usegit clone --depth 1 for faster cloning (~1.2GB vs 5.4GB full history)

Table of Contents

🌐 CSC Platform Ecosystem

Easily access all the tools and services in the Countries States Cities platform:

ToolDescriptionLink
NPM PackageOfficial JavaScript/TypeScript package@countrystatecity/countries
DocumentationComplete API documentation and guidesdocs.countrystatecity.in
Demo DatabaseBrowse the full database onlinedemo.countrystatecity.in
API ServiceProgrammatic access to countries, states, citiescountrystatecity.in
Export ToolExport data in multiple formatsexport.countrystatecity.in
Update ToolSubmit and track data change requestsmanager.countrystatecity.in
Status PageReal-time service uptime and incidentsstatus.countrystatecity.in

🔄 Choose Your Integration Method

MethodSetupBest ForOfflineCost
NPM/PyPI Package< 1 minJS/TS/Python apps, offline useFree
REST API< 5 minProduction apps, real-time data, any languageFree tier + paid
Export Tool< 2 minCustom datasets, specific regionsFree + credits
Direct DownloadImmediateSQL databases, one-time imports, legacy systemsFree

📦 Official Packages

JavaScript/TypeScript (NPM)

npm install @countrystatecity/countries

Features: Zero dependencies, TypeScript support, offline-first, tree-shakeable

import{Country,State,City}from'@countrystatecity/countries';constusStates=State.getStatesOfCountry('US');

📖NPM Documentation · 📂GitHub

Python (PyPI)

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

Timezones Package

Dedicated timezone data package for JavaScript/TypeScript applications:

npm install @countrystatecity/timezones

📂GitHub Repository

API 🚀

🎉 IntroducingREST API for Countries States Cities Database.

API Documentation

banner

🛠️ Export Tool

Export Tool - Convert and download data in your preferred format

banner

Features: Multiple formats, flexible selection, custom filtering by region/country, bulk downloads, real-time processing

Available Formats

  • 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.

Distribution Files Info

FileJSONMYSQLPSQLSQLITESQLSERVERMONGODBXMLYAMLCSV
Regions✅🗜️✅🗜️✅🗜️✅🗜️
Subregions✅🗜️✅🗜️✅🗜️✅🗜️
Countries✅🗜️✅🗜️✅🗜️✅🗜️
States✅🗜️✅🗜️✅🗜️✅🗜️
Cities✅🗜️✅🗜️✅🗜️✅🗜️
Country+States✅🗜️NANANANANANANANA
Country+Cities✅🗜️NANANANANANANANA
Country+State+Cities/World✅🗜️✅🗜️NANANA

Legend: ✅ = Available | 🗜️ = Compressed (.gz) version also available

Demo

https://dr5hn.github.io/countries-states-cities-database/

Insights

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

Repository Architecture

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)

Import MongoDB

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

Export to DuckDB

Want to export the database to DuckDB format? You can easily convert the existing SQLite files to DuckDB format using our conversion script.

Prerequisites

First, install DuckDB Python package:

pip install duckdb

Convert SQLite to 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.

Performance & Benchmarks

Export Performance

FormatExport TimeWorld DB SizeCompressed (.gz)
CSV~1s45 MB9 MB (fastest)
JSON~4s161 MB18 MB
MongoDB~1s140 MB-
SQL~3s180 MB22 MB
SQLite~45s85 MB-
XML~9s220 MB15 MB
YAML~17s195 MB-

API Response Times (Average)

  • Countries: ~50ms | States: ~180ms | Cities by State: ~80ms | Search: ~120ms

System Requirements

  • 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!

📄 License

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

Contributing

🛠️ Easy Way:CSC Update Tool

Use our web tool to browse, search, and submit data change requests with a streamlined review process.

banner

📝 Manual Way: Edit JSON Files Directly

  1. Fork & clone:git clone --depth 1 https://github.com/YOUR_USERNAME/countries-states-cities-database.git
  2. Edit files incontributions/ directory (cities, states, or countries)
  3. Omitid,created_at,updated_at,flag fields (auto-managed)
  4. Include required fields:name,state_id,state_code,country_id,country_code,latitude,longitude
  5. 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!

Repo Activity

Repo Activity

As always, thanks to our amazing contributors!

Made withcontrib.rocks.

Sponsors

Make the world more Greener 🌴

Contribute towards better earthbuy the world a tree

🌐 Available On Multiple Platforms

Find and use this dataset across the web - choose the platform that fits your workflow:

PlatformBest ForAccess
📊Kaggle DatasetData science, ML projects, notebooksDownload on Kaggle
🗃️Data.worldData collaboration, business analyticsView on Data.world
📦NPM RegistryJavaScript/TypeScript developersnpm install @countrystatecity/countries
🐙GitHubContributors, raw files, issue trackingView Repository
🌍API ServiceProduction apps, real-time accessGet API Key
🛠️Export ToolCustom exports, specific formatsLaunch Tool
📊Status PageService uptime monitoring, incidentsCheck Status

Follow me at

Github @dr5hnTwitter @dr5hnLinkedIn @dr5hn

🙋‍♂️ Support My Work

Github Sponsorship

ko-fi

Suggestions / Feedbacks

Suggestions & Feedbacks are Most Welcomegadadarshan[at]gmail[dot]com

Disclaimer

While 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

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp