Python WHOIS Client
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.
Warnings
- gotcha WHOIS 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.
- gotcha Direct 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.
- gotcha Due 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.
Install
-
pip install python-whois
Imports
- whois
import whois
Quickstart
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)