Skip to main content

countrystatecity-phonecodes

PyPI Python Version License Type Checked phonecodes phonecodes

Official Python package for international phone/dialing codes — 250+ entries with country associations. Part of the countrystatecity ecosystem.

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,000+ states, 150,000+ cities
countrystatecity-timezones 400+ IANA timezones with country associations and time conversion
countrystatecity-currencies Currency codes, names, and symbols for every country
countrystatecity-translations Country name translations in 18+ languages
countrystatecity-regions Continents and geographic subregions for 250+ countries
countrystatecity-postal-codes Postal/ZIP codes and format validation 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

countrystatecity_phonecodes-1.0.4.tar.gz (11.2 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.4-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for countrystatecity_phonecodes-1.0.4.tar.gz
Algorithm Hash digest
SHA256 eb98be63763d3e20a48ab15e3a4e0c5a58f7dc5e9204c658a9ed4abc50b61675
MD5 064520943302d48adb9c75ee2588d5c4
BLAKE2b-256 cf5eab20458238b1ad7bb7c753c76bfbc770d7d4d213f9e1d713d1a6a9f98e02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for countrystatecity_phonecodes-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 da371cfac4facdb6978a5e870679e91aa465aa1a3d2e684b1e28215394c7640b
MD5 dca0a65ae055ccb1d7ff277863e098b8
BLAKE2b-256 76069d57d6e1755df8f461b7e0f3670fe6b436a64d3e3c7be5bdfd93fd9d9e07

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.5

2 files

This release

1.0.4 This release

2 files

1.0.3

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page