py-phone-number-fmt
Sanitize, validate and format phone numbers into E.164 valid phone numbers.
Google's libphonenumber on steroids. Tries all sorts of crazy combinations in an attempt to create a valid phone number. Useful for those of us who have to deal with poorly sanitized data.
Installation
$ pip install py-phone-number-fmt
Usage
Retrieve first valid number
from phonenumberfmt import format_phone_number
# implied phone region is the country of which to
# use the dialing prefix in case the number appears
# to be local
result = format_phone_number('778\173 0.92', implied_phone_region='RO')
assert result == '+40778173092'
Retrieve all valid numbers
# implied phone region is the country of which to
# use the dialing prefix in case the number appears
# to be local
result = format_phone_number_list('+40773818041 / +97172273000', implied_phone_region='RO')
assert result == ['+40778173092', '+97172273000']
The resulting phone number will be formatted according to the E.164 standard. Want to change the output format? Pass the third, optional parameter fmt with a valid member of phonenumbers.NumberFormat:
from phonenumbers import NumberFormat
result = format_phone_number(
'778\173 0.92',
implied_phone_region='RO',
fmt=NumberFormat.INTERNATIONAL, # default is NumberFormat.E164
)
Metadata
Release files for py-phone-number-fmt 2.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| py_phone_number_fmt-2.0.3.tar.gz | 6.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_phone_number_fmt-2.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.3 kB
Release files / py_phone_number_fmt-2.0.3.tar.gz
| Download URL | py_phone_number_fmt-2.0.3.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d7c9ef865121516f9f4048f84775abfafb66a3c951a0e7ca92b713d60e8ea607
|
|
BLAKE2b-256 checksum How to use checksums |
1091ae7c338510422df789429fd4b0b011c320f8aaaa09db59ec228fced834d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Release files / py_phone_number_fmt-2.0.3-py3-none-any.whl
| Download URL | py_phone_number_fmt-2.0.3-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b08bef80d045cb9251f177b25198f05378e7f5dfc11f4c8692d3c91a94a47ad
|
|
BLAKE2b-256 checksum How to use checksums |
0144534e2704dec59567892747f69dfbd4ecb8b0f9b9a184d64bd491a63a5119
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|