publicsuffix2
Get a public suffix for a domain name using the Public Suffix List. Forked from and using the same API as the publicsuffix package.
What it is and what it does
publicsuffix2 is a Python module that parses domain names against the Public Suffix List to identify the public suffix (effective TLD) and registrable domain. It builds the PSL as a Trie structure for efficient lookup, making it suitable for large-scale processing. The module comes bundled with a copy of the PSL so it works out of the box, though that data is from 2019-12-21.
The package supports several query modes: extracting the registrable domain (base domain), returning only the effective TLD, handling IDNA-encoded domains, ignoring wildcards for aggregation, and strict validation to reject domains with invalid TLDs. It exposes both convenience functions (get_public_suffix, get_sld, get_tld) and a PublicSuffixList class for finer control. However, the project is abandoned—no releases or commits since late 2021—so the bundled data will not reflect newly added public suffixes.
Use it for:
- Extract the registrable domain from a URL for web browser cookie scope management.
- Identify the effective TLD of a domain to highlight the most important part in a user interface.
- Aggregate and sort URLs by website in large-scale domain processing or DNS research.
- Validate that a domain includes a recognized public suffix using strict mode.
- Handle internationalized domain names (IDN) by toggling IDNA encoding on or off.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Extracts the public suffix and registrable domain from a domain name using the Public Suffix List, with support for IDNA encoding, wildcard handling, and strict validation.
Yes, if your domain processing needs are static or historical. The package has no dependencies, low install friction, and a stable API. However, do not use it if you require current public suffix data—the bundled list is from 2019-12-21 and the project is abandoned. Use fetch() to pull the latest list at runtime, or consider an actively maintained alternative if freshness is critical.
Install
publicsuffix2 on PyPI
pip
pip install publicsuffix2uv
uv add publicsuffix2poetry
poetry add publicsuffix2Installing publicsuffix2
Before you install
Low install friction with no runtime dependencies. However, the package is abandoned—last commit was 2021-11-02 and no releases since 2019-12-21. The Public Suffix List data bundled with the package will become stale over time.
License in practice
Dual-licensed under MIT and MPL-2.0 (copyleft). The code is MIT-licensed but the bundled Public Suffix List data is MPL-2.0-licensed, which imposes copyleft obligations on derivative works of the data.
Quickstart
pip install publicsuffix2
from publicsuffix2 import get_public_suffix
result = get_public_suffix('www.example.co.uk')
# result: 'example.co.uk'
The bundled Public Suffix List data is from 2019-12-21 and will not reflect newer public suffixes; use fetch() to download the latest list if current data is critical.
Verify before relying
- Whether the stale bundled PSL (from 2019-12-21) is acceptable for your domain processing use case.
- Performance characteristics of the Trie-based implementation in your specific workload or scale.
Package facts
| License | MIT and MPL-2.0 (copyleft) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 2,428 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 7,588,428/month — #1,718 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: publicsuffix2-2.20191221-py2.py3-none-any.whl
Keywords: domain, public suffix, suffix, dns, tld, sld, psl, idna
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
publicsuffixlistParses the Public Suffix List to extract the…
copyleft · top 5,000 on PyPI
tldsProvides a set of valid top-level domains…
permissive · top 15,000 on PyPI
tldextractAccurately extracts subdomain, domain, and…
permissive · top 1,000 on PyPI
tldExtracts the top-level domain (TLD) and…
copyleft · top 5,000 on PyPI
dnstwistGenerates domain name permutations to detect…
permissive · top 15,000 on PyPI
tldparseParses domain names into their constituent…
permissive · top 15,000 on PyPI
domain2idnaConverts domain names and URLs to Punycode/IDNA…
permissive · top 15,000 on PyPI
python-whoisQueries WHOIS servers directly to retrieve and…
permissive · top 5,000 on PyPI
whoisRetrieves WHOIS information for domain names by…
permissive · top 15,000 on PyPI