Public Suffix List

1.0.2.20260411 · active · verified Sat Apr 11

Publicsuffixlist is a Python library that implements a parser for the Public Suffix List (PSL). It allows users to extract the public suffix and registrable domain from a given hostname, supporting IDN (unicode and punycoded) and compliant with PSL test data. The library is pure Python, has no external dependencies, and ships with a bundled, frequently updated copy of the PSL. Its current version is 1.0.2.20260411, with new releases often tied to updates of the Public Suffix List itself.

Warnings

Install

Imports

Quickstart

Initialise the PublicSuffixList object to use the bundled PSL file. Then, use `publicsuffix()` to get the public suffix and `privatesuffix()` to get the registrable domain. The library inherently handles Unicode and Punycode IDNs. Users can also provide their own PSL data.

from publicsuffixlist import PublicSuffixList

psl = PublicSuffixList() # Uses built-in PSL file

# Get the longest public suffix part
print(f"Public Suffix for www.example.com: {psl.publicsuffix('www.example.com')}")
print(f"Public Suffix for www.example.co.uk: {psl.publicsuffix('www.example.co.uk')}")

# Get the shortest domain assigned for a registrant (registrable domain)
print(f"Private Suffix (registrable domain) for www.example.com: {psl.privatesuffix('www.example.com')}")
print(f"Private Suffix (registrable domain) for www.super.example.co.uk: {psl.privatesuffix('www.super.example.co.uk')}")

# Handle domains with unicode characters
print(f"Public Suffix for www.example.香港: {psl.publicsuffix('www.example.香港')}")

# Pass a custom PSL file
# with open('path/to/latest_psl.dat', 'rb') as f:
#     custom_psl = PublicSuffixList(f)

view raw JSON →