Type-safe Python package for international phone/dialing codes with 250+ country associations.
Project description
countrystatecity-phonecodes
Type-safe Python package for international phone/dialing codes with 250+ country associations.
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
Project details
Release history Release notifications | RSS feed
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.0.tar.gz.
File metadata
- Download URL: countrystatecity_phonecodes-1.0.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf06de6ac82146bcd96d6c2b8d00c56db59d7d182e472e4b2db053d5b917aa47
|
|
| MD5 |
cf06ea93cc43472f098ddc50252b2427
|
|
| BLAKE2b-256 |
132756ea12044bd05e6b88f89c10562fed4150c073d27e96596f17f014ddc72f
|
File details
Details for the file countrystatecity_phonecodes-1.0.0-py3-none-any.whl.
File metadata
- Download URL: countrystatecity_phonecodes-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47c1fbf919c105266c5052634c0fda44ce6a590d3053b233688fb30813748d44
|
|
| MD5 |
6c52c91841811ee4c6ce2ce99d4b6c7b
|
|
| BLAKE2b-256 |
f7fdf9d79698f7142a1f698791419aea5f3894f6ad8caa9914748e3070250fe3
|