Skip to main content

Get a public suffix for a domain name using the Public Suffix List. Forked from and using the same API as the publicsuffix package.

Project description

This module allows you to get the public suffix of a domain name using the Public Suffix List from http://publicsuffix.org

A public suffix is a domain suffix under which you can register domain names. Some examples of public suffixes are .com, .co.uk and pvt.k12.wy.us. Accurately knowing the public suffix of a domain is useful when handling web browser cookies, highlighting the most important part of a domain name in a user interface or sorting URLs by web site.

This Python module includes with a copy of the Public Suffix List so that it is usable out of the box. Newer versions try to provide reasonably fresh copies of this list. It also includes a convenience method to fetch the latest list.

The code is a fork of the publicsuffix package and uses the same module name and base API.

The code is MIT-licensed and the publicsuffix data list is MPL-2.0-licensed.

Usage

Install with:

pip install publicsuffix2

The module provides a function to query a domain name:

>>> from publicsuffix import get_public_suffix
>>> get_public_suffix('www.example.com')
'example.com'
>>> get_public_suffix('www.example.co.uk')
'example.co.uk'
>>> get_public_suffix('www.super.example.co.uk')
'example.co.uk'

This function loads and caches the public suffix list.

For more control and compatibility, there is also a class that parses a Public Suffix List and allows the same queries on individual domain names:

>>> from publicsuffix import PublicSuffixList
>>> psl= PublicSuffixList()
>>> psl.get_public_suffix('www.example.com')
'example.com'
>>> psl.get_public_suffix('www.example.co.uk')
'example.co.uk'
>>> psl.get_public_suffix('www.super.example.co.uk')
'example.co.uk'

Note that the host part of an URL can contain strings that are not plain DNS domain names (IP addresses, Punycode-encoded names, name in combination with a port number or a username, etc.). It is up to the caller to ensure only domain names are passed to the get_public_suffix() method.

The get_public_suffix function and the PublicSuffixList class initializer accept an optional argument pointing to a public suffix file. This can either be a file path, an iterable of public suffix lines, or a file-like object pointing to an opened list. The fetch function fetches the latest list:

>>> from publicsuffix import get_public_suffix, fetch
>>> latest = fetch()
>>> get_public_suffix('www.example.com', latest)
'example.com'

This will use the cached latest loaded above:

>>> get_public_suffix('www.example.co.uk')
'example.co.uk'

Source

Get a local copy of the development repository. The development takes place in the develop branch. Stable releases are tagged in the master branch:

git clone https://github.com/pombredanne/python-publicsuffix2.git

History

This code is forked from Tomaž Šolc’s fork of David Wilson’s code originally at: https://www.tablix.org/~avian/git/publicsuffix.git Copyright (c) 2014 Tomaž Šolc <tomaz.solc@tablix.org>

The API is essentially the same as publicsuffix including using the same package name to allow a straight forward replacement.

David Wilson’s code was originally at: from http://code.google.com/p/python-public-suffix-list/ Copyright (c) 2009 David Wilson

License

The code is MIT-licensed. The vendored public suffix list data from Mozilla is under the MPL-2.0.

Copyright (c) 2015 nexB Inc. Copyright (c) 2014 Tomaž Šolc <tomaz.solc@tablix.org> Copyright (c) 2009 David Wilson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Changelog

2016-06-21 publicsuffix2 2.20160621

  • Updated publicsuffix.file to the latest version from Mozilla.

  • new version scheme: major.<publisiffix list date>

2015-10-12 publicsuffix2 2.1.0

  • Merged latest updates from publicsuffix

  • Added new convenience top level get_public_suffix_function caching a loaded list if needed.

  • Updated publicsuffix.file to the latest version from Mozilla.

  • Added an update_psl setup command to fetch and vendor the latest list Use as: python setup.py update_psl

2015-06-04 publicsuffix2 2.0.0

  • Forked publicsuffix, but kept the same API

  • Updated publicsuffix.file to the latest version from Mozilla.

  • Changed packaging to have the suffix list be package data and be wheel friendly.

  • Use spaces indentation, not tabs

2014-01-14 publicsuffix 1.0.5

  • Correctly handle fully qualified domain names (thanks to Matthäus Wander).

  • Updated publicsuffix.txt to the latest version from Mozilla.

2013-01-02 publicsuffix 1.0.4

  • Added missing change log.

2013-01-02 publicsuffix 1.0.3

  • Updated publicsuffix.txt to the latest version from Mozilla.

  • Added trove classifiers.

  • Minor update of the README.

2011-10-10 publicsuffix 1.0.2

  • Compatibility with Python 3.x (thanks to Joern Koerner) and Python 2.5

2011-09-22 publicsuffix 1.0.1

  • Fixed installation issue under virtualenv (thanks to Mark McClain)

2011-07-29 publicsuffix 1.0.0

  • First release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

publicsuffix2-2.20160818.zip (90.5 kB view details)

Uploaded Source

publicsuffix2-2.20160818.tar.gz (82.6 kB view details)

Uploaded Source

publicsuffix2-2.20160818.tar.bz2 (75.8 kB view details)

Uploaded Source

Built Distribution

publicsuffix2-2.20160818-py2.py3-none-any.whl (85.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file publicsuffix2-2.20160818.zip.

File metadata

File hashes

Hashes for publicsuffix2-2.20160818.zip
Algorithm Hash digest
SHA256 947e0cd265c2adc765311684e00e86d7e4b17f3fb62894eff6d1596bace17486
MD5 b38e6d193099bd07f8830141a78e7191
BLAKE2b-256 68d7c08b30db482f20f200c6a69c41adac6108acb9e9521777bf60d7abb5e43e

See more details on using hashes here.

Provenance

File details

Details for the file publicsuffix2-2.20160818.tar.gz.

File metadata

File hashes

Hashes for publicsuffix2-2.20160818.tar.gz
Algorithm Hash digest
SHA256 8346ecdde6660f5a891d11fe79f827ef514ff0f9b9a91b4d2740ad068c868a0f
MD5 7f5abb82d88ea31f87baf4e0f57a5466
BLAKE2b-256 6e9a35fa66e6bab0cad700a5f6c951f8b00de0f0cff2513607bbfcd08826d477

See more details on using hashes here.

Provenance

File details

Details for the file publicsuffix2-2.20160818.tar.bz2.

File metadata

File hashes

Hashes for publicsuffix2-2.20160818.tar.bz2
Algorithm Hash digest
SHA256 c86464922db7fcc60b0749f5ac1fd9064e138aea5fcee04d3c76eea4a62f65ad
MD5 b488f4e88e26c5e00bd581ff29558682
BLAKE2b-256 f3a5445b0fa732c6b788a1a8d1570e3d2cda5525c030b02660d261172e51597c

See more details on using hashes here.

Provenance

File details

Details for the file publicsuffix2-2.20160818-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for publicsuffix2-2.20160818-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 31d84a12b7eb937ec2ef27493f57a7fb2b2633c259806fc3ba180ee3d03942bc
MD5 4dd5ab933d2085b7c667a0c2add0e85b
BLAKE2b-256 39436148f7ecd25e0f945fc275ddf041d7a00f781b6ba06b3a1d75161ddc7860

See more details on using hashes here.

Provenance

Supported by

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