Skip to main content

Google's libphonenumber on steroids.

Project description

py-phone-number-fmt

License PyPi CircleCI

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

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'

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
)

Project details


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-1.0b1.tar.gz (4.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page