tld
Extract the top-level domain (TLD) from the URL given.
What it is and what it does
tld is a lightweight URL parser that extracts domain components—top-level domain, first-level domain, subdomain, and full domain—from URLs using the Mozilla Public Suffix list. It handles edge cases like multi-part TLDs (e.g., 'co.uk') and can optionally repair malformed URLs by adding missing protocols. The package offers both string and object-based return modes, validation of TLD names, and extensibility through custom TLD source parsers and lists.
The library maintains a cached copy of the Public Suffix list and provides a command-line tool to refresh it. It has no external runtime dependencies, making it simple to integrate into URL-parsing pipelines, domain validation workflows, and security tools that need reliable domain decomposition.
Use it for:
- Validate and extract domain components from user-submitted URLs in web applications.
- Parse and categorize domains in log analysis or security monitoring tools.
- Build domain-based access control or cookie-scoping logic in web frameworks.
- Identify first-level domains for analytics or tracking across subdomains.
- Validate TLD names against the Public Suffix list in data pipelines.
- Implement custom domain parsing rules by subclassing the base parser for specialized use cases.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Extracts the top-level domain (TLD) and first-level domain (FLD) from URLs using the Public Suffix list, with optional error handling and support for custom TLD sources.
Yes. tld is a stable, actively maintained utility with zero dependencies, broad Python version support, and no known vulnerabilities. Its copyleft license requires review if you distribute proprietary code, but the license terms are well-established. Install it for any project needing reliable URL-to-domain decomposition.
Install
tld on PyPI
pip
pip install tlduv
uv add tldpoetry
poetry add tldInstalling tld
Before you install
Low friction: pure Python wheel with no runtime dependencies. Active maintenance with recent commits and stable production status across modern Python versions (3.9–3.15).
License in practice
Copyleft license (MPL-1.1 OR GPL-2.0-only OR LGPL-2.1-or-later) requires derivative works to be distributed under compatible terms; review your project's license compatibility before use.
Quickstart
pip install tld
from tld import get_tld
get_tld("http://www.google.co.uk")
# 'co.uk'
get_tld("http://www.google.idontexist", fail_silently=True)
# None
Requires Python 3.7 or greater; TLD names list should be updated via `update-tld-names` if domain recognition fails.
Verify before relying
- Frequency and process for updating the Public Suffix list bundled with releases.
- Performance characteristics when parsing large batches of URLs.
- Whether custom parser implementations are commonly used in production.
Package facts
| License | MPL-1.1 OR GPL-2.0-only OR LGPL-2.1-or-later (copyleft) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 161 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 15,866,317/month — #1,171 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: tld-0.13.2-py2.py3-none-any.whl
Keywords: tld, top-level domain names, python
Tags
More Internet packages
Botocore provides low-level, data-driven access…
permissive · top 100 on PyPI
aiobotocoreProvides an async client for AWS services using…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
filelockProvides a platform-independent file locking…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
googleapis-common-protosProvides common Protocol Buffer message…
permissive · top 100 on PyPI
tldextractAccurately extracts subdomain, domain, and…
permissive · top 1,000 on PyPI
tldsProvides a set of valid top-level domains…
permissive · top 15,000 on PyPI
publicsuffix2Extracts the public suffix and registrable…
copyleft · top 5,000 on PyPI
urlextractExtracts URLs from text by locating TLDs and…
permissive · top 5,000 on PyPI
pyfaup-rsParses URLs into components (scheme, host,…
copyleft · top 15,000 on PyPI
tldparseParses domain names into their constituent…
permissive · top 15,000 on PyPI
publicsuffixlistParses the Public Suffix List to extract the…
copyleft · top 5,000 on PyPI
python-whoisQueries WHOIS servers directly to retrieve and…
permissive · top 5,000 on PyPI
dnstwistGenerates domain name permutations to detect…
permissive · top 15,000 on PyPI
whoisRetrieves WHOIS information for domain names by…
permissive · top 15,000 on PyPI