How To Get Phone Details Using Python

- By Pratyush Mishra

·

2 min read

How To Get Phone Details Using Python

Hi everyone👋 , In this article, you will learn how you can get information about phone numbers, like the country name to which the phone number belongs, 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. You can refer to my YouTube video to see a working tutorial for better understanding and a step-by-step guide of the same.

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:

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'))

Output:

India

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

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'))

Output:

Airtel

Alright, guys! I hope this article was helpful for you if it is the leave your comments below. I will meet you in another article until then KEEP CODING🤗.

Â