Skip to main content

py-phone-number-fmt

License PyPi CircleCI

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.

See the list of test cases

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
)

Download files

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

Source Distribution

py_phone_number_fmt-2.0.3.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

py_phone_number_fmt-2.0.3-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file py_phone_number_fmt-2.0.3.tar.gz.

File metadata

  • Download URL: py_phone_number_fmt-2.0.3.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for py_phone_number_fmt-2.0.3.tar.gz
Algorithm Hash digest
SHA256 d7c9ef865121516f9f4048f84775abfafb66a3c951a0e7ca92b713d60e8ea607
MD5 2b149e3711609cde4a36c66fd4f22ce7
BLAKE2b-256 1091ae7c338510422df789429fd4b0b011c320f8aaaa09db59ec228fced834d9

See more details on using hashes here.

File details

Details for the file py_phone_number_fmt-2.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for py_phone_number_fmt-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1b08bef80d045cb9251f177b25198f05378e7f5dfc11f4c8692d3c91a94a47ad
MD5 4e698d27bed22b0f8753a42f2e2c0aa4
BLAKE2b-256 0144534e2704dec59567892747f69dfbd4ecb8b0f9b9a184d64bd491a63a5119

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.3 This release

2 files

2.0.2

2 files

2.0.0

2 files

1.1

1 file

1.0

1 file

Supported by

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