Official Python implementation of DIGIPIN - India's national geocoding standard by Department of Posts
Project description
🇮🇳 DIGIPIN-Py
Official Python implementation of India's national geocoding standard
Documentation • API Reference • Getting Started • Contributing • Changelog
What is DIGIPIN?
DIGIPIN (Digital Postal Index Number) is India's national geocoding system developed by the Department of Posts, Ministry of Communications, Government of India. It divides the entire country into a hierarchical grid, assigning a unique code to every ~4m × 4m location.
digipinpy is a high-performance, zero-dependency Python library implementing the official specification with 100% compliance.
Key Features
- 🎯 Pinpoint Accuracy - ~3.8m precision at level 10
- 🗺️ Hierarchical Grid - Variable precision from 1000km down to 4m
- 📦 Zero Dependencies - Pure Python core, optional framework integrations
- ⚡ High Performance - ~50,000 encodes/second, optimized quadtree polyfill (10x faster for corridors)
- 🔌 Framework Ready - Native Pandas, Django, FastAPI & geospatial support
- 📊 CSV Batch Processing - CLI tool for processing thousands of addresses
- 🗺️ Interactive Visualization - Beautiful maps with Folium integration
Installation
pip install digipinpy
Optional integrations:
pip install digipinpy[pandas] # Data science & CSV processing
pip install digipinpy[django] # Django database field
pip install digipinpy[fastapi] # FastAPI microservices
pip install digipinpy[geo] # Geospatial polyfill
pip install digipinpy[viz] # Interactive map visualization
Quick Start
Basic Usage
from digipin import encode, decode
# Encode coordinates to DIGIPIN
code = encode(28.622788, 77.213033) # Dak Bhawan, New Delhi
print(code) # '39J49LL8T4'
# Decode back to coordinates
lat, lon = decode('39J49LL8T4')
print(f"{lat:.6f}, {lon:.6f}") # 28.622788, 77.213033
Variable Precision
# Encode with different precision levels
code_full = encode(28.622788, 77.213033, precision=10) # ~3.8m
code_city = encode(28.622788, 77.213033, precision=5) # ~1km
code_region = encode(28.622788, 77.213033, precision=3) # ~16km
Proximity Search
from digipin import get_neighbors, get_disk
# Get 8 immediate neighbors
neighbors = get_neighbors('39J49LL8T4')
# Get all cells within radius 3
search_area = get_disk('39J49LL8T4', radius=3)
Polygon Coverage (NEW in v1.6.1)
from digipin import polyfill
# Convert polygon to DIGIPIN codes
polygon = [(28.63, 77.22), (28.62, 77.21), (28.62, 77.23)]
codes = polyfill(polygon, precision=8)
# Choose algorithm (quadtree is default)
codes = polyfill(polygon, precision=8, algorithm="quadtree") # Fast for sparse/large areas
codes = polyfill(polygon, precision=8, algorithm="grid") # Fast for small dense zones
⚡ Performance
v1.6.1 introduces optimized quadtree algorithm achieving O(Perimeter) complexity instead of O(Area):
| Use Case | Grid Scan | Quadtree | Speedup |
|---|---|---|---|
| Sparse corridor (highway) | 2.32s | 0.21s | 10.86x faster ⚡ |
| Small delivery zones (< 10 km²) | 0.002s | 0.006s | 0.3x |
| Large areas (> 100 km²) | 0.86s | 1.00s | 0.95x |
Key Findings:
- ✅ Quadtree excels at sparse polygons (highways, rivers, corridors) - up to 10x faster
- ✅ Grid scan wins for small dense areas (typical delivery zones)
- ✅ Both complete in < 50ms for 80% of use cases
- ✅ Algorithm selection is automatic (configurable via
algorithmparameter)
Documentation
📚 User Guides
- Getting Started - Installation and first steps
- API Reference - Complete function reference
- Use Cases - Real-world examples
🔌 Integrations
- Pandas Integration - DataFrame operations
- Django Integration - Database field with validation
- FastAPI Integration - REST API microservices
- Geospatial Polyfill - Polygon-to-codes conversion
🛠️ Development
- Contributing Guide - How to contribute
- Changelog - Version history
- Technical Specification - Official DIGIPIN spec
Features at a Glance
| Feature | Description |
|---|---|
| Encoding/Decoding | Coordinates ↔ DIGIPIN codes |
| Validation | Check code validity with is_valid() |
| Batch Operations | Process arrays efficiently |
| Proximity Search | Find neighbors, rings, disks |
| Hierarchical Ops | Parent/child relationships |
| CSV Batch Processing | digipin convert CLI for CSV/Excel files |
| Interactive Visualization | plot_pins(), plot_coverage() with Folium |
| Pandas Integration | .digipin accessor for DataFrames |
| Django Integration | DigipinField() with auto-validation |
| FastAPI Integration | Pre-built REST API router |
| Geospatial Polyfill | Convert polygons to code sets |
Project Status
- ✅ Production Ready - Version 1.6.1
- ✅ 100% Spec Compliant - Official DoP specification
- ✅ 178 Tests Passing - Comprehensive test coverage
- ✅ Type Hints - Full type annotation support
- ✅ Multi-Platform - Windows, macOS, Linux
- ✅ Python 3.7-3.14 - Wide version support
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Quick setup:
git clone https://github.com/DEADSERPENT/digipin.git
cd digipin
pip install -e ".[dev]"
pytest tests/ -v
License
MIT License - see LICENSE file for details.
Community & Support
Maintained by: SAMARTHA H V • MR SHIVAKUMAR 📧 samarthsmg14@gmail.com • hmrshivu@gmail.com
📦 PyPI • 🐛 Issues • 💬 Discussions • 📖 Changelog
This implementation is based on the official DIGIPIN specification published by the Department of Posts, Ministry of Communications, Government of India (March 2025).
Government of India | Department of Posts | National Addressing Initiative
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file digipinpy-1.7.0.tar.gz.
File metadata
- Download URL: digipinpy-1.7.0.tar.gz
- Upload date:
- Size: 60.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
680dab57e819e9850b80a394aef1d5aed4afd227b14f84f841a5064990adfbba
|
|
| MD5 |
547fcbd3ca82047dc8c86e22eb6beded
|
|
| BLAKE2b-256 |
cd62e088f6d30bdfa45ef11e0b3016a6cadc7c50f6a3e795b4602a308149e0bb
|
File details
Details for the file digipinpy-1.7.0-py3-none-any.whl.
File metadata
- Download URL: digipinpy-1.7.0-py3-none-any.whl
- Upload date:
- Size: 40.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfbc5409db1aa41ac056d7ce3f5277017448f900e8331afd8dc97acd7abdb97a
|
|
| MD5 |
e1ffe8825c2d7f639a44e1b19257bf46
|
|
| BLAKE2b-256 |
96968c55d8500526c08dc8755c1c5c813dd756f19e0001ae4be20664c2f33237
|