countrystatecity-phonecodes
Official Python package for international phone/dialing codes — 250 entries with country associations. Part of the countrystatecity ecosystem.
From offline prototype to production
This package provides a versioned offline snapshot. For regularly updated data, server-side search and filtering, field-selected responses, or managed availability and support, use the Country State City API.
Get a free API key · API docs · Pricing · Migration guide
Keep API keys in server-side environment variables, never in client-side code or source control.
Installation
pip install countrystatecity-phonecodes
Usage
from countrystatecity_phonecodes import (
get_all_phonecodes,
get_phonecode_by_country,
get_countries_by_phonecode,
search_phonecodes,
)
# Get phone code for a country
us = get_phonecode_by_country("US")
print(f"+{us.phoneCode} — {us.countryName}") # +1 — United States
# Get all countries sharing a dialing code
plus1 = get_countries_by_phonecode("1")
print(f"{len(plus1)} countries use +1") # 25 countries use +1
# Works with or without + prefix
plus44 = get_countries_by_phonecode("+44")
# Search by country name, code, or phone code
results = search_phonecodes("united")
results = search_phonecodes("44")
# All phone codes
all_codes = get_all_phonecodes()
print(f"Total entries: {len(all_codes)}")
API Reference
get_all_phonecodes() -> List[PhoneCode]
Returns all phone code entries (one per country).
get_phonecode_by_country(country_code: str) -> Optional[PhoneCode]
Returns the phone code for a country by ISO2 code (e.g., "US").
get_countries_by_phonecode(phone_code: str) -> List[PhoneCode]
Returns all countries sharing a dialing code (e.g., "1" or "+1").
search_phonecodes(query: str) -> List[PhoneCode]
Search by country name, ISO2 code, or phone code (case-insensitive).
PhoneCode Model
class PhoneCode:
phoneCode: str # e.g. "1", "44", "91"
countryCode: str # ISO2 e.g. "US", "GB", "IN"
countryName: str # e.g. "United States"
License
ODbL-1.0 — see LICENSE.
Other Packages in this Ecosystem
| Package | Description |
|---|---|
| countrystatecity-countries | 250 countries, 5,308 states, 171,938 cities |
| countrystatecity-timezones | 432 IANA timezones with country associations and time conversion |
| countrystatecity-currencies | 249 country/currency associations |
| countrystatecity-translations | 4,724 translations in 19 languages |
| countrystatecity-regions | Region and subregion associations for 250 countries |
| countrystatecity-postal-codes | Postal/ZIP records for 125 countries |
Data sourced from countries-states-cities-database.
Made with ❤️ by dr5hn
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file countrystatecity_phonecodes-1.0.5.tar.gz.
File metadata
- Download URL: countrystatecity_phonecodes-1.0.5.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f56592c42ffe3ac5376d76ddfed878e08889fe6a0cb7d45def6aec90205c828a
|
|
| MD5 |
8dbfa3eb37238f76ed764f7b8c278351
|
|
| BLAKE2b-256 |
24bcc89e2b1df4466d681e8fc448a015d15fe8e84955dd06dd412f1428793f8e
|
File details
Details for the file countrystatecity_phonecodes-1.0.5-py3-none-any.whl.
File metadata
- Download URL: countrystatecity_phonecodes-1.0.5-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6506c6eefc7a161197b72b552d2b637a94356c7b1df6c205bb6a3ae0f3dcadb
|
|
| MD5 |
19a1e3359efe8d206fbacce8132d4d82
|
|
| BLAKE2b-256 |
4e4b79aa753dccd5c8aa95b77434d6fd0ae2f88da836370807748798b5fd3283
|