Skip to main content

stapel-geo

CI coverage pypi downloads python license llms.txt

Geohash proximity search and geocoding, no GDAL/PostGIS/spatial database: a hierarchical location tree (flat lat/lon points with an auto-encoded geohash and a stable cross-service UUID), a proximity search facade (nearby/radius/bbox) behind one swappable backend, and a geocoder proxy (forward/structured/reverse) behind a provider merge-registry, throttled, cached and spend-ledgered per call.

Part of the Stapel framework — composable Django apps that deploy as a monolith or as microservices without changing module code.

Install

pip install stapel-geo

At a glance

Fact Value
Version 0.3.6
Python >=3.11 (3.11, 3.12, 3.13, 3.14)
HTTP operations 14
Config axes 2
Usage surface 16
Extension points 4
Error codes 48
Documented flows 4
Fleet dependencies stapel-core

Documentation

Flows: English · Errors: English · Русский · OpenAPI · capabilities.json · llms.txt (for agents)

What this is

  • Location tree — hierarchical reference places (django-treenode): flat lat/lon points with an auto-encoded, indexed geohash and a stable cross-service UUID. No polygons.
  • Proximity search facadenearby (top-K) / radius (membership) / bbox (viewport, antimeridian-aware) behind one swappable backend key. The default runs on your primary database via geohash prefix expansion (correct across the equator, the antimeridian and the poles, ranked by exact haversine); a Redis GEOSEARCH side-index backend ships for the hot set; Elasticsearch/Solr are named stubs.
  • Geocoder proxy — forward / structured / reverse geocoding behind a provider merge-registry (photon self-hosted default, nominatim keyless dev/fallback, google/yandex key-gated stubs), throttled, cached (30-day TTL) and spend-ledgered per call.
  • comm surfacegeo.nearby / geo.radius / geo.bbox / geo.geohash_encode / geo.resolve: consumers (listings, calendar) query geo by name, never importing it.

Quick start

pip install "stapel-geo[redis]"  # + the Redis search backend
INSTALLED_APPS = [
    # ...
    "stapel_geo",
]

# urls.py — the canonical versioned surface /geo/api/v1/...
path("geo/", include("stapel_geo.urls"))
# ... or mount only the geocoder proxy:
path("geo/api/v1/geocoding/", include("stapel_geo.geocoding.urls"))

Plain manage.py migrate — any Django database backend works.

HTTP surface (/geo/api/v1/)

Route What
locations/ List roots / search by name (?search=)
locations/{id-or-uuid}/ Location detail (lat/lon/geohash, tree parent)
locations/countries/ Root level of the tree
locations/by-parent/{id}/ Children of a node
locations/nearby-by-coords/?lat=&lon= Top-K nearest (exact distance_km)
locations/nearby-by-geohash/?geohash= Same, geohash input
locations/validate-uuid/{uuid}/ Cross-service reference check
geocoding/search?q= Forward geocoding (JWT + throttle)
geocoding/structured?city=&street= Structured address search
geocoding/reverse?lat=&lon= Reverse geocoding

Settings (STAPEL_GEO)

Key Default Meaning
SEARCH_BACKEND …search.postgres.PostgresGeoSearchBackend Search engine behind nearby/radius/bbox (dotted path).
REDIS_URL / REDIS_GEO_KEY redis://localhost:6379/0 / stapel:geo:locations Redis backend connection + side-index key.
GEOHASH_PRECISION 8 Stored geohash precision (1-12 chars).
NEARBY_PRECISION 6 Default precision for coordinate nearby search.
NEARBY_LIMIT / NEARBY_MAX_LIMIT 10 / 50 Default / max search results.
GEOCODER "photon" Default geocoder name (registry key).
GEOCODERS {} Extra providers, merged over the built-ins (None removes).
PHOTON_URL / PHOTON_LANGUAGES http://localhost:2322 / [default,en,de,fr] Photon provider knobs.
NOMINATIM_URL https://nominatim.openstreetmap.org Nominatim base (public: 1 rps, dev/fallback).
GEOCODER_TIMEOUT 10 Geocoder HTTP timeout (s).
GEOCODER_THROTTLE 30/min DRF scoped throttle rate for the proxy.
GEOCODE_CACHE_POLICY …geocoding.cache.LedgerCachePolicy Cache seam (dotted path).
GEOCODE_CACHE_TTL_DAYS 30 Default cache TTL.

comm Functions

from stapel_core.comm import call

call("geo.nearby", {"lat": 49.61, "lon": 6.13, "limit": 5})
call("geo.radius", {"lat": 49.61, "lon": 6.13, "radius_km": 25})
call("geo.bbox", {"min_lat": 49, "min_lon": 5, "max_lat": 50, "max_lon": 7})
call("geo.geohash_encode", {"lat": 49.61, "lon": 6.13})   # -> {"geohash": ...}
call("geo.resolve", {"uuid": "<location-uuid>"})

min_lon > max_lon in geo.bbox means the box crosses the antimeridian.

Swapping the search backend

STAPEL_GEO = {"SEARCH_BACKEND": "stapel_geo.search.redis.RedisGeoSearchBackend"}

The Redis backend is a side index: the primary DB stays the source of truth; post_save/post_delete keep it in sync and RedisGeoSearchBackend().rebuild() re-indexes from scratch. Implement stapel_geo.search.base.GeoSearchBackend (three verbs) to bring your own engine — see MODULE.md.

Extension points

See MODULE.md — the agent-facing map of every fork-free seam, and CHANGELOG.md — including what 0.3.0 removed and why.

License

MIT — see LICENSE.


This page is assembled by stapel-readme from docs/readme.md plus the contract artifacts in docs/. Edit the prose in docs/readme.md; the badges, facts and links above and below it are generated — do not hand-edit README.md.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stapel_geo-0.3.6.tar.gz (71.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stapel_geo-0.3.6-py3-none-any.whl (73.4 kB view details)

Uploaded Python 3

File details

Details for the file stapel_geo-0.3.6.tar.gz.

File metadata

  • Download URL: stapel_geo-0.3.6.tar.gz
  • Upload date:
  • Size: 71.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for stapel_geo-0.3.6.tar.gz
Algorithm Hash digest
SHA256 407379c26e12a5cadc4bfe4accdfeebcaefc70163a18fdb57d64ccdcab9172b3
MD5 cdc2b9232a4351c150786fd9e09790d6
BLAKE2b-256 1b24e25dcbd25e709339aff83cda5b00a5ebb34cf909369fa5d36299b819c1db

See more details on using hashes here.

Provenance

The following attestation bundles were made for stapel_geo-0.3.6.tar.gz:

Publisher: publish.yml on usestapel/stapel-geo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stapel_geo-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: stapel_geo-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 73.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for stapel_geo-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a74181443dcebabb0fc2bcb94e6a1e154456a9a69947a83c2331bfa683c6ab3e
MD5 016c38438b1ac4390b50766c7af4baf2
BLAKE2b-256 5c4eb3c0554b776c316541f18306e18e70ea9cf633f562c2e5a2318549724254

See more details on using hashes here.

Provenance

The following attestation bundles were made for stapel_geo-0.3.6-py3-none-any.whl:

Publisher: publish.yml on usestapel/stapel-geo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.4.1

2 files

0.4.0

2 files

This release

0.3.6 This release

2 files

0.3.5

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.1.0

2 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