Metadata-Version: 2.4
Name: py-phone-number-fmt
Version: 2.0.3
Summary: Sanitize, validate and format phone numbers into E.164 valid phone numbers.
Home-page: https://github.com/SectorLabs/py-phone-number-fmt
Author: Sector Labs
Author-email: open-source@sectorlabs.ro
License: MIT License
Keywords: phone number,phone,formatting,validation
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: phonenumbers<=10.0.0,>=8.13.33
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: summary

# py-phone-number-fmt

[![License](https://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
[![PyPi](https://badge.fury.io/py/py-phone-number-fmt.svg)](https://pypi.python.org/pypi/py-phone-number-fmt)
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/SectorLabs/py-phone-number-fmt/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/SectorLabs/py-phone-number-fmt/tree/master)

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](./tests/test_format_phone_number.py)

## 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
    )
