publicsuffix2 is a Python library designed to parse and identify the public suffix of a domain name using the official Public Suffix List (PSL). It is a fork of the original 'publicsuffix' package, aiming for API compatibility. The current version is 2.20191221, released in late 2019, meaning its bundled PSL data is not recent.
pip install publicsuffix2Verified import paths — ran on the pinned version, not inferred.
Initialize PublicSuffixList and use `get_public_suffix()` to extract the registrable domain from a given hostname. It returns None for hosts that are not valid domains or do not have a recognizable public suffix.
Explicitly choose and consistently use either `publicsuffix` or `publicsuffix2` throughout your project. Do not intermix or rely on their interchangeability.
For applications requiring a current Public Suffix List, consider using a more actively maintained library that provides up-to-date PSL data, or be aware of the inherent risks and limitations of using outdated data with `publicsuffix2`.
For applications requiring a current Public Suffix List, consider migrating to a more actively maintained library that provides up-to-date PSL data, or be aware of the inherent risks and limitations of using outdated data with `publicsuffix2`.
Ensure you are importing directly from the `publicsuffix2` package, which is the correct module name for this library. Example: `from publicsuffix2 import get_public_suffix` or `from publicsuffix2 import PublicSuffixList`.
This often indicates that the domain's TLD is too new to be present in `publicsuffix2`'s static PSL. The primary fix is to use a more actively maintained library with an updated PSL. If you must use `publicsuffix2`, you'll need to manually manage an external, updated PSL file and pass it to the function if the API supports it, or handle the `None` return gracefully. The current version provides a `fetch()` method to get the latest list, which should be used if dynamic updates are feasible.
When working with Unicode domains, ensure that the domain is properly Punycode-encoded before passing it to `publicsuffix2` functions, or, if using `PublicSuffixList` directly with UTF-8 domains, you might need to set `IDNA-encoding=False` during instantiation to prevent double-conversion or incorrect processing. Example: `psl = PublicSuffixList(IDNA_encoding=False)` (refer to the library's specific IDNA handling documentation).
No dependency data recorded yet.