Skip to main content

Contains the country codes from ISO 3166-1 based on the code based on:

https://github.com/deactivated/python-iso3166/

But also has the MCC and MNC codes based on the Wikipedia page:

http://en.wikipedia.org/wiki/List_of_mobile_country_codes

As well as the latest released listing from ITU:

http://www.itu.int/dms_pub/itu-t/opb/sp/T-SP-E.212B-2014-PDF-E.pdf

Note that MCC codes for a country can be:

  • None (no MCC code)

  • a string (where a country has one code)

  • a tuple of strings (where a country has more than one code)

Installation

$ pip install mobile-codes

Usage

>>> import mobile_codes

Lookup by Mobile Country Code (MCC):

>>> mobile_codes.mcc("648")
[Country(name=u'Zimbabwe', alpha2='ZW', alpha3='ZWE', numeric='716', mcc='648')]
>>> mobile_codes.mcc("311")
[Country(name=u'Guam', alpha2='GU', alpha3='GUM', numeric='316', mcc=('310', '311')),
 Country(name=u'United States', alpha2='US', alpha3='USA', numeric='840', mcc=('310', '311', '313', '316'))]
>>> mobile_codes.mcc("313")
[Country(name=u'United States', alpha2='US', alpha3='USA', numeric='840', mcc=('310', '311', '313', '316'))]

Lookup by name, alpha2, alpha3 (all case insensitive):

>>> mobile_codes.alpha3("CAN")
Country(name=u'Canada', alpha2='CA', alpha3='CAN', numeric='124', mcc='302')
>>> mobile_codes.alpha2("CA")
Country(name=u'Canada', alpha2='CA', alpha3='CAN', numeric='124', mcc='302')
>>> mobile_codes.name('canada')
Country(name=u'Canada', alpha2='CA', alpha3='CAN', numeric='124', mcc='302')

Lookup operators by mcc (returns a list of all operators):

>>> mobile_codes.operators('302')
[Operator(mcc='302', mnc='220', brand='Telus', operator=u'Telus'),
 Operator(mcc='302', mnc='221', brand='Telus', operator=u'Telus'),...

Lookup operator by mcc and Mobile Network Code (MNC):

>>> mobile_codes.mcc_mnc('722', '070')
Operator(mcc='722', mnc='070', brand='Movistar', operator=u'Movistar')

All lookups raise a KeyError if the requested value is not found.

Development

If you want to do development on the library, follow these steps:

  • Create a virtualenv

  • bin/pip install -r requirements/tests.txt

  • bin/nosetests -s mobile_codes

Contributors

  • Hanno Schlichting (hannosch)

  • Jared Kerim (jaredkerim)

Changes

0.6 - 2014-10-14

  • Move network and country constants into JSON files

  • Incorporate ITU data for operators

0.5 - unreleased

0.4 - 2014-06-13

  • Declare compatibility with Python 3.4.

  • Fix a number of country to mcc mappings.

  • Issue #9: Fix typo in mcc for Yemen.

  • Issue #10: Allow 310 as a mcc value for Puerto Rico.

0.3 - 2014-05-14

  • Changed mcc API to always return a list, possibly empty, possibly containing multiple countries.

0.2.2 - 2014-04-22

  • Some tests, docs changes and updates to the records, thanks hannosch.

0.2 - 2013-10-26

  • Added in MNC codes and a script to scrape them.

0.1 - 2013-10-22

  • Added in MCC codes and a lookup.

  • Made completely lazy, no records generated or indexed until first asked for.

Metadata

Release files for mobile-codes 0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mobile-codes 0.7
File Size Uploaded
mobile-codes-0.7.tar.gz 82.0 kB Details

Release files / mobile-codes-0.7.tar.gz

Download URL mobile-codes-0.7.tar.gz
Size 82.0 kB
Tags Source
SHA-256 checksum
How to use checksums
24f86a85cc98afae2e991307b15414c6870db83db35d9878ea49c6c945717a71
BLAKE2b-256 checksum
How to use checksums
ad6633224ff6f5d4831a8721b273b5e95c10ab7bdfe0591e2706eb709c9cc192
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.7 This release

1 release file

0.4

1 release file

0.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page