{"name":"python-phonenumbers: Google's libphonenumber Port for Python","description":"`python-phonenumbers` is a robust Python port of Google's highly acclaimed `libphonenumber` library. It offers comprehensive functionality for parsing, validating, and formatting international phone numbers, making it an indispensable tool for global applications. This library ensures accurate and standardized phone number handling across diverse regions.","github":"https://github.com/daviddrysdale/python-phonenumbers","url":"https://osrepos.com/repo/daviddrysdale-python-phonenumbers","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/daviddrysdale-python-phonenumbers","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/daviddrysdale-python-phonenumbers.md","json":"https://osrepos.com/repo/daviddrysdale-python-phonenumbers.json","topics":["Python","Phone Numbers","libphonenumber","Telephony","Internationalization","Data Validation","Parsing","Formatting"],"keywords":["Python","Phone Numbers","libphonenumber","Telephony","Internationalization","Data Validation","Parsing","Formatting"],"stars":null,"summary":"`python-phonenumbers` is a robust Python port of Google's highly acclaimed `libphonenumber` library. It offers comprehensive functionality for parsing, validating, and formatting international phone numbers, making it an indispensable tool for global applications. This library ensures accurate and standardized phone number handling across diverse regions.","content":"## Introduction\n\n`python-phonenumbers` is the official Python port of Google's `libphonenumber` library, a powerful and widely used tool for handling international phone numbers. This library provides a comprehensive suite of functionalities, including parsing, validation, formatting, and extracting metadata for phone numbers from various countries. It's designed to work seamlessly across Python 2.5-2.7 and Python 3.x, offering a consistent experience for developers.\n\nWhether you need to verify user input, standardize phone number displays, or extract geographical information, `python-phonenumbers` offers a reliable and well-maintained solution, mirroring the capabilities of its Java counterpart.\n\n## Installation\n\nGetting started with `python-phonenumbers` is straightforward. You can install it using pip:\n\nbash\npip install phonenumbers\n\n\n## Examples\n\nLet's explore some of the core functionalities of `python-phonenumbers` with practical examples.\n\n### Parsing and Validation\n\nThe library allows you to parse phone numbers from strings and then validate them for possibility and validity.\n\npython\nimport phonenumbers\n\n# Parse a number with a known region\nx = phonenumbers.parse(\"020 8366 1177\", \"GB\")\nprint(x)\n# Output: Country Code: 44 National Number: 2083661177 Leading Zero: False\n\n# Parse an E.164 number\ny = phonenumbers.parse(\"+442083661177\", None)\nprint(y)\n# Output: Country Code: 44 National Number: 2083661177 Leading Zero: False\n\n# Check if numbers are possible or valid\ninvalid_number = phonenumbers.parse(\"+120012301\", None)\nprint(f\"Is possible: {phonenumbers.is_possible_number(invalid_number)}\") # False\nprint(f\"Is valid: {phonenumbers.is_valid_number(invalid_number)}\")     # False\n\nvalid_but_unassigned = phonenumbers.parse(\"+12001230101\", None)\nprint(f\"Is possible: {phonenumbers.is_possible_number(valid_but_unassigned)}\") # True\nprint(f\"Is valid: {phonenumbers.is_valid_number(valid_but_unassigned)}\")     # False (NPA 200 not used)\n\n\n### Formatting Phone Numbers\n\nYou can format parsed `PhoneNumber` objects into various standard formats.\n\npython\nimport phonenumbers\n\nnumber = phonenumbers.parse(\"+442083661177\", None)\n\nprint(f\"National format: {phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.NATIONAL)}\")\n# Output: National format: 020 8366 1177\n\nprint(f\"International format: {phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.INTERNATIONAL)}\")\n# Output: International format: +44 20 8366 1177\n\nprint(f\"E.164 format: {phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.E164)}\")\n# Output: E.164 format: +442083661177\n\n\n### Geocoding and Carrier Information\n\nThe library also provides extended functionality to retrieve geographical and carrier information for phone numbers. Note that these require importing specific sub-packages.\n\npython\nfrom phonenumbers import geocoder, carrier\nimport phonenumbers\n\n# Geocoding\nch_number = phonenumbers.parse(\"0431234567\", \"CH\")\nprint(f\"Location (English): {geocoder.description_for_number(ch_number, 'en')}\")\n# Output: Location (English): Zurich\n\n# Carrier information\nro_number = phonenumbers.parse(\"+40721234567\", \"RO\")\nprint(f\"Carrier (English): {carrier.name_for_number(ro_number, 'en')}\")\n# Output: Carrier (English): Vodafone\n\n\n## Why Use `python-phonenumbers`?\n\n`python-phonenumbers` is an indispensable library for any application dealing with phone numbers globally. Its key advantages include:\n\n*   **Accuracy and Reliability**: Directly ported from Google's `libphonenumbers`, it inherits a vast and frequently updated dataset of phone number metadata, ensuring high accuracy in parsing and validation.\n*   **Internationalization**: Supports phone numbers from all over the world, handling country codes, national prefixes, and various formatting conventions.\n*   **Comprehensive Features**: Beyond basic parsing and formatting, it offers advanced features like \"as-you-type\" formatting, finding numbers in text, geocoding, and carrier identification.\n*   **Active Maintenance**: The library is actively maintained, keeping pace with changes in global telephony standards and data.\n*   **Memory Management**: It intelligently loads metadata on-demand, and provides options for managing memory overhead for extended functionalities.\n\n## Links\n\n*   **GitHub Repository**: <a href=\"https://github.com/daviddrysdale/python-phonenumbers\" target=\"_blank\">https://github.com/daviddrysdale/python-phonenumbers</a>\n*   **Official Documentation**: <a href=\"https://daviddrysdale.github.io/python-phonenumbers/\" target=\"_blank\">https://daviddrysdale.github.io/python-phonenumbers/</a>\n*   **PyPI Package**: <a href=\"https://pypi.org/project/phonenumbers/\" target=\"_blank\">https://pypi.org/project/phonenumbers/</a>","metrics":{"detailViews":1,"githubClicks":1},"dates":{"published":null,"modified":"2026-07-30T07:43:02.000Z"}}