{"id":5687,"library":"publicsuffix2","title":"publicsuffix2: Public Suffix List Parser","description":"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.","status":"maintenance","version":"2.20191221","language":"en","source_language":"en","source_url":"https://github.com/nexb/python-publicsuffix2","tags":["domain","publicsuffixlist","psl","networking","security"],"install":[{"cmd":"pip install publicsuffix2","lang":"bash","label":"Install publicsuffix2"}],"dependencies":[],"imports":[{"note":"This is a fork; ensure you import from 'publicsuffix2' not the original 'publicsuffix' package.","wrong":"from publicsuffix import PublicSuffixList","symbol":"PublicSuffixList","correct":"from publicsuffix2 import PublicSuffixList"}],"quickstart":{"code":"from publicsuffix2 import PublicSuffixList\n\n# Initialize the PublicSuffixList parser\npsl = PublicSuffixList()\n\n# Get the public suffix for various domains\nprint(f\"google.com -> {psl.get_public_suffix('www.google.com')}\")\nprint(f\"co.uk -> {psl.get_public_suffix('test.co.uk')}\")\nprint(f\"github.io -> {psl.get_public_suffix('myblog.github.io')}\")\nprint(f\"local domain (should be None) -> {psl.get_public_suffix('localhost')}\")\nprint(f\"invalid domain (should be None) -> {psl.get_public_suffix('not-a-domain')}\")","lang":"python","description":"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."},"warnings":[{"fix":"Explicitly choose and consistently use either `publicsuffix` or `publicsuffix2` throughout your project. Do not intermix or rely on their interchangeability.","message":"The `publicsuffix2` package is a fork of the `publicsuffix` library. While they shared an initial API, they are distinct projects and may diverge in bundled Public Suffix List (PSL) data, behavior, or features. Switching between them or assuming future compatibility can lead to unexpected results.","severity":"breaking","affected_versions":"All versions"},{"fix":"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`.","message":"The Public Suffix List (PSL) data is bundled directly within the `publicsuffix2` package. The last release (`2.20191221`) is from late 2019, meaning the bundled PSL is significantly outdated. This can lead to incorrect public suffix identification for newer TLDs or entries, potentially causing security vulnerabilities (e.g., incorrect cookie domain handling) and functional issues. There is no mechanism to update the PSL independently of a new package release.","severity":"gotcha","affected_versions":"2.20191221 and older"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}