Geofencing middleware and NextUne IP/whoami helpers for Django.
Project description
nextune-geofencing
Django app paired with the Express package @nextuneapps/geofencing: optional middleware that attaches location-related attributes to each request, optional URL routes, and TypedDict shapes for the payload structures your project works with.
Install
pip install nextune-geofencing
Requires Django 4.1+ and Python 3.10+.
Types (IDE and static checkers)
Import TypedDict definitions from the package so views, services, and tests stay aligned with the JSON you handle:
from typing import cast
from nextune_geofencing import (
ExchangeRatesBlock,
ExchangeRatesResponse,
NextuneGeo,
NextuneGeofencing,
NextuneLocationPayload,
)
def summarize_location(body: object) -> dict:
data = cast(NextuneLocationPayload, body)
geo = cast(NextuneGeo | None, data.get("geo"))
raw_gf = data.get("geofencing")
gf = cast(NextuneGeofencing | None, raw_gf if isinstance(raw_gf, dict) else None)
return {
"currency": (gf or {}).get("currency") or (geo or {}).get("currency"),
"country": (gf or {}).get("country_code") or (geo or {}).get("country"),
"payment_methods": data.get("payment_methods"),
}
def rates_table(body: object, base_code: str) -> dict[str, float | int] | None:
payload = cast(ExchangeRatesResponse, body)
block = cast(ExchangeRatesBlock | None, payload.get(base_code.upper()))
return block["rates"] if block else None
After middleware — use the helpers for typed reads of request:
from django.http import HttpRequest, JsonResponse
from nextune_geofencing import get_nextune_geofencing, get_nextune_country_code
def checkout(request: HttpRequest):
gf = get_nextune_geofencing(request)
return JsonResponse(
{
"country": get_nextune_country_code(request),
"currency": gf.get("currency") if gf else None,
}
)
Error bodies from this app’s views can be annotated as GeofencingAPIError when you parse JSON.
Django setup
INSTALLED_APPS = [
# ...
"nextune_geofencing",
]
MIDDLEWARE = [
# ...
"nextune_geofencing.middleware.GeofencingMiddleware",
]
Routes (optional)
from django.urls import include, path
urlpatterns = [
# ...
path("v1/geo/", include("nextune_geofencing.urls")),
]
Under the mount prefix (example above: v1/geo/):
GET …/whoami— resolves the requesting client’s IP, then returns location JSON (NextuneLocationPayload:geo,geofencing,payment_methods, etc.). Commonly used for “current visitor” context (country, currency, payments).POST …/ip— JSON body{"ip": "<address>"}→ the same location JSON shape (NextuneLocationPayload).GET …/exchange-rates/<currency>— three-letter ISO code (e.g.KES) → exchange-rate JSON (ExchangeRatesResponse).
Project details
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 nextune_geofencing-0.1.7.tar.gz.
File metadata
- Download URL: nextune_geofencing-0.1.7.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
387b15ee023ed6f8037924ef9785dade1b3a156c1573730f42aa49b59ee59367
|
|
| MD5 |
da9e9dc8bf3626cd4df4f9e913002da2
|
|
| BLAKE2b-256 |
bf15b144ef45dbf0a725eb3c7e788849b35cbb6c973e533b6e41a602a65e24b0
|
File details
Details for the file nextune_geofencing-0.1.7-py3-none-any.whl.
File metadata
- Download URL: nextune_geofencing-0.1.7-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58d946e64d395aa212aae5f497cd61ae2d4d24b0f3c62450978e0dc3433c7e4e
|
|
| MD5 |
164ad0cffa77dc310608584b58dcfddc
|
|
| BLAKE2b-256 |
d19815f4e66f69d496ba04f1e27d4d19e51e35a3f0a90aa71c6d4bf0dc2386f2
|