Skip to main content

publicsuffixlist implement

Project description

publicsuffixlist

Public Suffix List parser implementation for Python 2.5+/3.x.

  • Compliant with TEST DATA

  • Support IDN (unicode or punycoded).

  • Support Python2.5+ and Python 3.x

  • Shipped with built-in PSL and update scripts.

  • Written in Pure Python. No library dependencies.

Build Status

Install

publicsuffixlist can be installed via pip or pip3.

$ sudo pip install publicsuffixlist

If you are on a bit old destribution (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") # "unkownnewtld"
# 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.

$ python -m publicsuffixlist.test
...............
----------------------------------------------------------------------
Ran 15 tests in 2.898s

OK
$ python3 -m publicsuffixlist.test
...............
----------------------------------------------------------------------
Ran 15 tests in 2.562s

OK

Drop-in compat 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 ""

Limitation

publicsuffixlist do NOT provide domain name validation. In DNS protocol, most of 8-bit charactors are valid 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 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 result encoding. If you are not sure the input is valid Punycode or not, use .encode("idna") which is idempotence first.

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

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.3.1.tar.gz (71.8 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.3.1-py2.py3-none-any.whl (70.0 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for publicsuffixlist-0.3.1.tar.gz
Algorithm Hash digest
SHA256 37485320435bf44999608694477bfe5530629c662881db6d1bdb7e25dffe4370
MD5 23ee2cc4abe0742a22ed95a4de393348
BLAKE2b-256 9937adf15131a0c632c3a424a8f917e226e8fab2e83fc31488428533842af5e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for publicsuffixlist-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4a6a39770ce11ec5a00f7266a81a43a24ea6c16c1742c05e1fed8ddf138d183e
MD5 20ad681a7966c3e824d9d0e315125bb5
BLAKE2b-256 e593d76f1ec85dcc9c34ee92a5fa2c751423edad9ff170fce51df9415e2523f9

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