Official Python packages for accessing comprehensive countries, states, cities, timezones, currencies, and translations data with type hints and lazy loading.
| Package | PyPI | Description |
|---|---|---|
| countrystatecity-countries | Countries, states, and cities with full metadata | |
| countrystatecity-timezones | IANA timezone data and time conversion utilities | |
| countrystatecity-currencies | Currency codes, names, and symbols | |
| countrystatecity-translations | Country name translations in 18+ languages | |
| countrystatecity-phonecodes | International phone/dialing codes for 250+ countries |
Note: There is no bare
countrystatecitypackage on PyPI. Always install with the suffix (-countries,-timezones,-currencies,-translations,-phonecodes).
Install only what you need:
pip install countrystatecity-countries
pip install countrystatecity-timezones
pip install countrystatecity-currencies
pip install countrystatecity-translations
pip install countrystatecity-phonecodesfrom countrystatecity_countries import (
get_countries,
get_country_by_code,
get_states_of_country,
get_cities_of_state,
)
# All countries
countries = get_countries()
print(f"Total countries: {len(countries)}")
# Specific country
usa = get_country_by_code("US")
print(f"{usa.emoji} {usa.name} โ {usa.capital}")
print(f"Currency: {usa.currency_symbol} {usa.currency_name}")
# States and cities (lazy loaded)
states = get_states_of_country("US")
cities = get_cities_of_state("US", "CA")from countrystatecity_timezones import (
get_all_timezones,
get_timezones_by_country,
get_timezone_by_zone_name,
get_timezones_by_offset,
convert_time,
)
# Timezones for a country
timezones = get_timezones_by_country("US")
# Lookup by zone name
tz = get_timezone_by_zone_name("America/New_York")
print(f"{tz.zone_name} โ {tz.gmt_offset_name}")
# Convert time between zones
from datetime import datetime
dt = datetime(2024, 1, 1, 12, 0, 0)
converted = convert_time(dt, "America/New_York", "Asia/Kolkata")from countrystatecity_currencies import (
get_all_currencies,
get_currency_by_country,
get_countries_by_currency,
search_currencies,
)
# Currency for a country
currency = get_currency_by_country("US")
print(f"{currency.symbol} {currency.name} ({currency.code})")
# All countries using a currency
countries = get_countries_by_currency("EUR")
# Search
results = search_currencies("dollar")from countrystatecity_phonecodes import (
get_all_phonecodes,
get_phonecode_by_country,
get_countries_by_phonecode,
search_phonecodes,
)
# Phone code for a country
us = get_phonecode_by_country("US")
print(f"+{us.phoneCode} โ {us.countryName}") # +1 โ United States
# All countries sharing a dialing code
plus1 = get_countries_by_phonecode("1")
print(f"{len(plus1)} countries use +1")
# Works with or without + prefix
plus44 = get_countries_by_phonecode("+44")
# Search
results = search_phonecodes("united")from countrystatecity_translations import (
get_all_translations,
get_translations_by_country,
get_translations_by_language,
get_translation,
search_translations,
)
# Country name in a specific language
translation = get_translation("US", "fr")
print(translation.name) # รtats-Unis
# All translations for a country
translations = get_translations_by_country("IN")
# All countries translated in Japanese
japanese = get_translations_by_language("ja")- โ Type-safe with Pydantic models and mypy strict mode
- โ Lazy loading for minimal memory footprint
- โ 250+ countries with full metadata
- โ 5,000+ states/provinces
- โ 150,000+ cities
- โ 400+ timezones with GMT offsets and time conversion
- โ Currency data for every country
- โ Translations in 18+ languages
- โ Phone/dialing codes for 250+ countries
- โ Zero external dependencies (except Pydantic)
- โ Python 3.8โ3.12 support
- โ Full test coverage with pytest
countrystatecity-pypi/
โโโ python/
โ โโโ packages/
โ โโโ countries/ # countrystatecity-countries
โ โโโ timezones/ # countrystatecity-timezones
โ โโโ currencies/ # countrystatecity-currencies
โ โโโ translations/ # countrystatecity-translations
โ โโโ phonecodes/ # countrystatecity-phonecodes
โ
โโโ .github/
โโโ workflows/
โโโ python-ci.yml # CI โ tests, type check, lint
โโโ publish.yml # Publish to PyPI
โโโ release.yml # Version bump + changelog
โโโ update-data.yml # Weekly data sync
git clone https://github.com/dr5hn/countrystatecity-pypi.git
# Install a package in dev mode (replace 'countries' with any package)
cd python/packages/countries
pip install -e ".[dev]"
# Run tests
pytest --cov=countrystatecity_countries --cov-report=html
# Type check
mypy countrystatecity_countries/ --strict
# Lint and format
ruff check countrystatecity_countries/ tests/
black countrystatecity_countries/ tests/
isort countrystatecity_countries/ tests/| Component | Technology |
|---|---|
| Type System | Pydantic |
| Testing | pytest |
| Type Checking | mypy (strict) |
| Formatting | black + isort |
| Linting | ruff |
| CI/CD | GitHub Actions |
All packages are licensed under the Open Database License (ODbL-1.0).
- 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') - Open a Pull Request
- Issues: GitHub Issues
- Website: countrystatecity.in
- countries-states-cities-database โ Source database
- countrystatecity NPM โ JavaScript/TypeScript packages
Made with โค๏ธ by dr5hn