Skip to main content

🇮🇳 DIGIPIN-Py

Official Python implementation of India's national geocoding standard

PyPI version Python Version License Tests codecov DOI Downloads

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 algorithm parameter)

Documentation

📚 User Guides

🔌 Integrations

🛠️ Development


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

Metadata

Release files for digipinpy 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for digipinpy 1.7.0
File Size Uploaded
digipinpy-1.7.0.tar.gz 60.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for digipinpy 1.7.0
File Interpreter ABI Platform
digipinpy-1.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 100.5 kB

Release files / digipinpy-1.7.0.tar.gz

Download URL digipinpy-1.7.0.tar.gz
Size 60.0 kB
Tags Source
SHA-256 checksum
How to use checksums
680dab57e819e9850b80a394aef1d5aed4afd227b14f84f841a5064990adfbba
BLAKE2b-256 checksum
How to use checksums
cd62e088f6d30bdfa45ef11e0b3016a6cadc7c50f6a3e795b4602a308149e0bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / digipinpy-1.7.0-py3-none-any.whl

Download URL digipinpy-1.7.0-py3-none-any.whl
Size 40.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfbc5409db1aa41ac056d7ce3f5277017448f900e8331afd8dc97acd7abdb97a
BLAKE2b-256 checksum
How to use checksums
96968c55d8500526c08dc8755c1c5c813dd756f19e0001ae4be20664c2f33237
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

1.7.0 This release

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page