Phone-ISO3166

Small project to map an E.164 (international) phone number to the ISO-3166-1 alpha 2 (two letter) country code, associated with that number.
Also provides mapping for E.212 (mobile network codes, mcc+mnc) to the country.
The package has no dependencies, and works on Py2.7+, Py3 and PyPy.
Simple Usage
To simply get a country code from a phone number or mcc, mnc.
>>> from phone_iso3166.country import *
>>> phone_country(45)
'DK'
>>> phone_country('+1 202-456-1111')
'US'
>>> phone_country(14412921234)
'BM'
>>> network_country(238, 1)
'DK'
Network names and codes
If you want more detailed information about the networks, such as the operator name use the functions in phone_iso3166.network.
>>> from phone_iso3166.network import *
>>> network(238, 1)
('DK', 'TDC Mobil')
>>> country_networks('DK')
[(238, 1, 'TDC Mobil'), (238, 2, 'Telenor'), (238, 3, 'MIGway A/S'),
(238, 4, 'NextGen Mobile Ltd T/A CardBoardFish'), (238, 6, 'Hi3G'),
(238, 8, 'Nordisk Mobiltelefon Danmark A/S'), (238, 10, 'TDC Mobil'),
(238, 43, 'MobiWeb Limited'), (238, 12, 'Lycamobile Denmark'),
(238, 13, 'Compatel Limited'), (238, 77, 'Tele2'), (238, 20, 'Telia'),
(238, 66, 'TT-Netvaerket P/S'), (238, 28, 'CoolTEL'),
(238, 30, 'Interactive Digital Media GmbH')]
More information
If want more information, you can easily use the country code with other python packages such as pycountry.
>>> from phone_iso3166.country import phone_country
>>> import pycountry
>>> phone = '+55 21 3814-2121'
>>> c = pycountry.countries.get(alpha_2=phone_country(phone))
>>> c.name
'Brazil'
>>> c.official_name
'Federative Republic of Brazil'
This package makes no attempt to understand the various input options for phone numbers, and assumes an international phone number. If you deal in fuzzy inputs, try phonenumbers.
>>> from phone_iso3166.country import phone_country
>>> import phonenumbers
>>> import pycountry
>>> local = phonenumbers.parse("020 8366 1177", "GB")
>>> phonenumbers.format_number(local, phonenumbers.PhoneNumberFormat.E164)
'+442083661177'
>>> cc = phone_country(str(local.country_code)+str(local.national_number))
>>> uk = pycountry.countries.get(alpha_2=cc)
>>> uk.name
'United Kingdom'
>>> uk.official_name
'United Kingdom of Great Britain and Northern Ireland'
>>> wh = phonenumbers.parse("0012024561111", "GB")
>>> cc_wh = phone_country(str(wh.country_code)+str(wh.national_number))
>>> cc_wh
'US'
Metadata
Release files for phone-iso3166 0.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| phone-iso3166-0.3.4.tar.gz | 33.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| phone_iso3166-0.3.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 67.5 kB
Release files / phone-iso3166-0.3.4.tar.gz
| Download URL | phone-iso3166-0.3.4.tar.gz |
|---|---|
| Size | 33.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f36246fc5b55acb53b53ed0d816a1b617cc49e262c8432920f48906aed1da9a
|
|
BLAKE2b-256 checksum How to use checksums |
2000d1b1d3f0a73fd85745a8d0d69090bc40116744622a93b2311ae5bcb61dd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.5.6
|
Release files / phone_iso3166-0.3.4-py3-none-any.whl
| Download URL | phone_iso3166-0.3.4-py3-none-any.whl |
|---|---|
| Size | 34.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
991b399b158c785e1cee55cfeb6c0fbb71377389d11233d67c4cfe8f7d3b58fe
|
|
BLAKE2b-256 checksum How to use checksums |
9728811a860d78df49cf0088c8bad90472cb8cf378090ae62a1319914027063d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5
|
Security for phone-iso3166 0.3.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.