Registry / http-networking / python-whois

python-whois

JSON →
library0.9.6pypypi✓ verified 26d ago

python-whois is a Python library for querying WHOIS servers directly and parsing domain registration information. It aims to provide structured data for various Top-Level Domains (TLDs) and is currently at version 0.9.6, with recent activity in October 2025. The library focuses on direct server queries rather than relying on intermediate web services.

pip install python-whois
INSTALL
IMPORT
SIG · PYTHON-WHOIS
P
python-whois
http-networkingpythonv0.9.6
Install
1.7s avg
Import
105ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.6 · 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.110s · 19.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.100s · 20MB
17MB installed
● package 17MB
Code
Verified usage

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

whois
import whois
from whois import whois_query_function
The primary function is accessed directly via 'whois.whois(domain)'. Do not confuse with other 'whois' libraries or attempt to import sub-modules directly without explicit documentation.

The quickstart demonstrates how to import the `whois` module and use the `whois.whois()` function to retrieve and parse domain registration data. Key attributes like domain name, registrar, dates, and name servers are easily accessible. The raw WHOIS text is also available.

import whois # Query WHOIS for a domain domain = "example.com" w = whois.whois(domain) # Access parsed attributes print(f"Domain Name: {w.domain_name}") print(f"Registrar: {w.registrar}") print(f"Creation Date: {w.creation_date}") print(f"Expiration Date: {w.expiration_date}") print(f"Name Servers: {w.name_servers}") # Print all found attributes (as a dictionary) # print(w.text) # Uncomment to see the raw WHOIS text # print(w)
Debug
Known issues
gotchaWHOIS data is semi-structured and can vary significantly between TLDs and registrars. Parsing may not always be 100% accurate or complete, and some fields might be missing or in unexpected formats.
fix
Always validate the returned data and implement error handling for missing attributes. Consider falling back to raw text parsing for critical, unparsed fields if needed.
affects: All versions
gotchaDirect WHOIS queries can be subject to rate limiting, firewalls, or network issues, leading to timeouts. Some WHOIS servers might be temporarily unavailable or return incomplete responses.
fix
Implement robust error handling, retry mechanisms with exponential backoff, and consider using a SOCKS proxy (with PySocks installed and configured via the SOCKS environment variable) for improved reliability or to circumvent IP-based restrictions.
affects: All versions
gotchaDue to multiple Python libraries existing with 'whois' in their name (e.g., `pythonwhois`, `whoisdomain`, `ipwhois`), it's common to encounter `AttributeError: module 'whois' has no attribute 'whois'` if the wrong package is installed or a local file conflicts. Ensure you have installed `python-whois` (from richardpenman) and that no local `whois.py` file shadows the library.
fix
Verify installation with `pip show python-whois`. If you have a local `whois.py` file, rename it. If using an alternative `whois` library, ensure you are importing it correctly as per its documentation.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'whois'
The `python-whois` library is not installed in the current environment or the PyPI package name (`python-whois`) differs from the import name (`whois`).
fix
Install the correct package using pip: `pip install python-whois`
TypeError: 'module' object is not callable
The user is attempting to call the `whois` module directly as a function, rather than calling the specific `whois` function located within the module.
fix
Access the `whois` function through the imported module object: `import whois; domain_info = whois.whois('example.com')`
AttributeError: 'NoneType' object has no attribute 'domain_name'
The `whois.whois()` function returned `None` because it failed to retrieve WHOIS data for the queried domain (e.g., domain doesn't exist, WHOIS server timed out, or parsing failed), and subsequently an attribute was accessed on this `None` object.
fix
Always check if the result of `whois.whois()` is not `None` before attempting to access its attributes: `domain = whois.whois('example.com'); if domain: print(domain.domain_name)`
Upgrade
Version history
0.9.6latest on PyPI · released Oct 7, 2025
Audit
Dependencies
python-dateutiloptionalImproved parsing of various date formats in WHOIS records into datetime objects.
PySocksoptionalRequired for SOCKS proxy support.
Agent activity
24 hits · last 30 days
node
18
Resources
python-whois — pip install python-whois · libregistry