Skip to content

Chapter 6: APIs, Web Services & AI-Ready Data

Access data programmatically — query live government databases from your code.


Why APIs?

Downloading files manually is fine for one-time analysis. But if you need the latest data automatically, or want to build an application that updates live, you need an API. This chapter shows you how.


Prerequisites

Skills Required

This is the most technical chapter in the book. You should be comfortable with: - Basic Python (how to install packages, write functions) - HTTP requests (what a URL query parameter is) - JSON format (reading key-value pairs)

If not, Chapter 7: Visualizing Data covers enough Python to get started.


What Are OGC Web Standards?

Before using geospatial web services, understand the OGC (Open Geospatial Consortium) standards — the international protocols that all major geospatial servers follow:

Standard Full Name Returns Use Case
WMS Web Map Service PNG/JPEG image tiles Background maps, visual layers
WFS Web Feature Service GeoJSON/GML vector data Queryable spatial features
WMTS Web Map Tile Service Pre-rendered tiles Fast background maps
WCS Web Coverage Service Raster grid data Elevation, rainfall grids
CSW Catalogue Service Metadata Finding available datasets

GetCapabilities URL: Every OGC service has a URL you can append ?SERVICE=WMS&REQUEST=GetCapabilities to see all available layers.


Chapter Datasets

# Dataset Provider Standard Level
1 Bhuvan OGC Services NRSC/ISRO WMS/WFS 🔵
2 GEE Python API Google Python SDK 🔴
3 AI Kosh CDAC/MeitY REST API 🟡
4 data.gov.in API MeitY REST API 🔵
5 WRIS Web Services CWC/NIH WMS/WFS 🔵

✏️ First API Exercise

Exercise 6.0 — Your First API Call

Goal: Fetch data from data.gov.in API and print it.

import requests
import json

# data.gov.in API — No key required for basic browsing
# Find datasets
url = "https://data.gov.in/api/datastore/resource.json"
params = {
    "resource_id": "6176ee09-3d56-4a3b-8115-21841576b2f6",  # Census district pop
    "limit": 5,
    "filters[State]": "Goa"
}

response = requests.get(url, params=params)

if response.status_code == 200:
    data = response.json()
    print(f"Total records: {data.get('total', 'unknown')}")
    print("\nFirst 5 records:")
    for record in data.get('records', []):
        print(json.dumps(record, indent=2))
else:
    print(f"Error: HTTP {response.status_code}")
    print("Note: Some resources require an API key — register at data.gov.in")

What you should see: Population data for Goa districts printed in JSON format.


Start with: Bhuvan OGC Services →