Menu Close
Get Phone Number Info Using Python

How to Get Phone Number Info Using Python

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

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 pip command.

pip install phonenumbers

Country name using phone number:

To get the country name using phone number, you have to use 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)

Output will be:- India

Service provider name using phone number:

To get the country name using phone number, you have to use 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)

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 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 national phone number, you can use following code.

import phonenumbers
x = phonenumbers.parse("+9173xxxxxxxx", None)
print(phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.NATIONAL))

Output will be:- 073999 99999

Format international phone number:

To format international phone number, you can use following code.

import phonenumbers
x = phonenumbers.parse("+9173xxxxxxxxxx", None)
print(phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.NATIONAL))

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 a Python programmer and want to learn this type of program.

For More Information:- Click Here

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *