daviddrysdale / python-phonenumbers Goto Github PK
View Code? Open in Web Editor NEWPython port of Google's libphonenumber
License: Apache License 2.0
Python port of Google's libphonenumber
License: Apache License 2.0
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
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)
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!
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?
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!
According to Wikipedia ( http://en.wikipedia.org/wiki/Area_codes_512_and_737 ):
To relieve telephone exchanges in the Austin area, area code 737, overlying 512, went into effect in July 2013.
This could be updated:
In [2]: phonenumbers.description_for_number(phonenumbers.parse('+17375555555'), 'en')
Out[2]: ''
In [3]: phonenumbers.description_for_number(phonenumbers.parse('+15125555555'), 'en')
Out[3]: u'Texas'
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
.
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.
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
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
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
Do you have plans to implement the getNumberType method from libphonenumber? This would be very useful...
https://github.com/daviddrysdale/python-phonenumbers/blob/dev/python/HISTORY doesn't list 7.3.0, or 7.3.1, but it lists the others.
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
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:
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:
from .util import ...
try
blocks to use the except ... as ...
syntaxlong
by int
text_type
(unicode
or str
) and xrange
(xrange
or range
) for compatibilitysys.maxint
by something else -- I used sys.maxsize
but that's semantically wrong, another hardcoded constant would be betterAt 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.
Deleted
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?
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.
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.
Python 3.5 shows "DeprecationWarning: bad escape \p" for the regular expression on line 160 of phonenumbermatcher.py.
See http://bugs.python.org/issue23622 for the change in Python that added the warning.
+264 64 414500 does not recognized as valid but should be.
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)?
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.
number '01386000' with country code 'DE', should be a valid number, however
import phonenumbers
phone_obj = phonenumbers.parse('0138 6000', 'DE')
assert not phonenumbers.is_valid_number(phone_obj)
http://libphonenumber.googlecode.com/svn/trunk/javascript/i18n/phonenumbers/demo-compiled.html
Should look like this: str(timezone.time_zones_for_number(gb_number))
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_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)
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
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
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
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
Currently there are only beta releases on https://pypi.python.org/simple/phonenumbers/
Would it be possible to have final releases on PyPI, so that pip doesn't complain about version numbers?
http://www.pip-installer.org/en/latest/logic.html#pre-release-versions
Hi,
I have a country code, how I can the national country prefix for it?
Regards,
Dacian
According to ITU standard, from Oct 1 2015, mobile number starting with 173 is a valid range in CN (http://www.itu.int/oth/T020200002B/en), owning by China Telecom
This has been an accepted issue in libphonenumber googlei18n/libphonenumber#947
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.
HI,
We just got an UnicodeDecodeError for an invalid user input: '\xe2\x80\x8b1-123-456-789'. I suggest we catch that in the library and throw out a NumberParseException.
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'
According to ITU standard, from Oct 1 2015, mobile number starting with 173 is a valid range in CN (http://www.itu.int/oth/T020200002B/en), owning by China Telecom
This has been an accepted issue in libphonenumber googlei18n/libphonenumber#947
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.
Test case: +972 58 555 6666
>>> import phonenumbers
>>> x = phonenumbers.parse("+972 58 555 6666", None)
>>> phonenumbers.is_valid_number(x)
False
Testing the same number on http://libphonenumber.appspot.com/ shows that the number is perfectly valid.
This test case seems to fail with all Israeli numbers (+972
) within the 058
area code.
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)
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
Missing prefixes are for GG, IM, JE, by design.
See also: 5884943#comments
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
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.
>>> n = phonenumbers.parse("+5586998975814")
>>> phonenumbers.is_valid_number(n)
False
According to National Numbering Plan for Brazil , mobile numbers have been slowly migrating from '+55 XX XXXX XXXX' to '+55 XX 9XXXX XXXX'. Eventually these numbers could be 2-9.
The library recognizes this to be a valid mobile number: http://libphonenumber.appspot.com/
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
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.
How the original java library parse language code
zh
-> simplified chinesezh-tw
-> traditional chinesezh_Hant
-> unknown locale, use englishBut python library
zh
-> simplified chinesezh-tw
unknown locale, use englishzh_Hant
-> traditional chineseBelow 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
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)
~: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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.