{"id":24235,"library":"phone-iso3166","title":"phone-iso3166","description":"A Python library that maps phone numbers (E.164 format) to their corresponding country codes (ISO 3166-1 alpha-2). Version 0.4.1 provides a simple `CountryCodeResolver` class and a convenience function `phone_country`. Lightweight with no external dependencies.","status":"active","version":"0.4.1","language":"python","source_language":"en","source_url":"https://github.com/offmango/phone-iso3166","tags":["phone","country","iso-3166","telephone","mapping"],"install":[{"cmd":"pip install phone-iso3166","lang":"bash","label":"Latest from PyPI"}],"dependencies":[],"imports":[{"wrong":"from phone_iso3166 import country_code","symbol":"CountryCodeResolver","correct":"from phone_iso3166 import CountryCodeResolver"}],"quickstart":{"code":"from phone_iso3166 import country_code\n\n# Example with a valid US number\nphone = '+14155552671'\ncode = country_code(phone)\nprint(code)  # Output: US\n\n# Example with a UK number\nphone2 = '+442071838750'\ncode2 = country_code(phone2)\nprint(code2)  # Output: GB","lang":"python","description":"Import the `country_code` function and pass an E.164 formatted phone number (string with leading +). Returns ISO 3166-1 alpha-2 country code or None if not found."},"warnings":[{"fix":"Always include the '+' prefix, e.g., '+14155552671'.","message":"Input must be in E.164 format with leading '+'. Without the '+', the library fails silently or returns None.","severity":"gotcha","affected_versions":"all"},{"fix":"Use in conjunction with a phone number validation library like `phonenumbers` if you need validation.","message":"The library does not validate the phone number's correctness; it only maps based on the country code prefix. Any number starting with '+1' will map to US (or Canada), even if the number is invalid.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `country_code` function instead of instantiating `CountryCodeResolver`.","message":"The `CountryCodeResolver` class is functional but the simpler `country_code` function is preferred. The class may be removed in future versions.","severity":"deprecated","affected_versions":"<=0.4.1"}],"env_vars":null,"search_vec":"'-1':20 '-2':22 '-3166':44 '0.4.1':24 '3166':19 'alpha':21 'class':29 'code':17 'conveni':32 'correspond':15 'countri':16,35,42 'countrycoderesolv':28 'depend':40 'e.164':11 'extern':39 'format':12 'function':33 'iso':18,43 'iso3166':3 'librari':6 'lightweight':36 'map':8,46 'number':10 'phone':2,9,34,41 'phone-iso3166':1 'provid':25 'python':5 'simpl':27 'telephon':45 'version':23","created_at":"2026-05-01T08:11:59.925048+00:00","updated_at":"2026-05-01T08:11:59.925048+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nImportError: cannot import name 'CountryCodeResolver' from 'phone_iso3166' (/tmp/tmpdsuxqop6/venv/lib/python3.12/site-packages/phone_iso3166/__init__.py)"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.4.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/phone-iso3166/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}