Bulk WHOIS lookups with Python using RDAP (registrar, expiry, nameservers, no API key)

I wrote this with help from an AI assistant. I ran every script below myself on Nov 16, 2026, against live registry RDAP servers, and the output shown is copied from those runs.
If you've ever scripted WHOIS lookups, you know the pain: port 43, a different free-text format for every registry, rate limits, and a regex for each one. There's a better option that most people still don't use: RDAP (Registration Data Access Protocol). It's the official replacement for WHOIS, every gTLD registry is required to run it, and it returns clean JSON over HTTPS.
In this post we'll build one small Python script that:
- finds the right RDAP server for any TLD using IANA's bootstrap file,
- looks up a list of domains and pulls out registrar, creation date, expiry date and nameservers,
- calculates domain age and days until expiry,
- tells "not registered" apart from "no RDAP for this TLD",
- and saves everything to CSV.
pip install requests
I tested with Python 3.13 and requests 2.34. No API key needed.
Step 1: find the RDAP server for a TLD
There's no single RDAP server. Each registry runs its own, and IANA publishes a "bootstrap" file that maps TLDs to server URLs: https://data.iana.org/rdap/dns.json. Its services list holds pairs of [list_of_tlds, list_of_urls], so we flatten it into a dict:
import requests
BOOTSTRAP_URL = "https://data.iana.org/rdap/dns.json"
HEADERS = {"Accept": "application/rdap+json", "User-Agent": "rdap-demo/1.0"}
_session = requests.Session()
_session.headers.update(HEADERS)
def load_bootstrap() -> dict[str, str]:
"""Map each TLD to its registry's RDAP base URL, using IANA's bootstrap file."""
data = _session.get(BOOTSTRAP_URL, timeout=30).json()
table = {}
for tlds, urls in data["services"]:
https = [u for u in urls if u.startswith("https://")] or urls
for tld in tlds:
table[tld.lower()] = https[0].rstrip("/") + "/"
return table
When I ran it, the file covered 1,203 TLDs. Download it once per run, not once per domain.
Step 2: query a domain
The lookup URL is just {base}domain/{name}. A 404 means the registry has no record, which for a gTLD means the domain isn't registered. Registries also rate-limit, so we respect Retry-After on a 429:
import time
def fetch_rdap(domain: str, bootstrap: dict[str, str], retries: int = 3) -> dict | None:
tld = domain.rsplit(".", 1)[-1].lower()
base = bootstrap.get(tld)
if not base:
raise LookupError(f"no RDAP server for .{tld}")
url = f"{base}domain/{domain}"
for attempt in range(retries):
r = _session.get(url, timeout=20)
if r.status_code == 404:
return None # not registered (or not in this registry)
if r.status_code == 429:
time.sleep(int(r.headers.get("Retry-After", 2 ** attempt)))
continue
r.raise_for_status()
return r.json()
raise RuntimeError(f"rate limited too many times: {domain}")
Step 3: pull out the fields you actually want
The RDAP response is verbose but regular:
- dates live in
events, each with aneventAction(registration,expiration,last changed...) and an ISOeventDate, - the registrar is an entry in
entitieswith the roleregistrar, and its name sits in a jCard (vcardArray) underfn, statusis a list of EPP status strings, andnameserversis a list of objects withldhName.
from datetime import datetime, timezone
def event_date(data: dict, action: str) -> str | None:
for ev in data.get("events", []):
if ev.get("eventAction") == action:
return ev.get("eventDate")
return None
def registrar_name(data: dict) -> str | None:
for ent in data.get("entities", []):
if "registrar" in ent.get("roles", []):
for item in ent.get("vcardArray", [None, []])[1]:
if item[0] == "fn":
return item[3]
return None
def parse_date(s: str | None) -> datetime | None:
if not s:
return None
return datetime.fromisoformat(s.replace("Z", "+00:00"))
def summarize(domain: str, data: dict | None) -> dict:
if data is None:
return {"domain": domain, "registered": False}
now = datetime.now(timezone.utc)
created = parse_date(event_date(data, "registration"))
expires = parse_date(event_date(data, "expiration"))
return {
"domain": domain,
"registered": True,
"registrar": registrar_name(data),
"created": created.date().isoformat() if created else None,
"expires": expires.date().isoformat() if expires else None,
"age_years": round((now - created).days / 365.25, 1) if created else None,
"days_to_expiry": (expires - now).days if expires else None,
"status": ", ".join(data.get("status", [])),
"nameservers": ", ".join(ns.get("ldhName", "").lower()
for ns in data.get("nameservers", [])),
}
Step 4: run a batch and save CSV
import csv, sys
def main(domains: list[str], out: str = "domains.csv") -> None:
bootstrap = load_bootstrap()
print(f"bootstrap: {len(bootstrap)} TLDs with RDAP")
rows = []
for d in domains:
d = d.strip().lower().rstrip(".")
try:
row = summarize(d, fetch_rdap(d, bootstrap))
except Exception as e: # keep going on bad TLDs / server errors
row = {"domain": d, "error": str(e)}
rows.append(row)
print(row)
time.sleep(0.5) # be polite to registries
fields = list(dict.fromkeys(k for r in rows for k in r))
with open(out, "w", newline="") as f:
w = csv.DictWriter(f, fieldnames=fields)
w.writeheader()
w.writerows(rows)
print(f"saved {len(rows)} rows to {out}")
if __name__ == "__main__":
main(sys.argv[1:])
Here's real output from my run (trimmed a little):
bootstrap: 1203 TLDs with RDAP
{'domain': 'python.org', 'registered': True, 'registrar': 'Gandi SAS', 'created': '1995-03-27', 'expires': '2033-03-28', 'age_years': 31.6, 'days_to_expiry': 2323, 'status': 'client transfer prohibited', ...}
{'domain': 'github.com', 'registered': True, 'registrar': 'MarkMonitor Inc.', 'created': '2007-10-09', 'expires': '2028-10-09', 'age_years': 19.1, 'days_to_expiry': 693, ...}
{'domain': 'apify.com', 'registered': True, 'registrar': 'Amazon Registrar, Inc.', 'created': '2009-06-02', 'expires': '2035-06-02', 'age_years': 17.5, 'days_to_expiry': 3120, ...}
{'domain': 'nic.io', 'error': 'no RDAP server for .io'}
{'domain': 'this-domain-should-not-exist-8812.com', 'registered': False}
{'domain': 'google.xyzunknown', 'error': 'no RDAP server for .xyzunknown'}
saved 7 rows to domains.csv
Things I learned along the way
- Not every TLD has RDAP yet. Most country-code TLDs aren't in IANA's bootstrap file.
.iowasn't when I ran this, so the script reports it as an error instead of guessing. For those you still need classic WHOIS or the ccTLD's own service. - 404 is your "available" signal, but only for TLDs that do have an RDAP server. Keep the two cases separate, like the script does.
- Thin vs. thick registries. For
.comand.net, the Verisign record gives you dates, registrar and nameservers, but contact details (mostly redacted anyway) live on the registrar's RDAP server, linked from thelinksarray. For expiry monitoring you don't need it. - Be polite. Registries rate-limit. A short sleep between requests and honoring
Retry-Afterkept my runs clean.
A quick offline test
The parsing logic is easy to test without the network, using a tiny fake response:
from rdap_whois import summarize
SAMPLE = {
"status": ["client transfer prohibited"],
"events": [
{"eventAction": "registration", "eventDate": "2001-05-01T00:00:00Z"},
{"eventAction": "expiration", "eventDate": "2099-05-01T00:00:00Z"},
],
"entities": [{"roles": ["registrar"],
"vcardArray": ["vcard", [["version", {}, "text", "4.0"],
["fn", {}, "text", "Demo Registrar"]]]}],
"nameservers": [{"ldhName": "NS1.DEMO.NET"}],
}
row = summarize("example.org", SAMPLE)
assert row["registrar"] == "Demo Registrar"
assert row["expires"] == "2099-05-01"
assert row["nameservers"] == "ns1.demo.net"
Ideas for using it
- A weekly job that flags any of your domains with
days_to_expiry < 30. - Checking the age of domains in a lead list (very new domains are often a spam signal).
- Auditing which registrar and DNS provider each of a client's domains uses.
If you'd rather not run and schedule this yourself, I packaged the same idea as a hosted tool: Bulk WHOIS Lookup API on Apify. It takes a list of domains and returns the same fields plus DNS details. But the script above is all you need for a few hundred domains.
Questions or a TLD that behaves oddly? Leave a comment and I'll take a look.
About the author
- I build data APIs for developers: job listings from 13k company career sites, bulk WHOIS/RDAP domain checks, sitemaps, PDFs and SEC filings. Python, scraping without the pain, pay-per-result.
Comments
Join the discussionNo comments yet. Be the first to comment.



