Registry / serialization / tld
library0.13.2pypypi✓ verified 26d ago

The `tld` library provides functions to reliably extract the top-level domain (TLD) from a given URL, along with subdomains and full domain names. It leverages the Public Suffix List to ensure accuracy. The current version is 0.13.2, and it typically sees several updates per year, though major versions may have longer gaps.

pip install tld
INSTALL
IMPORT
SIG · TLD
T
tld
serializationpythonv0.13.2
Install
1.7s avg
Import
126ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.13.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.136s · 18.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.116s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_tld
from tld import get_tld
update_tld_names
from tld.utils import update_tld_names
from tld import update_tld_list
The function name and import path changed in newer versions (post 0.11.x). `update_tld_list` is deprecated/removed.

This example demonstrates extracting the TLD from a URL, both as a string and as an object for more detailed information. It also highlights the optional `update_tld_names` call and how to handle invalid URLs using `fail_silently`.

from tld import get_tld from tld.utils import update_tld_names # It's good practice to update the TLD names regularly # This fetches the latest Public Suffix List # For production, consider running this in a scheduled job, not on every startup. # update_tld_names() url1 = "http://www.google.co.uk" tld1 = get_tld(url1) print(f"TLD for '{url1}': {tld1}") url2 = "https://sub.domain.example.com/path?query=1" obj2 = get_tld(url2, as_object=True) print(f"TLD for '{url2}': {obj2.tld}") print(f"Subdomain: {obj2.subdomain}") print(f"Domain: {obj2.domain}") print(f"Full domain: {obj2.fld}") try: invalid_url = "ftp://invalid-url" get_tld(invalid_url, fail_silently=False) except Exception as e: print(f"Error extracting TLD for '{invalid_url}': {e}")
tld --version
Debug
Known issues
gotchaThe `tld` list needs to be updated periodically to remain accurate. New TLDs are introduced regularly. Failing to update can lead to incorrect TLD extraction for newer domains.
fix
Call `from tld.utils import update_tld_names; update_tld_names()` in your deployment pipeline or on a scheduled basis. For performance, avoid calling it on every application startup.
affects: All versions
breakingThe default value for the `search_private` parameter in `get_tld` changed from `True` to `False`.
fix
If you rely on extracting TLDs from private domains (e.g., local network hostnames or intranet sites), explicitly set `search_private=True` in your `get_tld` calls: `get_tld(url, search_private=True)`.
affects: 0.12.0 and later
deprecatedThe function `tld.update_tld_list` was replaced by `tld.utils.update_tld_names`.
fix
Update your import and function call to `from tld.utils import update_tld_names; update_tld_names()`.
affects: Prior to 0.12.0
breakingPython 3.6 support was dropped.
fix
Upgrade your Python environment to Python 3.7 or newer.
affects: 0.13.0 and later
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'tld'
The `tld` package has not been installed in your Python environment.
fix
Run `pip install tld` in your terminal to install the library.
tld.exceptions.TldBadUrl: Invalid URL
The input string provided to `get_tld` does not conform to a valid URL format that the library can parse, often due to missing scheme or being malformed.
fix
Ensure the input string is a well-formed URL, for example, by prepending 'http://' or 'https://' if it's just a domain name.
tld.exceptions.TldDomainNotFound: TLD could not be found for URL
The library could not identify a valid top-level domain from the Public Suffix List within the provided URL, often because the domain part is missing or unrecognized.
fix
Provide a URL that includes a recognized TLD and a valid domain structure, and ensure the TLD names list is up-to-date by calling `tld.update_tld_names()` if network issues might be a factor.
AttributeError: module 'tld' has no attribute 'extract'
This error typically occurs when a user installs the `tld` library but expects the functionality and API (like the `extract` function) of the `tldextract` library, which are two different packages.
fix
If you intend to use the `extract` function, install and use the `tldextract` library (`pip install tldextract`) instead of `tld`.
Upgrade
Version history
0.13.2latest on PyPI · released Mar 6, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
17
Amazon
1
OpenAI (training)
1
Resources
tld — pip install tld · libregistry