python-phonenumbers: Google's libphonenumber Port for Python
This repository profile is provided by osrepos.com, an open source repository discovery platform.

Summary
`python-phonenumbers` is a robust Python port of Google's highly acclaimed `libphonenumber` library. It offers comprehensive functionality for parsing, validating, and formatting international phone numbers, making it an indispensable tool for global applications. This library ensures accurate and standardized phone number handling across diverse regions.
Repository Information
Topics
Click on any tag to explore related repositories
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Introduction
python-phonenumbers is the official Python port of Google's libphonenumber library, a powerful and widely used tool for handling international phone numbers. This library provides a comprehensive suite of functionalities, including parsing, validation, formatting, and extracting metadata for phone numbers from various countries. It's designed to work seamlessly across Python 2.5-2.7 and Python 3.x, offering a consistent experience for developers.
Whether you need to verify user input, standardize phone number displays, or extract geographical information, python-phonenumbers offers a reliable and well-maintained solution, mirroring the capabilities of its Java counterpart.
Installation
Getting started with python-phonenumbers is straightforward. You can install it using pip:
pip install phonenumbers
Examples
Let's explore some of the core functionalities of python-phonenumbers with practical examples.
Parsing and Validation
The library allows you to parse phone numbers from strings and then validate them for possibility and validity.
import phonenumbers
# Parse a number with a known region
x = phonenumbers.parse("020 8366 1177", "GB")
print(x)
# Output: Country Code: 44 National Number: 2083661177 Leading Zero: False
# Parse an E.164 number
y = phonenumbers.parse("+442083661177", None)
print(y)
# Output: Country Code: 44 National Number: 2083661177 Leading Zero: False
# Check if numbers are possible or valid
invalid_number = phonenumbers.parse("+120012301", None)
print(f"Is possible: {phonenumbers.is_possible_number(invalid_number)}") # False
print(f"Is valid: {phonenumbers.is_valid_number(invalid_number)}") # False
valid_but_unassigned = phonenumbers.parse("+12001230101", None)
print(f"Is possible: {phonenumbers.is_possible_number(valid_but_unassigned)}") # True
print(f"Is valid: {phonenumbers.is_valid_number(valid_but_unassigned)}") # False (NPA 200 not used)
Formatting Phone Numbers
You can format parsed PhoneNumber objects into various standard formats.
import phonenumbers
number = phonenumbers.parse("+442083661177", None)
print(f"National format: {phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.NATIONAL)}")
# Output: National format: 020 8366 1177
print(f"International format: {phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.INTERNATIONAL)}")
# Output: International format: +44 20 8366 1177
print(f"E.164 format: {phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.E164)}")
# Output: E.164 format: +442083661177
Geocoding and Carrier Information
The library also provides extended functionality to retrieve geographical and carrier information for phone numbers. Note that these require importing specific sub-packages.
from phonenumbers import geocoder, carrier
import phonenumbers
# Geocoding
ch_number = phonenumbers.parse("0431234567", "CH")
print(f"Location (English): {geocoder.description_for_number(ch_number, 'en')}")
# Output: Location (English): Zurich
# Carrier information
ro_number = phonenumbers.parse("+40721234567", "RO")
print(f"Carrier (English): {carrier.name_for_number(ro_number, 'en')}")
# Output: Carrier (English): Vodafone
Why Use python-phonenumbers?
python-phonenumbers is an indispensable library for any application dealing with phone numbers globally. Its key advantages include:
- Accuracy and Reliability: Directly ported from Google's
libphonenumbers, it inherits a vast and frequently updated dataset of phone number metadata, ensuring high accuracy in parsing and validation. - Internationalization: Supports phone numbers from all over the world, handling country codes, national prefixes, and various formatting conventions.
- Comprehensive Features: Beyond basic parsing and formatting, it offers advanced features like "as-you-type" formatting, finding numbers in text, geocoding, and carrier identification.
- Active Maintenance: The library is actively maintained, keeping pace with changes in global telephony standards and data.
- Memory Management: It intelligently loads metadata on-demand, and provides options for managing memory overhead for extended functionalities.
Links
- GitHub Repository: https://github.com/daviddrysdale/python-phonenumbers
- Official Documentation: https://daviddrysdale.github.io/python-phonenumbers/
- PyPI Package: https://pypi.org/project/phonenumbers/
Related repositories
Similar repositories that may be relevant next.

PLY: A Legacy Python Lex-Yacc Parser Generator (Project Abandoned)
July 30, 2026
PLY (Python Lex-Yacc) is a zero-dependency Python implementation of the traditional lex and yacc parsing tools, designed for building compilers, ASTs, and protocol decoders. Created by David Beazley, it offers a robust LALR(1) parsing algorithm compatible with modern Python versions. However, it's important to note that the project has been officially abandoned by its author, with no further maintenance expected.

sqlparse: A Powerful Non-Validating SQL Parser for Python
July 30, 2026
sqlparse is a robust, non-validating SQL parser module for Python, designed to tokenize SQL text and group its components into a structured tree. It serves as a foundational tool for building formatters, linters, and query analysis applications. Developers can leverage its capabilities to split SQL scripts, format statements, and deeply inspect their token trees.

Boto3: The AWS SDK for Python for Seamless Cloud Interaction
July 29, 2026
Boto3 is the official Amazon Web Services (AWS) SDK for Python, enabling developers to easily interact with a wide range of AWS services like S3 and EC2. It provides a powerful and intuitive interface for managing cloud resources directly from Python applications. With robust documentation and active community support, Boto3 is an essential tool for Python developers working with AWS.
google-api-python-client: The Official Python Library for Google APIs
July 29, 2026
The `google-api-python-client` is the official Python client library for interacting with Google's discovery-based APIs. It provides a robust way for Python developers to integrate their applications with various Google services. While in maintenance mode, it remains a reliable choice, especially with its improved v2.0 caching mechanism.
Source repository
Open the original repository on GitHub.