Registry / web-framework / django-ipware

django-ipware

JSON →
library7.0.1pypypi✓ verified 25d ago

A Django application to retrieve a user's IP address. It aims to provide the best attempt to get the client's IP while handling scenarios involving proxy servers and load balancers. `django-ipware` is a wrapper using `python-ipware` under the hood since version 6.0.0. The current version is 7.0.1, released on April 19, 2024, indicating active development and a regular release cadence with updates to align with new Django and Python versions.

pip install django-ipware
INSTALL
IMPORT
SIG · DJANGO-IPWARE
D
django-ipware
web-frameworkpythonv7.0.1
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_client_ip
from ipware import get_client_ip
from ipware import get_client_ip

A simple Django view demonstrating how to retrieve the client's IP address using `get_client_ip`. It returns the IP address and a boolean indicating if it's publicly routable. Remember to pass the `request` object.

from django.http import HttpRequest, JsonResponse from ipware import get_client_ip def my_view(request: HttpRequest): client_ip, is_routable = get_client_ip(request) if client_ip is None: # Unable to get the client's IP address return JsonResponse({'error': 'Unable to determine client IP'}, status=400) else: # We got the client's IP address ip_info = { 'ip_address': str(client_ip), 'is_publicly_routable': is_routable } return JsonResponse(ip_info)
Debug
Known issues
gotchaThere is no perfect out-of-the-box solution against IP Address Spoofing. `django-ipware` makes the best attempt but should be used only as a complement to other firewall and security measures.
fix
Implement additional security measures (firewalls, WAFs) and utilize `proxy_trusted_ips` or `proxy_count` arguments if behind known proxies to improve accuracy. Always validate IP addresses for security-critical operations.
affects: All versions
breakingPrior to version 6.0.0, `django-ipware` was a standalone package. From version 6.0.0 onwards, it became a wrapper around the `python-ipware` package. While the primary `get_client_ip` import path remains stable, internal workings and advanced configurations (especially for direct `python-ipware` usage) might differ.
fix
Review `django-ipware` and `python-ipware` documentation for specific API changes if upgrading from versions older than 6.0.0, especially if customizing IP resolution logic beyond basic `get_client_ip` calls. Ensure `python-ipware` is considered a core dependency for recent versions.
affects: >= 6.0.0
gotchaIncorrect IP address resolution behind proxy servers (e.g., load balancers, CDNs). Without proper configuration, `django-ipware` might return the proxy's IP address instead of the actual client's IP.
fix
If your Django server is behind proxies, configure `get_client_ip(request, proxy_count=N)` with the correct number of proxies or `get_client_ip(request, proxy_trusted_ips=['IP_1', 'IP_2'])` with known trusted proxy IP ranges. Customize `IPWARE_META_PRECEDENCE_ORDER` in settings if non-standard HTTP headers are used.
affects: All versions
deprecatedSome integrating packages (e.g., `django-axes` versions 6+) have made `django-ipware` an optional dependency and renamed their internal settings related to IPware. This indicates a shift towards more explicit dependency management and configuration in ecosystem partners.
fix
If using `django-ipware` with `django-axes` or similar packages, ensure `django-ipware` is explicitly installed (`pip install django-ipware`) and review the integrating library's documentation for updated configuration settings (e.g., `AXES_IPWARE_PROXY_ORDER` instead of `AXES_PROXY_ORDER` in `django-axes`).
affects: From `django-axes` v6 onwards (affects users integrating with `django-axes`)
Upgrade
Version history
7.0.1latest on PyPI · released Apr 19, 2024
Audit
Dependencies
python-ipwarerequiredCore logic for IP address resolution; `django-ipware` is a wrapper around `python-ipware` since version 6.0.0.
DjangorequiredDjango web framework integration.
Agent activity
40 hits · last 30 days
node
34
OpenAI (training)
1
Resources
django-ipware — pip install django-ipware · libregistry