Registry / serialization / phone-iso3166

phone-iso3166

JSON →
library0.4.1pypypiunverified

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.

pip install phone-iso3166
INSTALL
IMPORT
SIG · PHONE-ISO3166
P
phone-iso3166
serializationpythonv0.4.1
Install
1.6s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.4.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.2MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CountryCodeResolver
✓ from phone_iso3166 import CountryCodeResolver
✗ from phone_iso3166 import country_code

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.

from phone_iso3166 import country_code # Example with a valid US number phone = '+14155552671' code = country_code(phone) print(code) # Output: US # Example with a UK number phone2 = '+442071838750' code2 = country_code(phone2) print(code2) # Output: GB
Debug
Known issues
gotchaInput must be in E.164 format with leading '+'. Without the '+', the library fails silently or returns None.
fix
Always include the '+' prefix, e.g., '+14155552671'.
affects: all
gotchaThe 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.
fix
Use in conjunction with a phone number validation library like `phonenumbers` if you need validation.
affects: all
deprecatedThe `CountryCodeResolver` class is functional but the simpler `country_code` function is preferred. The class may be removed in future versions.
fix
Use `country_code` function instead of instantiating `CountryCodeResolver`.
affects: <=0.4.1
Upgrade
Version history
0.4.1latest on PyPI · released Aug 18, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
phone-iso3166 — pip install phone-iso3166 · libregistry