Registry / serialization / phonenumberslite

phonenumberslite

JSON →
library9.0.38pypypi✓ verified 23d ago

Phonenumberslite is a Python port of Google's `libphonenumber` library, designed for parsing, formatting, storing, and validating international phone numbers. It is a 'lite' version of the main `phonenumbers` library, specifically omitting the larger geocoding, carrier, and timezone data packages to reduce its footprint, making it suitable for environments with memory or space limitations. The library is actively maintained, with the current version being 9.0.27.

pip install phonenumberslite
INSTALL
IMPORT
SIG · PHONENUMBERSLITE
P
phonenumberslite
serializationpythonv9.0.38
Install
1.9s avg
Import
101ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v9.0.38 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.104s · 23MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.9s · import 0.098s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

phonenumbers
import phonenumbers
The primary module for all core functionality.
PhoneNumberFormat
from phonenumbers import PhoneNumberFormat
Used to specify formatting options for phone numbers.
geocoder
from phonenumbers import geocoder
The 'phonenumberslite' version *does not include* geocoding, carrier, or timezone functionality to reduce package size. Attempting to import these will fail or result in missing attributes. Use the full 'phonenumbers' package for these features.

This quickstart demonstrates how to parse, validate, and format phone numbers using `phonenumberslite`. It shows how to handle numbers with and without explicit region codes, checks for validity and possibility, and formats numbers into E.164, International, and National formats. It also includes error handling for `NumberParseException` when an invalid string is provided.

