{"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":[{"note":"","wrong":"","symbol":"country_code","correct":"from phone_iso3166 import country_code"},{"note":"Common mistake: importing from internal module, but public API is directly from package.","wrong":"from phone_iso3166.resolver import CountryCodeResolver","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,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Upgrade to the latest version: `pip install --upgrade phone-iso3166`. Use `from phone_iso3166 import country_code`.","cause":"Incorrect import path or outdated version. The `country_code` function was added in version 0.4.0. If using an older version, it won't exist.","error":"AttributeError: module 'phone_iso3166' has no attribute 'country_code'"},{"fix":"Ensure the phone number is in E.164 format with a leading '+' and only digits after that, e.g., '+14155552671'.","cause":"The input phone number is missing the '+' prefix or contains non-numeric characters after the '+'.","error":"phone_iso3166.exceptions.InvalidPhoneNumber: Invalid phone number format"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}