django-ipware
A Django application to reliably retrieve a client's real IP address from the request
Repository Health
Technical Analysis
django-ipware is a small Django utility that determines a client’s IP address from an incoming request, handling the mess of X-Forwarded-For headers, proxy chains, and other request metadata that make naive request.META['REMOTE_ADDR'] lookups unreliable behind load balancers and CDNs. Since version 6.0.0 it’s a thin Django wrapper around the framework-agnostic python-ipware package.
It exposes a single get_client_ip(request) function that returns both the detected IP and whether it’s publicly routable, plus configurable options like trusted_proxies_ips and proxy_count for teams that need to guard against IP spoofing in security-sensitive contexts such as authentication or anti-fraud logic.
What You Get
get_client_ip(request)returning both the detected IP address and ais_routableflag- Configurable
IPWARE_META_PRECEDENCE_ORDERsetting to control which request headers are checked and in what order trusted_proxies_ipsandproxy_countoptions for hardening IP detection against spoofing in proxy chains- A thin, Django-specific wrapper around the framework-agnostic
python-ipwarepackage for teams that want the same logic outside Django - Zero-configuration default behavior that works out of the box for common deployment setups
Common Use Cases
- Logging or rate-limiting requests by client IP address in a Django application
- Geolocating users or personalizing content based on client IP in views or middleware
- Feeding IP address into authentication, anti-fraud, or abuse-detection logic behind a load balancer or CDN
- Auditing and access logs that need the real client IP rather than a proxy’s address
Under The Hood
Architecture: The package is intentionally minimal — ipware/ip.py (33 lines) delegates the actual header-parsing and precedence logic to the underlying python-ipware library, while apps.py provides the Django app config so the package integrates as a standard installed app.
Tech Stack: Pure Python with a single runtime dependency on python-ipware for the core IP-resolution algorithm; no database migrations or models are required since the package only reads request metadata.
Code Quality: Tests live in ipware/tests/tests_ip.py against a dedicated testsettings.py Django settings module, exercising the various header-precedence and proxy-count scenarios; coverage reporting is wired up per the README badges.
API Design: The public surface is a single function, get_client_ip(request), returning an (ip, is_routable) tuple — about as low-friction as a Django utility can get, with advanced configuration available via settings rather than complicating the function signature.