Fast, offline reverse geocoding for India
Project description
lakhua (Python)
Offline reverse geocoding for India, optimized for fast in-memory lookups using H3 indexes.
Features
- Offline-first: No API keys, no network dependency
- In-memory lookup: Singleton loader for efficient data management
- Parent-resolution fallback: Automatic fallback from resolution 5 → 4
- Type-safe: Full type hints and dataclasses
- Modern Python: Supports Python 3.8+
- Fast: In-memory map-based lookups with minimal overhead
Installation
pip install lakhua
Quick Start
from lakhua import geocode
location = geocode(28.6139, 77.209)
if location:
print(location.city, location.state)
API Reference
Recommended top-level APIs
geocode(lat, lon, options=None) -> GeocodeResult | Nonegeocode_h3(h3_index, options=None) -> GeocodeResult | None
These helpers use the default singleton geocoder internally.
Advanced class APIs
ReverseGeocoder.get_instance()DataLoader.get_instance()
Use these only when you need explicit control in advanced runtime or testing scenarios.
GeocodeOptions
@dataclass
class GeocodeOptions:
resolution: int = 5 # H3 resolution for geocode(lat, lon)
fallback: bool = True # Enable parent resolution fallback
debug: bool = False # Print timing logs
GeocodeResult
@dataclass
class GeocodeResult:
city: str
state: str
district: str | None
pincode: str | None
matched_h3: str
matched_resolution: int
Returns None for invalid inputs or when no match is found.
Examples
Coordinate lookup
from lakhua import geocode
result = geocode(12.9716, 77.5946)
print(result)
Direct H3 lookup
from lakhua import geocode_h3
result = geocode_h3("8560145bfffffff")
print(result)
Debug mode
from lakhua import geocode, GeocodeOptions
result = geocode(19.076, 72.8777, GeocodeOptions(debug=True))
print(result)
Custom resolution
from lakhua import geocode, GeocodeOptions
result = geocode(
28.6139, 77.2090,
GeocodeOptions(resolution=4, fallback=False)
)
Performance Notes
- Data files are loaded once per process into memory
- Lookups are map-based in-memory operations
- Fallback adds up to two additional parent checks (5 → 4) when enabled
- Average lookup time: < 1ms (in-memory)
Project Layout
lakhua/
core/
__init__.py
constants.py
data_loader.py
geocoder.py
types.py
__init__.py
data/
reverse_geo_4.json
reverse_geo_5.json
Development
Setup
pip install -e ".[dev]"
Run tests
pytest
Linting and formatting
ruff check .
ruff format .
Type checking
mypy lakhua
License
MIT
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 lakhua-0.1.0.tar.gz.
File metadata
- Download URL: lakhua-0.1.0.tar.gz
- Upload date:
- Size: 241.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15f081943784efeed3a26d3f481d0673e59197857b687cb4ed8da3ff54d8fe21
|
|
| MD5 |
b66b114e1cbc047fed21138f814a47f9
|
|
| BLAKE2b-256 |
58a9b03d3c9f403dfc48ebad81fcf421d87e9a0c05b0131bc2c5b4b8eab2db28
|
Provenance
The following attestation bundles were made for lakhua-0.1.0.tar.gz:
Publisher:
pypi-publish.yml on aialok/lakhua
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lakhua-0.1.0.tar.gz -
Subject digest:
15f081943784efeed3a26d3f481d0673e59197857b687cb4ed8da3ff54d8fe21 - Sigstore transparency entry: 975848508
- Sigstore integration time:
-
Permalink:
aialok/lakhua@6729a3a7e6f8e684caf5fdbbc90457b7678a6b30 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/aialok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@6729a3a7e6f8e684caf5fdbbc90457b7678a6b30 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file lakhua-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lakhua-0.1.0-py3-none-any.whl
- Upload date:
- Size: 249.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9c753c56a59b417441f5086c9455b971fad38bb4e14d25e2b1bd21fc13371e7
|
|
| MD5 |
5c0033645841363591008fd04709f80c
|
|
| BLAKE2b-256 |
13fda604d206f00c43a6bb859c40e7c57e37e72183c1a59ca715e89f59aa9d43
|
Provenance
The following attestation bundles were made for lakhua-0.1.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on aialok/lakhua
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lakhua-0.1.0-py3-none-any.whl -
Subject digest:
f9c753c56a59b417441f5086c9455b971fad38bb4e14d25e2b1bd21fc13371e7 - Sigstore transparency entry: 975848511
- Sigstore integration time:
-
Permalink:
aialok/lakhua@6729a3a7e6f8e684caf5fdbbc90457b7678a6b30 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/aialok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@6729a3a7e6f8e684caf5fdbbc90457b7678a6b30 -
Trigger Event:
workflow_dispatch
-
Statement type: