tlds
raw JSON → 2026041800 verified Fri May 01 auth: no python
Automatically updated list of valid top-level domains (TLDs) sourced directly from IANA. The package provides a simple set and list of all current TLDs. Version 2026041800 is a date-based version reflecting the IANA update date. Released approximately daily.
pip install tlds Common errors
error ModuleNotFoundError: No module named 'tlds' ↓
cause The package is not installed or misspelled (e.g., 'tld' instead of 'tlds').
fix
Run: pip install tlds
error NameError: name 'tlds_set' is not defined ↓
cause Forgot to import the set; or imported from a different module.
fix
Use: from tlds import tlds_set
error AttributeError: 'list' object has no attribute 'lower' ↓
cause Trying to call .lower() on the list instead of iterating.
fix
Check each element: any(t.lower() == 'example' for t in tlds_list)
Warnings
gotcha The TLD set is updated daily, so values can change between package versions. Do not rely on a specific version's set for security-critical checks without pinning the version. ↓
fix Pin the version in requirements.txt: tlds==2026041800
gotcha The set contains only the lowercase version of each TLD (e.g., 'com', not 'COM'). Always lowercase input before checking membership. ↓
fix Use: domain_extension.lower() in tlds_set
gotcha The set includes IDN TLDs in their punycode form (xn--...). If you expect an internationalized domain name, convert it to punycode before checking. ↓
fix Use idna package: from idna import encode; encode('münchen').decode() in tlds_set
Imports
- tlds_set
from tlds import tlds_set - tlds_list
from tlds import tlds_list
Quickstart
from tlds import tlds_set, tlds_list
print('Number of TLDs:', len(tlds_set))
print('First 5:', list(tlds_set)[:5])
print('Is .com valid?', 'com' in tlds_set)