DEV Community

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

Posted on • Edited on

6 4

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay