Find bank branch name from IFSC code in Python

In this tutorial, we are going to learn how can we Find bank branch names from IFSC code in Python. It’s very easy and simple, with just a few lines of code. Let’s see how it will work.

As you know python offers various modules and libraries performing various different types of tasks. Here we are going to use the request module from python. We are asking for details from Razorpay.

Using the request module we can send HTTP requests using Python. The HTTP request returns data according to it.
Before proceeding towards the actual code let’s download this module to our system using the pip command.

pip install requests

After successful installation of the module let’s proceed towards code. The full code is given below.

# Importing modules
import requests as req

# Url for sending HTTP request
URL = "https://ifsc.razorpay.com/"

# taking IFSC code as input
IFSC_Code = input("Enter IFSC code : ")

#Url to request HTTP
final_url = URL+IFSC_Code

# getting data
get_data = req.get(final_url).json()

# printing bank branch name
bank = get_data['BANK']
branch = get_data['BRANCH']
print(bank,branch)

 

As you can see in the above code first we are importing the request module as req. Then we have the URL of razor pay for sending the HTTP request. After doing that we are taking IFSC code as input from the user so that we can fetch details.

For getting details of banks associated with that particular IFSC code we are using the get method. Here in the get function, we are giving final_url to request HTTP which is consists of Razorpay URL + IFSC code. We are storing that data in a variable named get_data. The .json() here is used for transmitting data in webpages so that output can be well structured.

Initially, this data contains all information about the bank such as Address, Branch, code, state, etc.  Since we are using JSON, Output will be returned as a key: value pair. So we have to extract the Branch name from this data we can do this by passing a particular key. Here we are retrieving that data in two separate variables bank, branch And finally, we are printing that Bank Branch name as output.

Let’s give some input to our code and see what it will return.

Output

Enter IFSC code : SBIN0000371
State Bank of India ACHALPUR

For extracting data from JSON you can also refer to the following tutorial.

Python program to extract a single value from JSON response (Using API call)

Leave a Reply

Your email address will not be published.