publicsuffixlist 1.0.2.20260615
pip install publicsuffixlist
Released:
publicsuffixlist implement
Navigation
Verified details
These details have been verified by PyPIMaintainers
π Avatar for ko-zu from gravatar.comko-zu
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: Mozilla Public License 2.0 (MPL 2.0) (MPL-2.0)
- Author: ko-zu
- Requires: Python >=3.5
-
Provides-Extra:
update,readme
Classifiers
- Development Status
- License
- Operating System
- Topic
Project description
publicsuffixlist
Public Suffix List parser implementation for Python 3.5+.
- Compliant with TEST DATA
- Supports IDN (unicode and punycoded).
- Supports Python3.5+
- Shipped with built-in PSL and an updater script.
- Written in Pure Python with no library dependencies.
π publish package
π CI test
π PyPI version
π Downloads
Install
publicsuffixlist can be installed via pip.
$ pip install publicsuffixlist
Usage
Basic Usage:
frompublicsuffixlistimport PublicSuffixList psl = PublicSuffixList() # Uses built-in PSL file print(psl.publicsuffix("www.example.com")) # "com" # the longest public suffix part print(psl.privatesuffix("www.example.com")) # "example.com" # the shortest domain assigned for a registrant print(psl.privatesuffix("com")) # None # Returns None if no private (non-public) part found print(psl.publicsuffix("www.example.unknownnewtld")) # "unknownnewtld" # New TLDs are valid public suffix by default print(psl.publicsuffix("www.example.ι¦ζΈ―")) #"ι¦ζΈ―" # Accepts unicode print(psl.publicsuffix("www.example.xn--j6w193g")) # "xn--j6w193g" # Accepts Punycode IDNs by default print(psl.privatesuffix("WWW.EXAMPLE.COM")) # "example.com" # Returns in lowercase by default print(psl.privatesuffix("WWW.EXAMPLE.COM", keep_case=True) # "EXAMPLE.COM" # kwarg `keep_case=True` to disable the case conversion
The latest PSL is packaged once a day. If you need to parse your own version,
it can be passed as a file-like iterable object, or just a str:
with open("latest_psl.dat", "rb") as f: psl = PublicSuffixList(f)
The unittest and PSL updater can be invoked as module.
$ python -m publicsuffixlist.test
$ python -m publicsuffixlist.update
Additional convenient methods:
print(psl.is_private("example.com")) # True print(psl.is_public("example.com")) # False print(psl.privateparts("aaa.www.example.com")) # ("aaa", "www", "example.com") print(psl.subdomain("aaa.www.example.com", depth=1)) # "www.example.com"
Limitation
Domain Label Validation
publicsuffixlist do NOT provide domain name and label validation.
In the DNS protocol, most 8-bit characters are acceptable as labels of domain
names. While ICANN-compliant registries do not accept domain names containing
underscores (_), hostnames may include them. For example, DMARC records can
contain underscores. Users must confirm that the input domain names are valid
based on their specific context.
Punycode Handling
Partially encoded (Unicode-mixed) Punycode is not supported due to very slow
Punycode encoding/decoding and unpredictable encoding results. If you are
unsure whether an input is valid Punycode, you should use:
unknowndomain.encode("idna").decode("ascii"). This method, converting to idna
is idempotent.
Handling Arbitrary Binary
If you need to accept arbitrary or malicious binary data, it can be passed as a tuple of bytes. Note that the returned bytes may include byte patterns that cannot be decoded or represented as a standard domain name. Example:
psl.privatesuffix((b"a.a", b"a.example\xff", b"com")) # (b"a.example\xff", b"com") # Note that IDNs must be punycoded when passed as tuple of bytes. psl = PublicSuffixList("δΎ.example") psl.publicsuffix((b"xn--fsq", b"example")) # (b"xn--fsq", b"example") # UTF-8 encoded bytes of "δΎ" do not match. psl.publicsuffix((b"\xe4\xbe\x8b", b"example")) # (b"example",)
License
- This module is licensed under Mozilla Public License 2.0.
- The Public Suffix List maintained by the Mozilla Foundation is licensed under the Mozilla Public License 2.0.
- The PSL testcase dataset is in the public domain (CC0).
Development / Packaging
This module and its packaging workflow are maintained in the author's repository located at https://github.com/ko-zu/psl.
A new package, which includes the latest PSL file, is automatically generated
and uploaded to PyPI. The last part of the version number represents the
release date. For example, 0.10.1.20230331 indicates a release date of March
31, 2023.
This package dropped support for Python 2.7 and Python 3.4 or prior versions at the version 1.0.0 release in June 2024. The last version that works on Python 2.x is 0.10.0.x.
Source / Link
- GitHub repository: (https://github.com/ko-zu/psl)
- PyPI: (https://pypi.org/project/publicsuffixlist/)
Project details
Verified details
These details have been verified by PyPIMaintainers
π Avatar for ko-zu from gravatar.comko-zu
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: Mozilla Public License 2.0 (MPL 2.0) (MPL-2.0)
- Author: ko-zu
- Requires: Python >=3.5
-
Provides-Extra:
update,readme
Classifiers
- Development Status
- License
- Operating System
- Topic
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
Uploaded
Python 2Python 3
File details
Details for the file publicsuffixlist-1.0.2.20260615.tar.gz.
File metadata
- Download URL: publicsuffixlist-1.0.2.20260615.tar.gz
- Upload date:
- Size: 108.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d52b7b5b5b75f11bac4c034a7b181d1fd1cb27dd440a208e11c2266e631898b
|
|
| MD5 |
929fc635f3017d3106121ba500bab30b
|
|
| BLAKE2b-256 |
8a447b65b2042b3ff44478557ca05bde5320c19b2c91b51e11600c390707c8cc
|
File details
Details for the file publicsuffixlist-1.0.2.20260615-py2.py3-none-any.whl.
File metadata
- Download URL: publicsuffixlist-1.0.2.20260615-py2.py3-none-any.whl
- Upload date:
- Size: 108.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6566afa2f6183a8d1daabc27185f6bb11583091e87a7a2b3cc7d9c9fe1d3de69
|
|
| MD5 |
dd88f2474bf2116976bbb59aa84a5f0d
|
|
| BLAKE2b-256 |
bb3d4d9d61bd960bf7c2992de34fe88c444631a725f2484c1023a0bd18848265
|
