skillfed

tld

Extract the top-level domain (TLD) from the URL given.

tld v0.13.2 15.9M downloads/30d#1,171 on PyPI186
Copyleft license MPL-1.1 OR GPL-2.0-only OR LGPL-2.1-or-later Active released

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 tld

uv

uv add tld

poetry

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 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

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Programming Language :: Python :: 3.9Topic :: Internet

Tags

extract tld from urltop level domain parserpublic suffix listdomain name extractionparse url domain partsfld first level domainvalidate tld names
url-parsingdomain-extractionpublic-suffix

More Internet packages