DEV Community

Cover image for How to get phone number information using Python ?
Prakash Singh
Prakash Singh

Posted on • Edited on

How to get phone number information using Python ?

In order to get details of any mobile number. We can use an inbuilt library of python i.e "phonenumbers". And modules present inside this library are "geocoder", "carrier" and "timezone".

Step 1: install the library "phonenumbers"

!pip install phonenumbers
Enter fullscreen mode Exit fullscreen mode



Step 2: import library

import phonenumbers
Enter fullscreen mode Exit fullscreen mode



Step 3: take user's phone number and parse it

a = input("Enter Phone Number: ")
# Parsing
ph_no = phonenumbers.parse(a)
Enter fullscreen mode Exit fullscreen mode



Step 4:
geocoder : this module is used to get the location of your number.

from phonenumbers import geocoder
# Location Of Number
print(geocoder.description_for_number(ph_no,"en"))
Enter fullscreen mode Exit fullscreen mode



Step 5:
carrier : this module is used to get the service_provider's name of your number.

from phonenumbers import carrier
# Service_Provider's Name
print(carrier.name_for_number(ph_no,"en"))
Enter fullscreen mode Exit fullscreen mode



Step 6:
timezone : this module tells the timezone of the phone number.

from phonenumbers import timezone
# Timezone
print(timezone.time_zones_for_number(ph_no))
Enter fullscreen mode Exit fullscreen mode

Full Code : Click Here

Top comments (0)