Giter Club home page Giter Club logo

python-phonenumbers's People

Contributors

aa-turner avatar adamchainz avatar andyst avatar artnez avatar arturdryomov avatar benmanns avatar cclauss avatar cygnusb avatar daviddrysdale avatar jdufresne avatar jlaine avatar jonesnc avatar joshuadavidthomas avatar kavdev avatar keghani avatar lieryan avatar penmetsaa avatar pokoli avatar roubert avatar scop avatar skimat avatar stegayet avatar sushilshrestha avatar tasssadar avatar timgates42 avatar tobami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-phonenumbers's Issues

FIXED_LINE_OR_MOBILE issue

When I try to get FIXED_LINE_OR_MOBILE . My number +1 414-719-88XX is a mobile number with AT&T. But it says its an fixed line .

but on freecarrierlookup.com i got the genuine result

Phone Number: 14147198856
Carrier: ATT Mobility
Is Wireless: y ( mobile)
SMS Gateway Address: [email protected]
MMS Gateway Address: [email protected]

please help . where we will get the update

wrong parsing of russian number starting with 00

So that the country code is kept into the national number

phonenumbers.parse("+7 894 123 45 67", "RU")
PhoneNumber(country_code=7, national_number=8941234567, extension=None, italian_leading_zero=False, number_of_leading_zeros=None, country_code_source=None, preferred_domestic_carrier_code=None)

phonenumbers.parse("007 894 123 45 67", "RU")
PhoneNumber(country_code=7, national_number=78941234567, extension=None, italian_leading_zero=True, number_of_leading_zeros=2, country_code_source=None, preferred_domestic_carrier_code=None)

Maintain a changelog

It would be useful to know what changes between versions released to PyPI (without browsing commits). Would it be possible to keep a simple changelog that lists the changes between versions?

I ask as django-oscar depends on this package and it's tricky to know what range of versions to support.

Thanks!

Mobile number start with 8 or 7 Handle

  • Phone number start with 8 is not mapped to Mobile number ( Indian Mobile number)
  • Phone number start with 7 is not mapped to Mobile number ( Indian Mobile number)

Cannot install dev branch from pip

I want to use pip to install from the dev branch. But it fails because setup.py is not found in the repository root.

The following syntax is used to install straight from git repository:

sudo pip install git+git://github.com/daviddrysdale/python-phonenumbers.git@dev

Is it possible to move setup.py to the repository root to fix this? Alternatively, is it possible to run dev branch without maintaining a git clone of the repository on the target system?

Release notes?

First off, great library β€” thanks very much for providing it πŸ‘

I'm wondering if release notes or a changelog is available. I can't seem to find one, apologies if I've simply missed it ...

If there aren't release notes, would you consider adding them somewhere? It would make upgrading much simpler :)

Thanks!

National numbers outside the US and Canada are always prefixed with 01

When formatting a number from outside the US or Canada as a national number, this library always prepend a 01 in front.

Here's an example with a number from Mexico

num = phonenumbers.parse('+523222222099')
phonenumbers.format_number(num, phonenumbers.PhoneNumberFormat.NATIONAL)
// OUT: u'01 322 222 2099'

I'd expect the national number to be 322 222 2099.

Ecuador cellphone is treated as invalid

