WHOIS lookups in Python: three ways compared
In Python you can use the python-whois package (pip install python-whois), which parses classic WHOIS text, or call RDAP with requests and get clean JSON from the registry. RDAP is the steadier choice now that generic domains have moved to it. If you want parsed dates plus DNS, mail and HTTPS checks from one request, our Domain Report API costs $0.01 per domain.
Try it free Domain Report API — WHOIS, DNS, email set-up and HTTPS · $0.01 / call
Option 1: the python-whois package
It's quick to start, but it parses free-form text from port 43 servers. Dates can come back as a list when the record repeats them, some endings return nothing useful, and as registries turn WHOIS off you'll see more empty results. Normalise with: d = d[0] if isinstance(d, list) else d.
import whois # pip install python-whois
w = whois.whois("example.com")
print(w.registrar)
print(w.creation_date) # a datetime, or a list of them
print(w.expiration_date)
Option 2: RDAP with requests
Same facts, but JSON with fixed names. Here the server comes from IANA's bootstrap file instead of a redirector, which is kinder to free services when you run many lookups.
import requests
BOOT = requests.get("https://data.iana.org/rdap/dns.json", timeout=10).json()
def rdap(domain):
tld = domain.rsplit(".", 1)[-1]
for tlds, urls in BOOT["services"]:
if tld in tlds:
base = next((u for u in urls if u.startswith("https")), urls[0])
r = requests.get(base.rstrip("/") + "/domain/" + domain, timeout=15)
return r.json() if r.ok else None
return None # this ending has no RDAP server
d = rdap("example.com")
events = {e["eventAction"]: e["eventDate"] for e in d.get("events", [])}
print(events.get("registration"), events.get("expiration"))
Option 3: one report call
requests can't pay the 402 by itself. Any x402 v2 client, or Coinbase AgentKit with the iamai-agentkit plugin, pays in USDC on Base and repeats the call. No wallet? Try 5 domains a day free on the listing page.
import requests
r = requests.post(
"https://iamai.markets/api/x402/services/2EI0aA1Eztau",
json={"domain": "example.com"},
)
print(r.status_code) # 402: $0.01 to pay
# After your x402 client pays and repeats the request:
# res = r.json()["result"]
# res["registration"]["age_days"], res["registration"]["days_to_expiry"]
# res["dns"]["mx"], res["email"]["dmarc"], res["https"]["works"]
Which one to pick
| Way | Cost | Best for | Watch out for |
|---|---|---|---|
| python-whois | Free | Quick scripts on common endings | Text parsing, lists of dates, WHOIS shutting down |
| RDAP with requests | Free | Reliable dates and status in your own code | Rate limits, ccTLDs without RDAP |
| whoisit (RDAP client library) | Free | RDAP without writing the bootstrap code | Another dependency to keep current |
| Domain Report API | $0.01 per domain | Dates plus DNS, SPF, DMARC and HTTPS in one call | One domain per call, x402 wallet to pay |
Errors you'll meet
- HTTP 429 from a registry: you're going too fast. Sleep a couple of seconds between lookups.
- HTTP 404 from RDAP: usually not registered. Confirm with a DNS lookup before you treat it as available.
- Socket timeouts with python-whois: some port 43 servers are slow or block cloud IPs.
- Owner fields full of "REDACTED": normal privacy redaction, not a parsing bug.
The product
Questions
Which pip package is the right "whois"?
python-whois is installed with pip install python-whois and imported as whois. There is also a different package called whois, so check which one is installed if the examples fail.
Can Python get the domain owner's email?
Rarely. Owner contacts are redacted for most domains, whatever library you use.
How do I check thousands of domains?
With RDAP, group them by ending, cache the bootstrap file and pace requests to each registry. The Domain Report API is one domain per call at $0.01 each.
Related
Updated 2026-12-01