import phonenumbers from phonenumbers import PhoneNumberFormat from phonenumbers.phonenumberutil import NumberParseException # Parse a phone number try: # Example with explicit region code for a non-E.164 number number_str_gb = "020 7946 0958" parsed_number_gb = phonenumbers.parse(number_str_gb, "GB") print(f"Parsed GB Number: {parsed_number_gb}") # Example with E.164 format (no region needed) number_str_e164 = "+15555551234" parsed_number_e164 = phonenumbers.parse(number_str_e164, None) print(f"Parsed E164 Number: {parsed_number_e164}") # Validate the number is_valid = phonenumbers.is_valid_number(parsed_number_gb) is_possible = phonenumbers.is_possible_number(parsed_number_gb) print(f"Is GB number valid? {is_valid}") print(f"Is GB number possible? {is_possible}") # Format the number formatted_e164 = phonenumbers.format_number(parsed_number_gb, PhoneNumberFormat.E164) formatted_international = phonenumbers.format_number(parsed_number_gb, PhoneNumberFormat.INTERNATIONAL) formatted_national = phonenumbers.format_number(parsed_number_gb, PhoneNumberFormat.NATIONAL) print(f"Formatted E.164: {formatted_e164}") print(f"Formatted International: {formatted_international}") print(f"Formatted National: {formatted_national}") # Attempt to parse an invalid number invalid_number_str = "not a phone number" phonenumbers.parse(invalid_number_str, "US") except NumberParseException as e: print(f"Error parsing number: {e.args[0]}")
Debug
Known issues
gotchaThe 'phonenumberslite' package explicitly excludes geocoding, carrier, and timezone data to reduce its size. If you need these functionalities (e.g., `phonenumbers.geocoder`, `phonenumbers.carrier`, `phonenumbers.timezone`), you must install the full `phonenumbers` package instead.
fix
If geocoding, carrier, or timezone features are required, `pip uninstall phonenumberslite` and then `pip install phonenumbers`.
affects: All versions of phonenumberslite
gotchaThe `phonenumbers.parse()` function requires a `region_code` argument (e.g., 'US', 'GB') unless the input phone number is in E.164 format (starts with '+'). If a non-E.164 number is passed without a `region_code`, a `NumberParseException` will be raised.
fix
Always provide a `region_code` (e.g., `phonenumbers.parse('02083661177', 'GB')`) for numbers not in E.164 format, or handle `NumberParseException` appropriately.
affects: All versions
gotchaValidation of a phone number can be done with `is_possible_number()` or `is_valid_number()`. `is_possible_number()` performs a quick length-based check and is faster, while `is_valid_number()` performs a more thorough validation including prefix and region checks. For strict validation, always use `is_valid_number()`.
fix
Use `phonenumbers.is_valid_number(parsed_number)` for comprehensive validation. Use `is_possible_number()` for a quicker, less strict check when performance is critical (e.g., filtering a large dataset).
affects: All versions
gotchaThe `phonenumbers` library's `PhoneNumber` objects are typically immutable and should be created using the `phonenumbers.parse()` function. Direct instantiation of `PhoneNumber` objects is not the recommended or supported way to work with the library.
fix
Always use `phonenumbers.parse(number_string, region_code)` to obtain a `PhoneNumber` object.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'phonenumbers'
This error often occurs when a project's dependencies expect the full `phonenumbers` library, but `phonenumberslite` is installed, or when `phonenumberslite` is installed but the import statement incorrectly tries to access the top-level `phonenumbers` package directly rather than the specific `phonenumbers` submodule (which exists within the `phonenumberslite` distribution). This can also happen if `phonenumberslite` itself is not correctly installed or recognized by the Python environment.
fix
Ensure that either `phonenumbers` or `phonenumberslite` is installed consistently throughout your project's dependencies. If `phonenumberslite` is explicitly desired, verify your import statements are correct (e.g., `import phonenumbers` will work as `phonenumberslite` provides the `phonenumbers` package), and check your Python environment's installed packages. If a dependency truly requires features only in the full `phonenumbers` library, you might need to switch to `pip install phonenumbers` instead of `phonenumberslite`.
phonenumbers.phonenumberutil.NumberParseException: (0) Missing or invalid default region.
This exception is raised when the `phonenumbers.parse()` function is called with a national number (without an international dialing code like '+44') and `None` is provided for the `region_code` argument, preventing the library from inferring the correct country context.
fix
When parsing national numbers, always provide a valid two-letter ISO 3166-1 country code as the `region_code` argument, or ensure the number includes the full E.164 international format (e.g., `+CCXXXXXXXXXX`).
```python
import phonenumbers

# Correct: Provide a region code for a national number
number = phonenumbers.parse("02081234567", "GB")
print(number)

# Correct: Use E.164 format (no region code needed)
number = phonenumbers.parse("+442081234567", None)
print(number)
```
AttributeError: module 'phonenumbers' has no attribute 'geocoder'
This error occurs when using `phonenumberslite` and attempting to import or access functionality related to geocoding, carrier information, or timezone data (e.g., `phonenumbers.geocoder`, `phonenumbers.carrier`, `phonenumbers.timezone`). `phonenumberslite` is a stripped-down version of the main `phonenumbers` library, specifically designed to omit these larger data packages to reduce its footprint.
fix
If your application requires geocoding, carrier, or timezone functionality, you must install the full `phonenumbers` library instead of `phonenumberslite`.
```bash
pip uninstall phonenumberslite
pip install phonenumbers
```
Then, your imports like `from phonenumbers import geocoder` will work correctly.
phonenumbers.phonenumberutil.NumberParseException: (1) The string supplied did not seem to be a phone number.
This exception indicates that the input string provided to `phonenumbers.parse()` could not be interpreted as a phone number at all, even after attempting to infer a region or with a provided region code. It typically means the input is malformed, contains non-numeric characters in unexpected places, or is simply not a phone number.
fix
Ensure that the input string is a plausible phone number before attempting to parse it. You might want to pre-process the input to remove irrelevant characters or validate its basic structure. Always wrap parsing calls in a `try-except` block to handle invalid inputs gracefully.
```python
import phonenumbers

try:
    # Example of an unparseable string
    number = phonenumbers.parse("gibberish", None)
    print(number)
except phonenumbers.phonenumberutil.NumberParseException as e:
    print(f"Error parsing number: {e}")

# A valid, parseable number
try:
    number = phonenumbers.parse("+15551234567", None)
    print(number)
except phonenumbers.phonenumberutil.NumberParseException as e:
    print(f"Error parsing number: {e}")
```
Upgrade
Version history
9.0.38latest on PyPI · released Aug 28, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
phonenumberslite — pip install phonenumberslite · libregistry