{"id":2733,"library":"python-ipware","title":"Python Ipware","description":"A Python package for server applications to retrieve the client's IP address. It provides a robust and accurate solution for identifying IP addresses, particularly in complex network environments involving proxies and load balancers. The current version is 3.0.0, released on April 19, 2024. The library is actively maintained with a focus on accurate IP retrieval.","status":"active","version":"3.0.0","language":"en","source_language":"en","source_url":"https://github.com/un33k/python-ipware","tags":["ip-address","networking","security","proxy","django","flask"],"install":[{"cmd":"pip install python-ipware","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The module was renamed from `ipware` to `python_ipware` in version 2.0.0 to avoid conflicts with `django-ipware`.","wrong":"from ipware import IpWare","symbol":"IpWare","correct":"from python_ipware import IpWare"}],"quickstart":{"code":"from python_ipware import IpWare\nfrom pprint import pprint\n\n# Simulate a request.META or request.environ dictionary from a web framework\n# In a real web application, this dictionary would be provided by Django (request.META)\n# or Flask (request.environ).\nsimulated_meta = {\n    'REMOTE_ADDR': '192.168.1.100', # Direct connection IP (e.g., last proxy)\n    'HTTP_X_FORWARDED_FOR': '203.0.113.45, 198.51.100.10, 192.168.1.100', # Client, Proxy1, Proxy2\n    'HTTP_CLIENT_IP': '203.0.113.45',\n    'HTTP_X_REAL_IP': '203.0.113.45',\n}\n\n# Instantiate IpWare with default configuration\nipw = IpWare()\n\n# Get the client IP and a flag indicating if the route is trusted based on configuration\nip, trusted_route = ipw.get_client_ip(simulated_meta)\n\nif ip:\n    print(f\"Client IP: {ip}\")\n    print(f\"Is routable (global IP): {ip.is_global}\")\n    print(f\"Is private IP: {ip.is_private}\")\n    print(f\"Trusted route: {trusted_route}\")\nelse:\n    print(\"Unable to determine client IP address.\")\n\nprint(\"\\n--- Custom Proxy Configuration Examples ---\")\n\n# Example with proxy_count: If your server is behind 1 known trusted proxy\n# The actual client IP is assumed to be the one before the last proxy.\nipw_with_proxy_count = IpWare(proxy_count=1)\nip_pc, trusted_route_pc = ipw_with_proxy_count.get_client_ip(simulated_meta)\n\nif ip_pc:\n    print(f\"Client IP (with proxy_count=1): {ip_pc}\")\n    print(f\"Trusted route (with proxy_count=1): {trusted_route_pc}\")\nelse:\n    print(\"Unable to determine client IP with proxy_count=1.\")\n\n# Example with proxy_list: If you have specific trusted proxy IPs\n# Let's assume '198.51.100.10' is a known trusted proxy.\nipw_with_proxy_list = IpWare(proxy_list=['198.51.100.10'])\nip_pl, trusted_route_pl = ipw_with_proxy_list.get_client_ip(simulated_meta)\n\nif ip_pl:\n    print(f\"Client IP (with proxy_list=['198.51.100.10']): {ip_pl}\")\n    print(f\"Trusted route (with proxy_list=['198.51.100.10']): {trusted_route_pl}\")\nelse:\n    print(\"Unable to determine client IP with proxy_list.\")","lang":"python","description":"This quickstart demonstrates how to instantiate `IpWare` and retrieve the client's IP address from a simulated HTTP request metadata dictionary. It also includes examples of configuring `IpWare` for environments behind trusted proxies using `proxy_count` and `proxy_list` parameters to ensure accurate IP resolution."},"warnings":[{"fix":"Update your import statements to `from python_ipware import IpWare`.","message":"The import path for `IpWare` changed in version 2.0.0 from `from ipware import IpWare` to `from python_ipware import IpWare`.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Implement comprehensive security measures beyond IP address retrieval, such as robust firewall rules and other authentication/authorization mechanisms.","message":"Ipware is a complementary security measure and should not be relied upon as a primary defense against IP address spoofing. Always pair it with robust firewall security protocols.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the official changelog for specific API changes when upgrading to 3.0.0 or higher and test your application thoroughly.","message":"Version 3.0.0 indicates a 'possibility of api change causing minimal backward incompatibly'. While specific changes are not detailed, minor adjustments to code might be required upon upgrade.","severity":"breaking","affected_versions":"3.0.0"},{"fix":"Carefully configure `proxy_count` to match the number of trusted proxies in front of your server, or provide an accurate `proxy_list` of trusted IP addresses or patterns. Refer to the 'Advanced Users' section in the documentation for guidance.","message":"Incorrect configuration of `proxy_count` or `proxy_list` parameters can lead to the retrieval of an internal proxy IP rather than the actual client's IP address, especially when deployed behind load balancers or multiple proxies.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}