Skip to main content

Split domain names into subdomain, registered, and public parts per the Public Suffix List

Project description

public_suffix_list

This is a module for querying the Public Suffix List to determine effective top level domains.

It provides APIs to split domain names into subdomains, registered, and public suffix parts.

Note this module does NOT include a copy of the public suffix list, it downloads the list, caches it, and periodically checks for updates automatically.

As such, internet connectivity is required. If the list is unable to be refreshed, it will continue to run with the last cached version.

For applications that do not have internet connectivity, use an alternate package that includes a copy of the list, or pre-populate the cache file through other means. Note that without periodic updates the list will get out of date.

Cache updates happen on a thread so do not cause processing delays.

See https://publicsuffix.org/ for details about the list.

API

The package provides the following functions which operate on a single, global list instance:

public_suffix_list.setup(url: str = None, cache_dir: str = None, refresh_interval: datetime.timedelta = None, log: Logger = None) -> PublicSuffixList: ...

Initialize the global list. Only needs to be called if not using the default values.

Accepts an optional URL to download the list from, the default is: https://publicsuffix.org/list/public_suffix_list.dat

The list cache will be stored in a file 'public_suffix_list.dat' in the cache_dir, the default cache_dir is '.'.

The refresh_interval defaults to 24 hours.

An optional logger will receive debug and error messages. If a logger is not provided, fatal errors will raise exceptions.

public_suffix_list.split_domain(domain_name: str) -> Tuple[str, str, str]: ...

Split a domain name into subdomain, registered name, and publix suffix.

Returns a Tuple of (subdomain, registered name, public suffix).

e.g. www.example.com -> (www, example, com)

public_suffix_list.public_suffix(domain_name: str) -> str: ...

Return public suffix of domain name.

e.g. www.example.com -> com

public_suffix_list.registered_name(domain_name: str) -> str: ...

Return registered name of domain name only.

e.g. www.example.com -> example

public_suffix_list.registered_domain_name(domain_name: str) -> str: ...

Return fully qualified registered domain name.

e.g. www.example.com -> example.com

public_suffix_list.split_registered_domain_name(domain_name: str) -> Tuple[str, str]: ...

Split a domain name into subdomain and fully qualified registered domain name.

e.g. www.example.com -> (www, example.com)


And the following class:

public_suffix_list.PublicSuffixList

PublicSuffixList(url: str = None, cache_dir: str = None, refresh_interval: datetime.timedelta = None, log: Logger = None) -> None: ...

Instantiate a PublicSuffixList.

Accepts an optional URL to download the list from, the default is: https://publicsuffix.org/list/public_suffix_list.dat

The list cache will be stored in a file 'public_suffix_list.dat' in the cache_dir, the default cache_dir is '.'.

The refresh_interval defaults to 24 hours.

An optional logger will receive debug and error messages. If a logger is not provided, fatal errors will raise exceptions.

PublicSuffixList.split_domain(self, domain_name: str) -> Tuple[str, str, str]: ...

Split a domain name into subdomain, registered name, and publix suffix.

Returns a Tuple of (subdomain, registered name, public suffix).

e.g. www.example.com -> (www, example, com)

PublicSuffixList.public_suffix(self, domain_name: str) -> str:

Return public suffix of domain name.

e.g. www.example.com -> com

PublicSuffixList.registered_name(self, domain_name: str) -> str:

Return registered name of domain name only.

e.g. www.example.com -> example

PublicSuffixList.registered_domain_name(self, domain_name: str) -> str:

Return registered domain name.

e.g. www.example.com -> example.com

PublicSuffixList.split_registered_domain_name(self, domain_name: str) -> Tuple[str, str]:

Split a domain name into subdomain and registered domain.

e.g. www.example.com -> (www, example.com)


pubic_suffix_list.Logger(Protocol)

The protocol for the optional logger.

Logger.detail(self, *args) -> None: ...

Print detailed debug information.

Used when downloading the list.

Logger.warning(self, *args) -> None: ...

Print a non-fatal error.

Used when the list download fails.

Logger.error(self, *args) -> None: ...

Print a fatal error.

Used when the cache is unavailable and the list is unable to be downloaded or stored.

Installation

Install with pip:

pip install public-suffix-list

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

public_suffix_list-1.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file public_suffix_list-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: public_suffix_list-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10

File hashes

Hashes for public_suffix_list-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c7c787f65459f2397d5fb0b6293e0cdcac8378b6cbe2e6e9ec00c1ff7f6b66b
MD5 d6e6a3f4c25ef77a87fb049295ff79c5
BLAKE2b-256 a4d1a82eba64ea78a10f9877816ecec6b07d1b71ae5febd6b79c1d14b3b5eb67

See more details on using hashes here.

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