Python script to fetch Bank details from IFSC | Daily Python #9

Ajinkya Sonawane
Daily Python
Published in
2 min readJan 13, 2020

This article is a tutorial on fetching Bank details from IFSC using Python and Razorpay IFSC Toolkit.

Snip of Razorpay IFSC Toolkit’s webpage

This article is a part of Daily Python challenge that I have taken up for myself. I will be writing short python articles daily.

Requirements:

  1. Python 3.0
  2. Pip

Install the following packages:

  1. requests— Library to making HTTP requests.
pip install requests

Let’s import the requests library

import requests

First, let’s visit the Razorpay IFSC Toolkit and see how to make requests to its API for fetching bank details.

Snip of the Razorpay IFSC Toolkit in action

Let’s define a class in Python that can fetch this JSON response for a given IFSC code and make these fields accessible using function calls.

class BankDetails:
'''
class to fetch the response of one Bank and
make it accessible through functions
'''
def __init__(self,IFSC_Code):
URL = "https://ifsc.razorpay.com/"
self.result = requests.get(URL+IFSC_Code).json()

def getBankName(self):
bankName = self.result['BANK']
print('Bank Name : ',bankName)
return bankName
def getBankContact(self):
bankContact = self.result['CONTACT']
print('Bank Contact : ',bankContact)
return bankContact
def getBankAddress(self):
bankAddr = self.result['ADDRESS']
print('Bank Address : ',bankAddr)
return bankAddr

def getBankBranch(self):
bankBranch = self.result['BRANCH']
print('Bank Branch : ',bankBranch)
return bankBranch
def getBankState(self):
bankState = self.result['STATE']
print('Bank State : ',bankState)
return bankState
def getBankCity(self):
bankCity = self.result['CITY']
print('Bank City : ',bankCity)
return bankCity

The above class requires a parameter that is the IFSC code while instantiating its object. The function calls make it easy to access the details of the particular Bank. Let’s create an object and see the working of the above code.

IFSC_Code = 'MAHB0001716'
bank = BankDetails(IFSC_Code)
bank.getBankName()
bank.getBankContact()
bank.getBankBranch()
bank.getBankAddress()
bank.getBankCity()
bank.getBankState()
Snip of the Output of the above code snippet

I hope this article was helpful, do leave some claps if you liked it.

Follow the Daily Python Challenge here:

--

--