{"id":1746,"library":"tld","title":"TLD Extraction Library","description":"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.","status":"active","version":"0.13.2","language":"en","source_language":"en","source_url":"https://github.com/barseghyanartur/tld","tags":["tld","url","domain","parsing","public suffix list"],"install":[{"cmd":"pip install tld","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"get_tld","correct":"from tld import get_tld"},{"note":"The function name and import path changed in newer versions (post 0.11.x). `update_tld_list` is deprecated/removed.","wrong":"from tld import update_tld_list","symbol":"update_tld_names","correct":"from tld.utils import update_tld_names"}],"quickstart":{"code":"from tld import get_tld\nfrom tld.utils import update_tld_names\n\n# It's good practice to update the TLD names regularly\n# This fetches the latest Public Suffix List\n# For production, consider running this in a scheduled job, not on every startup.\n# update_tld_names()\n\nurl1 = \"http://www.google.co.uk\"\ntld1 = get_tld(url1)\nprint(f\"TLD for '{url1}': {tld1}\")\n\nurl2 = \"https://sub.domain.example.com/path?query=1\"\nobj2 = get_tld(url2, as_object=True)\nprint(f\"TLD for '{url2}': {obj2.tld}\")\nprint(f\"Subdomain: {obj2.subdomain}\")\nprint(f\"Domain: {obj2.domain}\")\nprint(f\"Full domain: {obj2.fld}\")\n\ntry:\n    invalid_url = \"ftp://invalid-url\"\n    get_tld(invalid_url, fail_silently=False)\nexcept Exception as e:\n    print(f\"Error extracting TLD for '{invalid_url}': {e}\")","lang":"python","description":"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`."},"warnings":[{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"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)`.","message":"The default value for the `search_private` parameter in `get_tld` changed from `True` to `False`.","severity":"breaking","affected_versions":"0.12.0 and later"},{"fix":"Update your import and function call to `from tld.utils import update_tld_names; update_tld_names()`.","message":"The function `tld.update_tld_list` was replaced by `tld.utils.update_tld_names`.","severity":"deprecated","affected_versions":"Prior to 0.12.0"},{"fix":"Upgrade your Python environment to Python 3.7 or newer.","message":"Python 3.6 support was dropped.","severity":"breaking","affected_versions":"0.13.0 and later"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}