Python script to search flights using Goibibo API | Daily Python #25

Ajinkya Sonawane
Daily Python
Published in
2 min readFeb 10, 2020

This article is a tutorial on how to search for flights by consuming the Goibibo API in Python.

Requirements:

  1. Python 3.0
  2. Pip

Install the following packages:

  1. requests — Library to making HTTP requests.
  2. pprint — PrettyPrinter:
pip install requests pprint

First, let’s sign up on the Goibibo’s API portal

Fill in the details and activate your account from the email received. You will now be able to access the API key and the Application ID, which will be used for making calls with the APIs.

First, let’s import the requests module

import requests
from pprint import PrettyPrinter
pp = PrettyPrinter()

Store the App ID and the API Key into variables for future use

AppID = "YOUR_GOIBIBO_APP_ID"
AppKey = "YOUR_GOIBIBO_APP_KEY"

The parameters required for fetching flights using the API

Let’s create a dictionary to store the values of these parameters

params = {
"app_id":AppID,
"app_key":AppKey,
"format":"json",
"source":"PNQ",
"destination":"BOM",
"dateofdeparture":"20200215",
"dateofarrival":"",
"":"",
"seatingclass":"E",
"adults":"1",
"children":"0",
"counter":"100",
}

Let’s hit the API Url and fetch the result for the above parameters

URL = "http://developer.goibibo.com/api/search/"response = requests.get(URL,params=params).json()
pp.pprint(response)
Snip of the JSON Response (output) of the above code snippet

We can loop this code and try to find the best flight price for the given locations and then simply send an email reminder using the mail service which was discussed in Daily Python #1.

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

Follow the Daily Python Challenge here:

--

--