publicsuffixlist
Public Suffix List parser implementation for Python 2.6+/3.x.
- Compliant with TEST DATA
- Support IDN (unicode or punycoded).
- Support Python2.6+ and Python 3.x
- Shipped with built-in PSL and the updater script.
- Written in Pure Python. No library dependencies.
Install
publicsuffixlist can be installed via pip or pip3.
$ sudo pip install publicsuffixlist
If you are in a bit old distributions (RHEL/CentOS6.x), you may need to update pip itself before install.
$ sudo pip install -U pip
Usage
from publicsuffixlist import PublicSuffixList
psl = PublicSuffixList()
# uses built-in PSL file
psl.publicsuffix("www.example.com") # "com"
# longest public suffix part
psl.privatesuffix("www.example.com") # "example.com"
# shortest domain assigned for a registrant
psl.privatesuffix("com") # None
# None if no private (non-public) part found
psl.publicsuffix("www.example.unknownnewtld") # "unknownnewtld"
# new TLDs are valid public suffix by default
psl.publicsuffix(u"www.example.香港") # u"香港"
# accept unicode
psl.publicsuffix("www.example.xn--j6w193g") # "xn--j6w193g"
# accept punycoded IDNs by default
Latest PSL can be passed as a file like line-iterable object.
with open("latest_psl.dat", "rb") as f:
psl = PublicSuffixList(f)
Works with both Python 2.x and 3.x.
$ python2 setup.py test
$ python3 setup.py test
Drop-in compatibility code to replace publicsuffix
# from publicsuffix import PublicSuffixList
from publicsuffixlist.compat import PublicSuffixList
psl = PublicSuffixList()
psl.suffix("www.example.com") # return "example.com"
psl.suffix("com") # return "" (as str, not None)
Some convenient methods available.
psl.is_private("example.com") # True
psl.privateparts("aaa.www.example.com") # ("aaa", "www", "example.com")
psl.subdomain("aaa.www.example.com", depth=1) # "www.example.com"
Limitation
publicsuffixlist do NOT provide domain name validation.
In DNS protocol, most of 8-bit characters are acceptable label of domain name. ICANN compliant registries do not accept domain names that have _ (underscore) but hostname may have. DMARC records, for example.
Users need to confirm the input is valid based on the users' context.
Partially encoded (Unicode-mixed) Punycode is not supported because of very slow Punycode en/decoding and unpredictable encoding of results.
If you are not sure the input is valid Punycode or not, you should do unknowndomain.encode("idna") which is idempotence.
ICANN and private suffixes
The public suffix list contains both suffixes for ICANN domains and private suffixes. Using the flag only_icann the private suffixes can be deactivated:
>>> psl = PublicSuffixList()
>>> psl.publicsuffix("example.priv.at")
'priv.at'
>>> psl = PublicSuffixList(only_icann=True)
>>> psl.publicsuffix("example.priv.at")
'at'
License
- This module is licensed under Mozilla Public License 2.0.
- Public Suffix List maintained by Mozilla Foundation is licensed under Mozilla Public License 2.0.
- PSL testcase dataset is 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 instance, 0.10.1.20230331.
Source / Link
- Git repository on GitHub (https://github.com/ko-zu/psl)
- PyPI (https://pypi.org/project/publicsuffixlist/)
Metadata
Release files for publicsuffixlist 0.10.0.20231122
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| publicsuffixlist-0.10.0.20231122.tar.gz | 99.3 kB | Without provenance | Details for publicsuffixlist-0.10.0.20231122.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| publicsuffixlist-0.10.0.20231122-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for publicsuffixlist-0.10.0.20231122-py2.py3-none-any.whl |
Total release size: 198.6 kB
Release files / publicsuffixlist-0.10.0.20231122.tar.gz
| Download URL | publicsuffixlist-0.10.0.20231122.tar.gz |
|---|---|
| Size | 99.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d02ac754fa104d2dc8f593ef7ffe305905f8bd89f9bc079653135a9e39db17ad
|
|
BLAKE2b-256 checksum How to use checksums |
fd1b8ae9c1f25b5971dbd1b5d5d56836bf38dc7d689a2eb2742673b8c24feeb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / publicsuffixlist-0.10.0.20231122-py2.py3-none-any.whl
| Download URL | publicsuffixlist-0.10.0.20231122-py2.py3-none-any.whl |
|---|---|
| Size | 99.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
ce47acf7fb7e817fba8397b43896fcb4b4307d41e2c9d2f63418b3e65c7f15cb
|
|
BLAKE2b-256 checksum How to use checksums |
d18bbd1454ece37f2d5b00db0d79158e9a4bbad16bf9aaade48582212958ce89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Security for publicsuffixlist 0.10.0.20231122
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.