Introducing the datagovindia package: Use Government of India’s Open Government Data OGD platform APIs with Python & R
March 30, 2022
Author:
Aditya_Chhabra
The package provides the following features right from your Python/R environment
DISCOVERY
Find the API resource you need.
INFORMATION
Retrieve information about API resources.
DATA
Download data in a convenient dataframe from any API on data.gov.in.
What you need to get started
Installation
Install the package in your Python environment with one simple command
pip install -U datagovindia
Get started in just 5 steps:
Step 1 Import the library
from datagovindia import DataGovIndia
Step 2 Initialize with your API-Key
YOUR_API_KEY = “579b464db66ec23bd********************7209ff7b23ac571b”
datagovin = DataGovIndia(YOUR_API_KEY)
Output
Step (1/2) API key is VALID
You don’t need to enter it again
Step (2/2) Latest API meta-data loaded! You may begin.
Step 3 Search for the data you want
datagovin.search_by_title(“PIN CODE”)
Output
5 of 5 results for : `PIN CODE`
==================================================================================
Resource-ID: 5c2f62fe5afa4119a499fec9d604d5bd
All India Pincode Directory till last month
==================================================================================
Resource-ID: 7eca2fa3d6f5444eb3d6faa441e35294
Locality based Pincode as on 15th February 2016
==================================================================================
Resource-ID: 04cbe4b12f2b4c39a1d51c2e28bc0e32
All India Pincode directory with contact details along with Latitude and longitude
==================================================================================
Resource-ID: 0a0764783fd34e2cb2d2581876f56d77
All India Pincode Directory along with Contact Details
==================================================================================
Resource-ID: 6176ee093d564a3b811521841576b2f6
All India Pincode Directory
==================================================================================
Step 4 Get all the details
datagovin.get_resource_info(“5c2f62fe5afa4119a499fec9d604d5bd”)
{
“ResourceID”: “5c2f62fe5afa4119a499fec9d604d5bd”,
“Title”: “All India Pincode Directory till last month”,
“Description”: “All India Pincode Directory till last month”,
“TotalRecords”: 157126,
“DateCreated”: “13 July 2021, 04:41 PM”,
“DateUdpated”: “13 July 2021, 04:41 PM”,
“OrganizationNames”: [“Department of Posts”, “Ministry of Communications”],
“OrganizationTypes”: “Central”,
“Sector”: “Post”,
“Source”: “data.gov.in”,
“Fields”: [
“document_id”,
“circlename”,
“regionname”,
“divisionname”,
“officename”,
“pincode”,
“officetype”,
“delivery”,
“district”,
“statename”,
“latitude”,
“longitude”,
“resource_uuid”
]
}
Step 5 Download the dataset
data = datagovin.get_data(“5c2f62fe5afa4119a499fec9d604d5bd”)
print(f”Number of records in table: {len(data)}”)
Number of records in table: 157114
The package is also available in R, to install, use the following command:
install.packages(“datagovindia“)
For more examples, detailed documentation, or to create issues, visit:
We’re maintaining the packages actively, and we look forward to your questions and suggestions! Reach out to us at –
Email aditya0chhabra [at] gmail [dot] com
Email abhishek [dot] arora1996 [at] gmail [dot] com