django-ipware

A Django application to reliably retrieve a client's real IP address from the request

Library
PyPI
v7.0.1
1,066stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
37/100Needs Attention
Development Activity0
Maintenance0
Community60
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
66/100Good
Architecture55
Code Quality68
Innovation50
Learning Curve90

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 a is_routable flag
  • Configurable IPWARE_META_PRECEDENCE_ORDER setting to control which request headers are checked and in what order
  • trusted_proxies_ips and proxy_count options for hardening IP detection against spoofing in proxy chains
  • A thin, Django-specific wrapper around the framework-agnostic python-ipware package 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search