Get Phone Number Information using Python

In this article, you will learn how you can get the information about phone number like the country name to which the phone number belongs to, or the network service provider name of that phone number just by writing a simple Python program. Python provides a module name phonenumbers for this task. This article is Python’s port of Google’s libphonenumber library.

Installation
Install the package phonenumbers using the below command in your command prompt.

pip install phonenumbers

Example 1: Python program to get the country name to which phone number belongs:

filter_none

edit
close

play_arrow

link
brightness_4
code

import phonenumbers
  
# geocoder: to know the specific 
# location to that phone number
from phonenumbers import geocoder
  
   
phone_number = phonenumbers.parse("Number with country code"
# Indian phone number example: +91**********
# Nepali phone number example: +977********** 
   
      
# this will print the country name
print(geocoder.description_for_number(phone_number, 
                                      'en'))   

chevron_right


Output:

India

Example 2: Python program to get the service provider name to that phone number



filter_none

edit
close

play_arrow

link
brightness_4
code

import phonenumbers
  
# carrier: to know the name of 
# service provider of that phone number
from phonenumbers import carrier
  
   
service_provider = phonenumbers.parse("Number with country code")
# Indian phone number example: +91**********
# Nepali phone number example: +977**********
   
      
# this will print the service provider name
print(carrier.name_for_number(service_provider,
                              'en')) 

chevron_right


Output:

Airtel

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Possess good Mathematical and Statistical Foundation Data Science Enthusiast Addicted to Python

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.