In this article, we are going to learn How to get the Phone Number information using python programming.
At the end of this article, you will be able to get the phone information like country name, service provider name using your phone number.
Python provides a package named phonenumbers
which are used to get the phone numbers information. phonenumbers Python package provides the best methods to get access to the phone numbers information
Headings of Contents
What is Python phonenumbers package?
phonenumbers
is an external package of Python which provide lots of methods to access the phone number information using phone number.
If you have a company phone number, Then you are able to go through this article.
Installation:
To use phonenumbers
, You have to install it by using the pip
command.
pip install phonenumbers
Country name using phone number:
To get the country name using the phone number, you have to use the following code.
import phonenumbers
#import geocoder to get the location of phone number
from phonenumbers import geocoder
phone_number = phonenumbers.parse('you phone number with country code')
country_name = geocoder.description_for_number(phone_number, 'en')
print(country_name)
The output will be:- India
Service provider name using phone number:
To get the country name using the phone number, you have to use the following code.
import phonenumbers
#import carrier to get the location of the phone number
from phonenumbers import carrier
phone_number = phonenumbers.parse('you phone number with country code')
service = carrier.name_for_number(phone_number, 'en')
print(service)
The output will be:- Reliance Jio
Get the time zone of phone number.
To get the time zone of the phone number, you have to import the timezone module from Python phonenumbers
package.
import phonenumbers
#import timezone to get the location of the phone number
from phonenumbers import timezone
phone_number = phonenumbers.parse('you phone number with country code')
timezone = timezone.time_zones_for_number(phone_number)
print(timezone)
Output will be:- (‘Asia/Calcutta’,)
Format national phone number:
To format a national phone number, you can use the following code.
import phonenumbers
x = phonenumbers.parse("+9173xxxxxxxx", None)
print(phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.NATIONAL))
The output will be:- 073999 99999
Format international phone number:
To format an international phone number, you can use the following code.
import phonenumbers
x = phonenumbers.parse("+9173xxxxxxxxxx", None)
print(phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.NATIONAL))
The output will be:- 073999 99999
Conclusion:
In this tutorial, you have learned how to get phone number info using Python. If you want to perform the basic operation with a phone number, Then Python phonenumbers
package is best
option.
I hope this article will help you. if you like this article, please comment and share it with your friends who want to become Python programmers and want to learn this type of program.
For More Information:- Click Here