As in how to call abroad [1] to call ecuador numbers, you have to use a 9 after country code and before area code + number. However phone numbers is reporting a cell phone number as invalid.

  • phonenumbers.is_valid_number(phonenumbers.parse('+5936760xxxx)) == True
  • phonenumbers.is_valid_number(phonenumbers.parse('+59396760xxxx')) == False # 593 9 6760xxxx

[1] http://www.howtocallabroad.com/ecuador/

NumberParseException

Hi.
I've got an exception "(0) Could not interpret numbers after plus-sign" when trying to save phone number like "2146491379" - it's an US phone number. The thing is that it happens only to phone numbers starting with "2" or "+2".

Request Method: POST
Request URL: http://10.1.0.2/admin/profiles/profile/2/
Django Version: 1.4.5
Exception Type: NumberParseException
Exception Value: (0) Could not interpret numbers after plus-sign.
Exception Location: /.../.env/local/lib/python2.7/site-packages/phonenumbers/phonenumberutil.py in parse, line 2410
Python Executable: /usr/bin/python
Python Version: 2.7.3

Name: phonenumbers
Version: 5.7b2

Installing without version provided

Installation via pip returns error

$ pip install phonenumbers
Downloading/unpacking phonenumbers
  Could not find a version that satisfies the requirement phonenumbers (from versions: 4.2b1, 4.7b1, 3.9b1, 4.5b1, 4.3b1, 4.8b1, 3.7b1, 3.5b2, 4.0b1, 4.4b1, 4.6b1, 4.9b1, 4.1b1, 3.3a1, 5.0b1, 5.1b1, 5.2b1, 5.3b1, 5.6b1, 5.4b1, 5.5b1, 5.0b2, 5.7b1, 3.5b1, 5.8b1, 5.7b2)
Cleaning up...
No distributions matching the version for phonenumbers

Phone number length

Hi guys,

is that a built-in way to limit the phone number length? Because I enter numbers with 20 chars and they are accepted by the validator, although I believe there are no phone numbers that big.

Thanks

IR region numbers

Hi
Can you check phone numbers like +9812168560, please? They are formated (INTERNATIONAL) as +98 12168560, so the NDC length is zero. Moreover, I suspect that it is invalid number for the IR region.
Best
js

Porting to Python 3

Hello, this isn't really an issue, but I don't know where else to talk about this.

I need to use phonenumbers with Python 3.3.

The README talks about:

  • running 2to3, but I'm not sure how well that plays with pip.
  • the python3 branch, but the wording doesn't inspire a lot of confidence.

Current porting efforts keep compatibility with Python 2.5, which makes the shared-source approach one order of magnitude harder than targeting Python 2.6 as the lowest supported version.

Since I have some experience with porting to Python 3 (I ported Django, among other things), I tried to redo the porting for 2.6+ and 3.3+, which is all I need. It just required the following steps:

  • making relative imports explicit eg. from .util import ...
  • changing try blocks to use the except ... as ... syntax
  • removing long literals; I'm not sure why they're used instead of plain integers; this change makes a lot of noise in the tests
  • replacing long by int
  • adding text_type (unicode or str) and xrange (xrange or range) for compatibility
  • replacing sys.maxint by something else -- I used sys.maxsize but that's semantically wrong, another hardcoded constant would be better

At this point, the library appears to work ie. I can reproduce the examples in the documentation. However, for some reason, the tests (python setup.py test) fail massively, as if no data could be found for any country.

Finally I suggest the following fix to UnicodeMixin:

 class UnicodeMixin(object):  # pragma no cover
     """Define __str__ operator in terms of __unicode__ for Python 2/3"""
+    # Emulate the way the interpreter looks up magic methods
     if sys.version_info >= (3, 0):
-        __str__ = lambda x: x.__unicode__()
+        __str__ = lambda x: type(x).__unicode__(x)
     else:
-        __str__ = lambda x: unicode(x).encode('utf-8')
+        __str__ = lambda x: type(x).__unicode__(x).encode('utf-8')

It shouldn't matter except in weird subclassing schemes.

This isn't really actionnable, and I expect you to close this issue once you've read it, but I found it interesting to share this experience.

[EDIT] I accidentally sumbitted the issue while I was writing, I've completed my description since then.

What does phonenumbers.number_type() return?

I searched quite long but what does 0 and 1 as return of the method number_type() mean?

Is 0 for landline and 1 for mobile?

I cannot find any documentation about the return value.
Can anyone help me please?

is_valid_number returns false for some Argentina numbers, libphonenumber.appspot.com says they are valid mobile numbers

These two numbers in Argentina return false for is_valid_number on branch release-5.7b2:

>>> import phonenumbers
>>> x = phonenumbers.parse("+540348215617137", "AR")
>>> phonenumbers.is_valid_number(x)
False
>>>
>>> y = phonenumbers.parse("0344615614207", "AR")
>>> phonenumbers.is_valid_number(y)
False
>>>

In both cases, http://libphonenumber.appspot.com/ regards these as MOBILE numbers.

Problems with excessive memory usage

We are using phonennumbers, in order to be able to normalize phone numbers from 0660123123 for example to +48660123123 ITU-T E.164 format, knowing the ISO countr code the number is from (regardless of the format of the original number). This is a great piece of code which took us almost no time to integrate. Thanks for the porting work !!!
We noticed however after merging our code with this changes and deploying to rthe production server, suddenly our site stopped responding. We reverted back quickly and tried a few changes, and finally we narrowed it down to single line of code:

import phonenumbers

It seems that the library is awfully memory-hungry. After further checking - we found our that just importing phonenumbers increases the memory used by application by 50+MB. This is a django app we are running and before the import it was about 40 MB, so this is quite significant increase. Moreover it seems that there are some very bad effects, if the memory starts being swapped out to disc. Instead of observed moderate slowdown of the app, it basically stops responding. It seems that the code in your library is really hard trying to scan through the whole memory it's using and tries to bring the whole data back to memory.... Which - when you run several processes in parallell - can be disastrous because it seems that the processes are continuously swapping each other in back to memory/out to disk and the whole application stops responding.

Just to give a bit of background: we are running our django app in "controlled" environment of heroku where one "dyno" only has 512 MB of ram, and we are using gunicorn in front, that spawns several worker processes - this is in order to get scalability and be able to handle several requests in parallel per "dyno". So far we could easily run 4 workers per dyno but after adding phonenenumbers, the swapping out (and putting the site to halt) kicks in already at 2nd worker. We are running some other software there, like pgbouncer and the os itself takes a bit of memory, so we do not have all 512 MB available - it looks like we have around 180 MB. Which means for us that basically in order to get the same throughput with phonennumbers, we need to get 4x more dynos(!) (and on heroku you pay per dyno(!)). Obviously that's not really acceptable πŸ‘Ž . I know you mentioned at your wiki page that you are not that conscious about memory as the original Java library, because the library should be used in server environment... but it seems that assumption is not true for us, unfortunately.

We are looking into ways to solve it, so i have the following question. Is there a way to run the library in less-memory hungry mode ? How do the guys in Java lib did it? Maybe we can help somehow in moving it in the right direction of being less memory hungry? I guess the memory used comes from the need of doing type-ahead typing etc. features which are very useful for a mobile app, but less (if at all) useful for python code run at the server side (seems better to use it in javascript), so maybe that part can be trimmed down (or even completely removed, if this is the culprit). We only need one functionality: get a phone number and iso CC of where the number is from and produce ITU-T E.164 formatted number (regardless of the format of the original number), so maybe there is a way we could simply remove the other code and use the rest?

Any help greatly appreciated.

Get country code for international prefix

If I would have an valid internal number like +49123456789 is there any way I could get the country code of the numbers country (which would be in this example "de" or "DE" because its +49)?

Request: add how to contribute

i just wanted to add contribution (Algeria information) but dont find how, what i want to do is to edit regular expressions and add region match (for fixed line), but found the file containing DZ that is Auto-generated file and i should not edit it.

Parameters in wrong order on a function called from format_out_of_country_keeping_alpha_chars()

Arguments of PhoneMetadata.metadata_for_region_or_calling_code() on method format_out_of_country_keeping_alpha_chars() on phonenumberutil.py (line 1304) are in wrong order:

_# Metadata cannot be None because the country calling code is valid.
metadata_for_region = PhoneMetadata.metadata_for_region_or_calling_code(region_code, country_code)

Probably should be

Metadata cannot be None because the country calling code is valid.

metadata_for_region = PhoneMetadata.metadata_for_region_or_calling_code(country_code, region_code.upper())

As defined on phonemetadata.py

def metadata_for_region_or_calling_code(kls, country_calling_code, region_code):
if region_code == REGION_CODE_FOR_NON_GEO_ENTITY:
return kls.metadata_for_nongeo_region(country_calling_code, None)
else:
return kls.metadata_for_region(region_code, None)

setup.py test failed on kubuntu 12.04

I have been asked to use python-phonenumbers for a project.

I downloaded the zip, extracted to a directory, and ran

python setup.py test

The tail end of the long list of errors is as follows:

begin quote

'''

FAIL: testParseNumbersWithPlusWithNoRegion (tests.phonenumberutiltest.PhoneNumberUtilTest)

Traceback (most recent call last):
File "/home/Common/python-phonenumbers-dev/python/tests/phonenumberutiltest.py", line 2074, in testParseNumbersWithPlusWithNoRegion
self.assertEqual(NZ_NUMBER, phonenumbers.parse("tel:03-331-6005;phone-context=+64", "ZZ"))
AssertionError: PhoneNumber(country_code=64, national_number=33316005, extension=None, italian_leading_zero=False, number_of_leading_zeros=None, country_code_source=None, preferred_domestic_carrier_code=None) != PhoneNumber(country_code=64, national_number=33316005, extension=None, italian_leading_zero=True, number_of_leading_zeros=None, country_code_source=None, preferred_domestic_carrier_code=None)


Ran 516 tests in 1.431s

FAILED (failures=50, errors=306)
'''

end quote

Maybe python-phonenumbers depends on something I have not installed yet.

I will be moving to kubuntu 14.04 in the near future.

I would appreciate a suggestion on what to do next.

Thanks,

netvigator aka Rick Graves

[Installation via pip in virtualenv] ImportError: No module named shortdata

Traceback (most recent call last):
  File "<string>", line 16, in <module>
  File "/home/userdev/envs/userproject/build/phonenumbers/setup.py", line 40, in <module>
    from phonenumbers import __version__
  File "phonenumbers/__init__.py", line 79, in <module>
    from .asyoutypeformatter import AsYouTypeFormatter
  File "phonenumbers/asyoutypeformatter.py", line 32, in <module>
    from .phonenumberutil import _VALID_PUNCTUATION, REGION_CODE_FOR_NON_GEO_ENTITY
  File "phonenumbers/phonenumberutil.py", line 44, in <module>
    from .shortdata import _AVAILABLE_REGION_CODES as _AVAILABLE_SHORT_REGION_CODES
ImportError: No module named shortdata

international numbers error

Check the number like 0011404abcdefg (where a-g a digit) in the context of a region having 00 as the international prefix, e.g., PL. parse returns 1 and 404... and I think 0011404... is an incorrect international number dialed from PL (should be 001404...)

Best
js

Not correctly parsing australian numbers without area code prefix

When an australian number has no area code specified the national number returned does not add the missing area code.

Eg. 30004000 would be a brisbane phone number its national number would be 730004000 but:
phonenumbers.parse("30004000", "AU")

returns:
PhoneNumber(country_code=61, national_number=30004000L, extension=None, italian_leading_zero=False, country_code_source=None, preferred_domestic_carrier_code=None)

This leads to incorrect national and international numbers when formatted using format_number.

Is python-phonenumbers expected to provide this functionality or should i be pre processing the number and adding the prefix myself?

Thanks.

Leading 0s incorrectly coming in E.164 format

The expected output of E.164 formatted number is '+13432640000', but a leading 0 is included u'+103432642966'

>>> x=phonenumbers.parse('03432640000','US')
>>> x
PhoneNumber(country_code=1, national_number=3432640000, extension=None, italian_leading_zero=True, number_of_leading_zeros=None, country_code_source=None, preferred_domestic_carrier_code=None)
>>> phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.E164)
u'+103432640000'

Problem installing 6.0 on newly installed Ubuntu machine

I just tried installing phonenumbers on a newly installed Ubuntu 12.04 installation.

I'm running these versions of things:
Python: 2.7.3
pip: 1.5.1
virtualenv: 1.11.1

To repeat:

$ mkvirtualenv test
$ pip install phonenumbers
[... long list of byte compiled files ...]
Cleaning up...
Command /home/deploy/.virtualenvs/test/bin/python -c "import setuptools, tokenize;__file__='/home/deploy/.virtualenvs/test/build/phonenumbers/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-11ulaL-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/deploy/.virtualenvs/test/include/site/python2.7 failed with error code -9 in /home/deploy/.virtualenvs/test/build/phonenumbers
Storing debug log for failure in /home/deploy/.pip/pip.log

I've no idea what error code -9 means, but it works if I install version 5.9.2 instead.

PhoneNumber class methods and attributes

Is there a reason why PhoneNumber class doesn't have methods and attributes for validation and formatting the phone number? For templates and such it would seem easier to just write phone_number.international or phone_number.is_valid() instead of using phonenumbers.is_valid_number(phone_number) for example.

This seems to me like a design issue or maybe there's something I'm missing. Hopefully someone can clarify me.

Anyways I ended up writing my own PhoneNumber class. I'm not sure if there's a reason why the class was not designed this way.

import phonenumbers

class PhoneNumber(phonenumbers.phonenumber.PhoneNumber):
    def __init__(self, raw_number, country_code=None):
        self._phone_number = phonenumbers.parse(raw_number, country_code)
        super(PhoneNumber, self).__init__(
            country_code=self._phone_number.country_code,
            national_number=self._phone_number.national_number,
            extension=self._phone_number.extension,
            italian_leading_zero=self._phone_number.italian_leading_zero,
            raw_input=self._phone_number.raw_input,
            country_code_source=self._phone_number.country_code_source,
            preferred_domestic_carrier_code=
            self._phone_number.preferred_domestic_carrier_code
        )
        self.national = phonenumbers.format_number(
            self._phone_number,
            phonenumbers.PhoneNumberFormat.NATIONAL
        )
        self.international = phonenumbers.format_number(
            self._phone_number,
            phonenumbers.PhoneNumberFormat.INTERNATIONAL
        )
        self.e164 = phonenumbers.format_number(
            self._phone_number,
            phonenumbers.PhoneNumberFormat.E164
        )

    def is_valid(self):
        return phonenumbers.is_valid_number(self._phone_number)

Inconsistent treatment of French premium (4- and 6- digit) numbers

I noticed that French premium numbers (4- and 6- digit numbers starting with 1, 3, or 118) seem to be recognized for formatting, but return False in validity test, e.g.

p=phonenumbers.parse("118712", "FR")
str(phonenumbers.format_number(p, phonenumbers.PhoneNumberFormat.NATIONAL))
'118 712'
phonenumbers.is_valid_number(p)
False

theoretical number

Theoretically this number should belong to Russia I guess. +9782353434

It's a made up number. There is no country as +978 despite for 971, 972, 973, 974... However there is a country +9

What do you think?

PS: The method throws a NumberParseException.INVALID_COUNTRY_CODE

Canadian carrier data not supported?

Not sure if this is a question for you or the upstream people.

Parsing Canadian phone numbers doesn't give me any carrier information. Just wondering why and how it can be added.

List MNO of country

Hello!

How to get a mobile network operator's list of countries ? I want to get the list just using as parameters the alpha2 (fr) code of country or international code (+33).
Sorry for my english, I'm french man :)

Thx

Source not on pypi

Can you push a tar.gz to pypi for the latest release (3.9b1 as I write this)?

At the moment pypi's only got up to 3.7b1, which means that's the latest version that pip will install when asked to.

Geocoding results in Traditional Chinese

How the original java library parse language code

  • zh -> simplified chinese
  • zh-tw -> traditional chinese
  • zh_Hant -> unknown locale, use english

But python library

  • zh -> simplified chinese
  • zh-tw unknown locale, use english
  • zh_Hant -> traditional chinese

Below is the code demonstrating the problem

>>> from phonenumbers.geocoder import area_description_for_number
>>> print area_description_for_number(phonenumbers.parse("0800080123", "TW"), "zh")
屏东
>>> print area_description_for_number(phonenumbers.parse("0800080123", "TW"), "zh_tw")
Pingtung  // should be 屏東
>>> print area_description_for_number(phonenumbers.parse("0800080123", "TW"), "zh_Hant")
屏東 // should be Pingtung

Just for reference

  • 屏东 <- simplified chinese
  • 屏東 <- traditional chinese

PhoneNumberMatcher: documented functionality doesn't work

When trying to run example below I get no matches. Am I doing smth wrong?

python version: Python 3.4.3 :: Anaconda 2.3.0 (64-bit)

text = "Call me at (067) 97-28-961  r on 097922458 after 10am."
for match in phonenumbers.PhoneNumberMatcher(text, "RU"):
    print(match)

Crash parsing numbers for countries with blank metadata

~:python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import phonenumbers
>>> print phonenumbers.__version__
3.5b1
>>> phonenumbers.parse("+6921234567", "US")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.6-universal/egg/phonenumbers/phonenumberutil.py", line 2054, in parse
  File "build/bdist.macosx-10.6-universal/egg/phonenumbers/phonenumberutil.py", line 1885, in _maybe_strip_national_prefix_carrier_code
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/re.py", line 188, in compile
    return _compile(pattern, flags)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/re.py", line 239, in _compile
    raise TypeError, "first argument must be string or compiled pattern"
TypeError: first argument must be string or compiled pattern

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.