Package: public-suffix-list
public_suffix_listThis 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.Seehttps://publicsuffix.org/for details about the list.APIThe 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.datThe 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-> compublic_suffix_list.registered_name(domain_name: str) -> str: ...Return registered name of domain name only.e.g.www.example.com-> examplepublic_suffix_list.registered_domain_name(domain_name: str) -> str: ...Return fully qualified registered domain name.e.g.www.example.com-> example.compublic_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.PublicSuffixListPublicSuffixList(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.datThe 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-> comPublicSuffixList.registered_name(self, domain_name: str) -> str:Return registered name of domain name only.e.g.www.example.com-> examplePublicSuffixList.registered_domain_name(self, domain_name: str) -> str:Return registered domain name.e.g.www.example.com-> example.comPublicSuffixList.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.InstallationInstall with pip:pip install public-suffix-list