Official Python packages for accessing comprehensive countries, states, and cities database with type hints and lazy loading.
Note: All Python distributions are published with an entity suffix (e.g.
countrystatecity-countries). Currently there is no barecountrystatecitypackage on PyPI, sopip install countrystatecitymay not work as expected. Pick the suffixed package you need from the list below.
- countrystatecity-countries - Countries, states, and cities database with type hints and lazy loading
- countrystatecity-timezones - IANA timezone data and utilities
- countrystatecity-currencies - Currency codes, symbols, and formatting
- countrystatecity-languages - Language codes and metadata
- countrystatecity-phonecodes - International dialing codes and validation
pip install countrystatecity-countries
β οΈ Don't runpip install countrystatecityβ that name is unpublished. Always include the entity suffix (-countries,-timezones, etc.).
from countrystatecity_countries import (
get_countries,
get_country_by_code,
get_states_of_country,
get_cities_of_state,
)
# Get all countries
countries = get_countries()
print(f"Total countries: {len(countries)}")
# Get specific country
usa = get_country_by_code("US")
print(f"{usa.emoji} {usa.name}")
print(f"Capital: {usa.capital}")
print(f"Currency: {usa.currency_symbol} {usa.currency_name}")
# Get states (lazy loaded)
states = get_states_of_country("US")
print(f"Total states: {len(states)}")
# Get cities (lazy loaded)
cities = get_cities_of_state("US", "CA")
print(f"Cities in California: {len(cities)}")- β Type-safe with Pydantic models and mypy support
- β Lazy loading for minimal memory footprint
- β 250+ countries with full metadata
- β 5,000+ states/provinces
- β 151,000+ cities
- β Translations in 18+ languages
- β Timezone data per location
- β Zero external dependencies (except Pydantic)
- β Full test coverage with pytest
For detailed documentation, please refer to:
countrystatecity-pypi/
βββ python/ # Python packages root
β βββ packages/
β β βββ countries/ # Priority 1: Core package
β βββ shared/ # Shared utilities
β βββ scripts/ # Build scripts
β βββ README.md
β
βββ specs/ # Specifications
β βββ README.md
β βββ 1-python-pypi-monorepo-plan.md
β βββ 2-python-vs-npm-comparison.md
β βββ 3-python-quick-start-guide.md
β
βββ .github/
βββ workflows/
βββ python-ci.yml # CI/CD workflow
# Clone the repository
git clone https://github.com/dr5hn/countrystatecity-pypi.git
cd countrystatecity-pypi/python/packages/countries
# Install dependencies
pip install -e ".[dev]"# Run all tests
pytest
# Run with coverage
pytest --cov=countrystatecity_countries --cov-report=html
# Type checking
mypy countrystatecity_countries/ --strict
# Linting
ruff check countrystatecity_countries/ tests/
# Formatting
black countrystatecity_countries/ tests/
isort countrystatecity_countries/ tests/| Component | Technology | Purpose |
|---|---|---|
| Package Manager | pip/setuptools | Dependency management |
| Type System | Pydantic | Data validation, immutable models |
| Testing | pytest | Unit and integration tests |
| Type Checking | mypy | Static type checking |
| Formatting | black + isort | Code formatting |
| Linting | ruff | Fast Python linter |
| CI/CD | GitHub Actions | Automated testing |
- Type Safety - Full type hints with Pydantic models
- Performance - Lazy loading with LRU cache
- Minimal Dependencies - Only essential dependencies
- Python Best Practices - PEP 8 compliant, well-tested
- Developer Experience - Clear APIs, comprehensive docs
All packages are licensed under the Open Database License (ODbL-1.0).
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Documentation: GitHub Repository
- Issues: GitHub Issues
- Website: countrystatecity.in
- countries-states-cities-database - The source database (MySQL)
- countrystatecity NPM packages - JavaScript/TypeScript packages
Made with β€οΈ by dr5hn