Skip to main content

publicsuffixlist implement

Project description

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.

Build Status PyPI version Downloads

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).

Source / Link

Project details


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

publicsuffixlist-0.7.10.tar.gz (93.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

publicsuffixlist-0.7.10-py2.py3-none-any.whl (93.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file publicsuffixlist-0.7.10.tar.gz.

File metadata

  • Download URL: publicsuffixlist-0.7.10.tar.gz
  • Upload date:
  • Size: 93.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.8.0 tqdm/4.62.2 CPython/3.8.10

File hashes

Hashes for publicsuffixlist-0.7.10.tar.gz
Algorithm Hash digest
SHA256 ad6e3b95ac9a835587ad906fd18b25b68f6a55b7514bf75f3722f035ec7ee521
MD5 659569cc09bfbe93c430a6e68da9f7c2
BLAKE2b-256 8ed99cef0eb1103cd756f32b1d191046b43ad8cd72ff642eaf7b35f3b1df7719

See more details on using hashes here.

File details

Details for the file publicsuffixlist-0.7.10-py2.py3-none-any.whl.

File metadata

  • Download URL: publicsuffixlist-0.7.10-py2.py3-none-any.whl
  • Upload date:
  • Size: 93.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.8.0 tqdm/4.62.2 CPython/3.8.10

File hashes

Hashes for publicsuffixlist-0.7.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 19caf9ad3cc07099998255d30278e11e55b4d3b0b22b259e0e7372a6cae68a8e
MD5 b7d6dcf9b9a9b3f162b79dfdd5dac4c6
BLAKE2b-256 79ca27f6c8f55b5da2ef2ee4e0d317be08782f2154c8ba81522448454dc8425d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page