skillfed

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.

publicsuffix2 v2.20191221 7.6M downloads/30d#1,718 on PyPI30
Copyleft license MIT and MPL-2.0 Abandoned released

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 publicsuffix2

uv

uv add publicsuffix2

poetry

poetry add publicsuffix2

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseLicense :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)Programming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 3Topic :: Internet :: Name Service (DNS)Topic :: Utilities

Tags

public suffix list parserextract registrable domaindomain name parsingtld extractionetld lookupdomain cookie handlingdns domain analysis
domain-parsingpsl-lookupdns-utilities

More Utilities packages