Skip to main content

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.

PyPI Python Version License

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

Open Database License (ODbL-1.0)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

countrystatecity_phonecodes-1.0.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

countrystatecity_phonecodes-1.0.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file countrystatecity_phonecodes-1.0.0.tar.gz.

File metadata

File hashes

Hashes for countrystatecity_phonecodes-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bf06de6ac82146bcd96d6c2b8d00c56db59d7d182e472e4b2db053d5b917aa47
MD5 cf06ea93cc43472f098ddc50252b2427
BLAKE2b-256 132756ea12044bd05e6b88f89c10562fed4150c073d27e96596f17f014ddc72f

See more details on using hashes here.

File details

Details for the file countrystatecity_phonecodes-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for countrystatecity_phonecodes-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47c1fbf919c105266c5052634c0fda44ce6a590d3053b233688fb30813748d44
MD5 6c52c91841811ee4c6ce2ce99d4b6c7b
BLAKE2b-256 f7fdf9d79698f7142a1f698791419aea5f3894f6ad8caa9914748e3070250fe3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page