Registry / http-networking / ipwhois

ipwhois

JSON →
library1.3.0pypypi✓ verified 85d ago

ipwhois is a Python package designed for retrieving and parsing whois data for both IPv4 and IPv6 addresses. It is currently at version 1.3.0 and actively maintained, though its release cadence can be irregular.

pip install ipwhois
INSTALL
IMPORT
SIG · IPWHOIS
I
ipwhois
http-networkingpythonv1.3.0
Install
1.8s avg
Import
390ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.0 · 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.920 runs
installs and imports cleanly · install 0.0s · import 0.412s · 21MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.8s · import 0.368s · 22MB
19MB installed
● package 19MB
Code
Verified usage

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

IPWhois
from ipwhois import IPWhois
from ipwhois.ipwhois import IPWhois
The main class is directly importable from the top-level package.

This quickstart demonstrates how to perform a basic RDAP lookup using the IPWhois class. RDAP (Registration Data Access Protocol) is the recommended method for retrieving data. The `depth` parameter controls how many recursive lookups are performed for associated entities.

from ipwhois import IPWhois from pprint import pprint # Using a public IP for demonstration ip_address = '74.125.225.229' # Initialize IPWhois object obj = IPWhois(ip_address) # Perform RDAP lookup (recommended method) # depth=1 retrieves top-level network information # For more recursive lookups, increase depth results = obj.lookup_rdap(depth=1) pprint(results)
Debug
Known issues
breakingThe `IPWhois.lookup()` method was deprecated in older versions (around 0.15.0) and completely removed in v1.0.0. Calling it will result in an AttributeError or similar failure.
fix
Migrate to `IPWhois.lookup_whois()` for legacy WHOIS queries or, preferably, `IPWhois.lookup_rdap()` for RDAP queries, which offers a better data structure.
affects: < 1.0.0
breakingVersion 1.2.0 removed several previously deprecated functions and parameters, including `asn.IPASN._parse_fields_*`, `net.Net.lookup_asn`, `asn_alts`, and `allow_permutations`. Code relying on these will break.
fix
Refer to the v1.2.0 changelog and upgrade notes for a full list of removed components and their replacements. For ASN lookups, refer to the `IPASN` class and its current methods.
affects: >= 1.2.0
gotchaIf you are using an older version of `ipwhois` with a newer version of `dnspython`, you might encounter issues related to deprecated `dnspython` query methods. `ipwhois` v1.3.0 addressed this compatibility.
fix
Upgrade `ipwhois` to version 1.3.0 or later to ensure compatibility with recent `dnspython` versions.
affects: >= 1.2.0, < 1.3.0 with newer dnspython
gotchaFrequent or excessive queries, particularly against services like LACNIC, can lead to rate limiting based on your source IP, resulting in latency or blocked requests.
fix
Implement proper caching mechanisms for WHOIS data, introduce delays between queries, or consider using experimental bulk query support (with caution) if applicable.
affects: All versions
gotchaThe `root_ent_check` argument in `IPWhois.lookup_rdap()` (introduced in v1.2.0) defaults to `True`. While this provides more complete data, it can significantly increase the number of queries and potentially trigger rate-limiting.
fix
If experiencing performance or rate-limiting issues, set `root_ent_check=False` in `lookup_rdap()` to revert to the older functionality with fewer queries (but potentially less data).
affects: >= 1.2.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'ipwhois'
The `ipwhois` package has not been installed in the Python environment, or the environment where the code is run does not have access to the installed package.
fix
Install the package using pip: `pip install ipwhois` or `pip3 install ipwhois` if you have multiple Python versions.
AttributeError: IPWhois instance has no attribute 'lookup_rws'
The `lookup_rws()` method has been deprecated and removed in recent versions of `ipwhois`. The library now uses `lookup_rdap()` for RDAP lookups or `lookup_whois()` for legacy WHOIS lookups.
fix
Update your code to use the currently supported methods, `lookup_rdap()` or `lookup_whois()`: `results = obj.lookup_rdap()` or `results = obj.lookup_whois()`.
ipwhois.exceptions.WhoisLookupError: WHOIS lookup failed for X.X.X.X
This exception indicates that the WHOIS lookup process failed for the specified IP address, often due to network issues (e.g., timeout, connection refused), an unresponsive WHOIS server, or an invalid IP address.
fix
Implement error handling for `WhoisLookupError` to manage lookup failures gracefully. Check network connectivity, verify the IP address, and consider increasing the timeout parameter for the `IPWhois` object or the lookup method. Example: `try: obj.lookup_rdap(timeout=10) except WhoisLookupError: # handle error`.
KeyError: 'some_missing_key'
WHOIS data is highly inconsistent, and the parsed results dictionary may not always contain all expected keys or a specific nested structure, leading to a `KeyError` when attempting to access a missing key.
fix
Access dictionary keys safely using `dict.get()` with a default value, or check for key existence before access. Example: `country = results.get('asn_country_code', 'N/A')` or `if 'network' in results and 'name' in results['network']: network_name = results['network']['name']`.
Upgrade
Version history
1.3.0latest on PyPI · released Oct 15, 2024
Audit
Dependencies
dnspythonrequiredRequired for DNS-based lookups and ASN information.
defusedxmlrequiredAdded as a security requirement (for Python 3.4+).
Agent activity
6 hits · last 30 days
node
6
Resources