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-whoisVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
Install the correct package using pip: `pip install python-whois`
Access the `whois` function through the imported module object: `import whois; domain_info = whois.whois('example.com')`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)`