--- id: tld version: "0.13.2" license: MPL-1.1 OR GPL-2.0-only OR LGPL-2.1-or-later license_treatment: copyleft maintenance: active --- # tld — Extract the top-level domain (TLD) from the URL given. License: copyleft · Maintenance: active · Downloads: 15.9M/mo ## 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 above — 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 pip install tld uv add tld poetry add tld ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 15.9M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags extract tld from url, top level domain parser, public suffix list, domain name extraction, parse url domain parts, fld first level domain, validate tld names, url-parsing, domain-extraction, public-suffix [View on SkillFed](https://skillfed.io/packages/tld) · [View on PyPI](https://pypi.org/project/tld/)