Python API wrapper for CoWin, India's digital platform launched by the government to help citizens register themselves for the vaccination drive by booking an appointment at the nearby vaccination centres
The process to look-up for available slots to take the vaccine is tedious as you need to log in to the portal every time
This wrapper is meant to enable folks to build their own versions of a system to lookup for vaccine availablity either in a district or in a particular pin code.
Example:
from cowin_api import CoWinAPI
cowin = CoWinAPI()
states = cowin.get_states()
print(states)
pip install cowin
The wrapper currently covers four endpoints used by the CoWin portal specified below.
from cowin_api import CoWinAPI
cowin = CoWinAPI()
Returns the list of states in which vaccine drive is being conducted. This also returns the state_id
which would be
required in the subsequent requests.
from cowin_api import CoWinAPI
cowin = CoWinAPI()
states = cowin.get_states()
print(states)
Returns the list of districts in a particular states in which vaccine drive is being conducted. This also returns
the district_id
which would be required in the subsequent requests.
In this method, you would need to pass the state_id
retrieved from the previous method.
from cowin_api import CoWinAPI
state_id = '21'
cowin = CoWinAPI()
districts = cowin.get_districts(state_id)
print(districts)
A bunch of filters are available which can be passed while calling the get_availability_by_district
and get_availability_by_pincode
methods. These filters are optional and when it is not passed, default filters are
used which gives the actual data.
default_filters = {
'min_age_limit': 18,
'fee_type': ['Free', 'Paid'],
'vaccine': ['COVISHIELD', 'COVAXIN', 'Sputnik V'],
'available_capacity': 0,
'available_capacity_dose1': 0,
'available_capacity_dose2': 0
}
Out of the filters mentioned above, you can pass the needed filters to get the filtered results
Example:
To get all the centers having COVAXIN
OR COVISHIELD
, with minimum age limit as 45
and available free of cost, you
would need to set the following filters
filters = {
"min_age_limit": 45,
"vaccine": ['COVISHIELD', 'COVAXIN'],
'fee_type': ['Free']
}
Use this method to lookup for centers based on a district_id
or a list of district_ids
. This method is broader than
searching by pin code as it covers the whole district.
In this method, you would need to pass the district_id
retrieved from the previous methods. By default, the method
looks-up for slots with today's date. For any other dates pass the date in DD-MM-YYYY format.
from cowin_api import CoWinAPI
district_id = '395'
date = '03-05-2021' # Optional. Takes today's date by default
min_age_limit = 18 # Optional. By default returns centers with default filters
filters = {"min_age_limit": 18}
cowin = CoWinAPI()
available_centers = cowin.get_availability_by_district(district_id, date, filters)
print(available_centers)
Use this method to lookup for centers based on a pin_code
or a list of pin_codes
. By default, the method looks-up
for slots with today's date. For any other dates pass the date in DD-MM-YYYY format.
from cowin_api import CoWinAPI
pin_code = "400080"
date = '03-05-2021' # Optional. Default value is today's date
filters = {"min_age_limit": 18} # Optional. By default returns centers with default filters
cowin = CoWinAPI()
available_centers = cowin.get_availability_by_pincode(pin_code, date, filters)
print(available_centers)
The library internally uses requests
internally and any exceptions
thrown by requests are propagated ahead.
The API's of CoWin may at times return a 401 Unauthorized response. To mitigate this we are passing user agents in the request. Still, if the issue persists please wait for a few minutes before trying again.
Please try not to spam the CoWin servers and try to keep a timeout between subsequent requests if you are polling at a fixed interval
Contributions are always welcome!
The roadmap given above is just a line of thought. Please feel free to contribute any other method which you feel could be helpful.
MIT License