stapel-geo
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, plus a coarse IP-geolocation verb behind its own provider registry, so a map opens on a real place before the browser's position prompt is answered.
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.4.2 |
| Python | >=3.11 (3.11, 3.12, 3.13, 3.14) |
| HTTP operations | 17 |
| Config axes | 3 |
| Usage surface | 24 |
| Extension points | 6 |
| Error codes | 51 |
| Documented flows | 5 |
| 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 facade —
nearby(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 RedisGEOSEARCHside-index backend ships for the hot set; Elasticsearch/Solr are named stubs. -
Geocoder proxy — forward / structured / reverse / resolve behind a provider merge-registry (
photonself-hosted default,nominatimkeyless dev/fallback,google/yandexkey-gated stubs), throttled, cached (30-day TTL) and spend-ledgered per call. Forward search takes the map's own narrowings: a hardbboxand a soft viewport bias. -
The location picker's server half — because a place is chosen by a human, not typed as two decimals:
- every feature carries
properties.formatted, the display line, in the country's own postal order; geocoding/resolve?lat=&lon=turns one coordinate pair into a confirmable place (label, components, geohash, alternatives) in one round trip — the whole server side of "detect my position" and of a dropped map pin;map/config(public) hands the frontend its tile template, the attribution the ODbL licence obliges the map to display, the zoom envelope, the operating bbox and the debounce discipline.
The React pair builds against
docs/frontend-contract.md. - every feature carries
-
Where to open the map before anyone is asked —
ip(public) places the visitor from the address their request arrived on, so a picker opens on a city while the browser's geolocation prompt is still unanswered, or after it was refused. Offlinemaxminddatabase or a single configuredstaticpoint, behind the same kind of provider registry as the geocoder, with the map's own default centre as the floor under both. Coarse on purpose: city-at-best, wrong on a VPN or a carrier NAT, andsource/precision/ip_resolvedcome back with the point so a UI never presents a guess as the user's address. -
comm surface —
geo.nearby/geo.radius/geo.bbox/geo.geohash_encode/geo.resolve/geo.geocode/geo.reverse_geocode/geo.map_config: consumers (listings, calendar) query geo by name, never importing it.
Quick start
pip install "stapel-geo[redis]" # + the Redis search backend
pip install "stapel-geo[ipgeo]" # + the offline MaxMind reader for `ip`
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, ?bbox= + ?bias_lat=&bias_lon= (guarded + throttled) |
geocoding/structured?city=&street= |
Structured address search |
geocoding/reverse?lat=&lon= |
Reverse geocoding (raw candidates) |
geocoding/resolve?lat=&lon= |
One coordinate pair → one confirmable place |
map/config |
Basemap + picker configuration (public) |
ip |
Where the caller appears to be, for the map's opening centre (public, throttled) |
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 |
http://localhost:2322 |
Photon instance the default provider proxies. |
PHOTON_LANGUAGES |
[default,en,de,fr] |
What the Photon index actually carries — not a preference list. Photon 400s on anything else. |
PHOTON_LANGUAGE_FALLBACK |
"default" |
Where an unindexed language clamps. default = Photon's local-name mode (Russian in Russia). |
NOMINATIM_URL |
https://nominatim.openstreetmap.org |
Nominatim base (public: 1 rps, dev/fallback). |
GEOCODER_TIMEOUT |
10 |
Geocoder HTTP timeout (s). |
GEOCODER_THROTTLE / GEOCODER_ANON_THROTTLE |
30/min / 10/min |
Scoped throttle rates (identified / anonymous). |
GEOCODER_PERMISSIONS |
[IsNotAnonymousUser] |
Guard of the proxy verbs. Set to AllowAny for a public address search. |
GEOCODE_CACHE_POLICY |
…geocoding.cache.LedgerCachePolicy |
Cache seam (dotted path). |
GEOCODE_CACHE_TTL_DAYS |
30 |
Default cache TTL. |
ADDRESS_FORMATTER |
…geocoding.format.format_address |
Builds properties.formatted (seam). |
MAP_TILE_URL / MAP_TILE_ATTRIBUTION_* |
OSM public tiles / OSM credit | Basemap and its mandatory attribution. The default tile server is a dev default (W007). |
MAP_BBOX |
None |
The product's operating area; also the default hard restriction on forward geocoding. |
MAP_* (zoom, centre, debounce) |
see CONFIG.MD |
The rest of the picker's configuration. |
IP_LOCATOR |
"maxmind" |
Default IP locator name (registry key). |
IP_LOCATORS |
{} |
Extra locators, merged over the built-ins (None removes). |
IP_MAXMIND_DB |
"" |
Path to your own offline GeoLite2/GeoIP2 City .mmdb. Nothing is bundled — MaxMind forbids redistributing it. |
IP_STATIC_POINT / IP_STATIC_LABEL / IP_STATIC_PRECISION |
None / "" / "city" |
The static locator's one answer for everybody — a single-city product's honest one. |
IP_FALLBACK_CENTER / IP_FALLBACK_LABEL |
None / "" |
Where to open when the locator has nothing. Unset, MAP_DEFAULT_CENTER answers. |
IP_TRUSTED_PROXY_DEPTH |
0 |
How many proxies you own. 0 = REMOTE_ADDR only; 1 behind one nginx. Counted from the right of X-Forwarded-For, so a forged prefix is inert (W010). |
IP_CLIENT_IP_RESOLVER |
…ipgeo.client_ip.client_ip_from_request |
The whole client-address decision as one function (seam). |
IP_PERMISSIONS |
[AllowAny] |
Guard of the ip endpoint — open by design: the caller has no account yet. |
IP_THROTTLE / IP_ANON_THROTTLE |
120/min / 60/min |
Scoped throttle rates (scope geo_ip); the anonymous one is the live one here. |
IP_CACHE_TTL_S |
3600 |
How long one address's answer is cached (0 disables). |
Sending
lang? Senddefault, or nothing.PHOTON_LANGUAGESis what the index on disk carries, and Photon refuses anything else with HTTP 400 rather than degrading. Requests for an unindexed language clamp toPHOTON_LANGUAGE_FALLBACK("default"= the local name on the map, which for a single-country product is already the right language), and the response'slangfield tells you what was really used. To index another language for real, build the Photon database from the JSON dump withphoton.jar import -languages …; listing it here without rebuilding turns every request into a 502.manage.py checksays all of this (stapel_geo.W005/W006).
Behind a proxy? Set
IP_TRUSTED_PROXY_DEPTHto the number of hops you actually own (1behind a single nginx). Leave it at0there and every visitor geolocates to your proxy; raise it past what you own and a caller picks their own IP by typing anX-Forwarded-Forheader. The chainX-Forwarded-For ++ [REMOTE_ADDR]is counted from the right, which is what keeps a forged prefix inert.manage.py checksays this too (stapel_geo.W008/W009/W010).
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
Swappable from settings, no fork: the search backend (SEARCH_BACKEND),
the geocoder registry (GEOCODERS / GEOCODER), the geocode cache
(GEOCODE_CACHE_POLICY), the display line (ADDRESS_FORMATTER), the IP
locator registry (IP_LOCATORS / IP_LOCATOR — same merge semantics as
the geocoders'), and which address a request came from
(IP_CLIENT_IP_RESOLVER, the proxy-trust decision as one function).
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.
Metadata
Release files for stapel-geo 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stapel_geo-0.4.2.tar.gz | 142.2 kB | With provenance | Details for stapel_geo-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stapel_geo-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for stapel_geo-0.4.2-py3-none-any.whl |
Total release size: 268.8 kB
Release files / stapel_geo-0.4.2.tar.gz
| Download URL | stapel_geo-0.4.2.tar.gz |
|---|---|
| Size | 142.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8cf781ac5e7902c9e042a6095674e03f65fcca4a22caf6c38ef52fd385abf7d
|
|
BLAKE2b-256 checksum How to use checksums |
51e1c8bce6431ad3bc6dfa3758408ae5f5589883c220730c339a994dd2b18764
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / stapel_geo-0.4.2-py3-none-any.whl
| Download URL | stapel_geo-0.4.2-py3-none-any.whl |
|---|---|
| Size | 126.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4b8c00285268e5ab90657d45d722d31d9b207bf5a0305cb7cecfe364399142c6
|
|
BLAKE2b-256 checksum How to use checksums |
46c618411a11ecd7c9215c42017212059a60173439c4eb1ae6b5a6ee427ede3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logSecurity for stapel-geo 0.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for stapel_geo-0.4.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.