Code example

Pincode API in Python

A practical Python example for retrieving Indian postal information by PIN code.

Python using requests

import requests

url = "https://api.pincodeapi.in/api/v1/pincode/751001"
response = requests.get(url, timeout=10)
response.raise_for_status()
result = response.json()
if not result.get("success"):
    raise RuntimeError("API request failed")
for office in result["data"]["post_offices"]:
    print(office["office_name"], office["pincode"])

Retry temporary failures

from requests import Session
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

retry = Retry(total=2, backoff_factor=0.4, status_forcelist=[429, 500, 502, 503, 504])
session = Session()
session.mount("https://", HTTPAdapter(max_retries=retry))
response = session.get(url, timeout=10)
response.raise_for_status()

V1 response contract

Successful responses use success, endpoint-specific data and a meta object. Postal records use snake_case fields such as office_name, office_type, delivery_status, district and state.

Handling 404 and 429 responses

The current public limit is 6 API calls per 10 seconds per IP address. A 404 means the requested record was not found and should not be retried unchanged. A 429 means the rate limit was reached; respect Retry-After when the API supplies it. Limit retries and add jitter so many clients do not retry at exactly the same moment.

See the complete API documentation, response guide and Abuse Policy.