{"id":31772050,"url":"https://github.com/aboutcode-org/python-publicsuffix2","last_synced_at":"2025-12-12T00:59:49.099Z","repository":{"id":33199734,"uuid":"36842215","full_name":"aboutcode-org/python-publicsuffix2","owner":"aboutcode-org","description":"A small Python library to deal with publicsuffix data (includes a bundled PSL as \"package data\") in a wheel friendly format. Fork and continuation of Tomaž Šolc's \"publicsuffix\"","archived":false,"fork":false,"pushed_at":"2021-11-02T15:57:36.000Z","size":647,"stargazers_count":31,"open_issues_count":11,"forks_count":15,"subscribers_count":10,"default_branch":"develop","last_synced_at":"2025-09-14T04:30:29.456Z","etag":null,"topics":["publicsuffix","python","tld","top-level-domain"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aboutcode-org.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-04T02:07:39.000Z","updated_at":"2025-01-31T06:24:23.000Z","dependencies_parsed_at":"2022-07-20T12:02:21.692Z","dependency_job_id":null,"html_url":"https://github.com/aboutcode-org/python-publicsuffix2","commit_stats":null,"previous_names":["nexb/python-publicsuffix2"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/aboutcode-org/python-publicsuffix2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aboutcode-org%2Fpython-publicsuffix2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aboutcode-org%2Fpython-publicsuffix2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aboutcode-org%2Fpython-publicsuffix2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aboutcode-org%2Fpython-publicsuffix2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aboutcode-org","download_url":"https://codeload.github.com/aboutcode-org/python-publicsuffix2/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aboutcode-org%2Fpython-publicsuffix2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002601,"owners_count":26083426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["publicsuffix","python","tld","top-level-domain"],"created_at":"2025-10-10T03:55:15.637Z","updated_at":"2025-10-10T03:55:25.276Z","avatar_url":"https://github.com/aboutcode-org.png","language":"Python","readme":"Public Suffix List module for Python\n====================================\n\nThis module allows you to get the public suffix, as well as the registrable domain,\nof a domain name using the Public Suffix List from http://publicsuffix.org\n\nA public suffix is a domain suffix under which you can register domain\nnames, or under which the suffix owner does not control the subdomains.\nSome examples of public suffixes in the former example are \".com\",\n\".co.uk\" and \"pvt.k12.wy.us\"; examples of the latter case are \"github.io\" and\n\"blogspot.com\".  The public suffix is sometimes referred to as the effective\nor extended TLD (eTLD).\nAccurately knowing the public suffix of a domain is useful when handling\nweb browser cookies, highlighting the most important part of a domain name\nin a user interface or sorting URLs by web site. It is also used in a wide range\nof research and applications that leverages Domain Name System (DNS) data.\n\nThis module builds the public suffix list as a Trie structure, making it more efficient\nthan other string-based modules available for the same purpose. It can be used\neffectively in large-scale distributed environments, such as PySpark.\n\nThis Python module includes with a copy of the Public Suffix List (PSL) so that it is\nusable out of the box. Newer versions try to provide reasonably fresh copies of\nthis list. It also includes a convenience method to fetch the latest list. The PSL does\nchange regularly.\n\nThe code is a fork of the publicsuffix package and includes the same base API. In\naddition, it contains a few variants useful for certain use cases, such as the option to\nignore wildcards or return only the extended TLD (eTLD). You just need to import publicsuffix2 instead.\n\nThe public suffix list is now provided in UTF-8 format. To correctly process\nIDNA-encoded domains, either the query or the list must be converted. By default, the\nmodule converts the PSL. If your use case includes UTF-8 domains, e.g., '食狮.com.cn',\nyou'll need to set the IDNA-encoding flag to False on instantiation (see examples below).\nFailure to use the correct encoding for your use case can lead to incorrect results for\ndomains that utilize unicode characters.\n\nThe code is MIT-licensed and the publicsuffix data list is MPL-2.0-licensed.\n\n.. image:: https://api.travis-ci.org/nexB/python-publicsuffix2.png?branch=master\n   :target: https://travis-ci.org/nexB/python-publicsuffix2\n   :alt: master branch tests status\n\n.. image:: https://api.travis-ci.org/nexB/python-publicsuffix2.png?branch=develop\n   :target: https://travis-ci.org/nexB/python-publicsuffix2\n   :alt: develop branch tests status\n\nUsage\n-----\n\nInstall with::\n\n    pip install publicsuffix2\n\nThe module provides functions to obtain the base domain, or sld, of an fqdn, as well as one\nto get just the public suffix. In addition, the functions a number of boolean parameters that\ncontrol how wildcards are handled. In addition to the functions, the module exposes a class that\nparses the PSL, and allows for more control.\n\nThe module provides two equivalent functions to query a domain name, and return the base domain,\nor second-level-doamin; get_public_suffix() and get_sld()::\n\n    \u003e\u003e\u003e from publicsuffix2 import get_public_suffix\n    \u003e\u003e\u003e get_public_suffix('www.example.com')\n    'example.com'\n    \u003e\u003e\u003e get_sld('www.example.com')\n    'example.com'\n    \u003e\u003e\u003e get_public_suffix('www.example.co.uk')\n    'example.co.uk'\n    \u003e\u003e\u003e get_public_suffix('www.super.example.co.uk')\n    'example.co.uk'\n    \u003e\u003e\u003e get_sld(\"co.uk\")  # returns eTLD as is\n    'co.uk'\n\nThis function loads and caches the public suffix list. To obtain the latest version of the\nPSL, use the fetch() function to first download the latest version. Alternatively, you can pass\na custom list.\n\nFor more control, there is also a class that parses a Public\nSuffix List and allows the same queries on individual domain names::\n\n    \u003e\u003e\u003e from publicsuffix2 import PublicSuffixList\n    \u003e\u003e\u003e psl = PublicSuffixList()\n    \u003e\u003e\u003e psl.get_public_suffix('www.example.com')\n    'example.com'\n    \u003e\u003e\u003e psl.get_public_suffix('www.example.co.uk')\n    'example.co.uk'\n    \u003e\u003e\u003e psl.get_public_suffix('www.super.example.co.uk')\n    'example.co.uk'\n    \u003e\u003e\u003e psl.get_sld('www.super.example.co.uk')\n    'example.co.uk'\n\nNote that the ``host`` part of an URL can contain strings that are\nnot plain DNS domain names (IP addresses, Punycode-encoded names, name in\ncombination with a port number or a username, etc.). It is up to the\ncaller to ensure only domain names are passed to the get_public_suffix()\nmethod.\n\nThe get_public_suffix() function and the PublicSuffixList class initializer accept\nan optional argument pointing to a public suffix file. This can either be a file\npath, an iterable of public suffix lines, or a file-like object pointing to an\nopened list::\n\n    \u003e\u003e\u003e from publicsuffix2 import get_public_suffix\n    \u003e\u003e\u003e psl_file = 'path to some psl data file'\n    \u003e\u003e\u003e get_public_suffix('www.example.com', psl_file)\n    'example.com'\n\nNote that when using get_public_suffix() a global cache keeps the latest provided\nsuffix list data.  This will use the cached latest loaded above::\n\n    \u003e\u003e\u003e get_public_suffix('www.example.co.uk')\n    'example.co.uk'\n\n**IDNA-encoding.** The public suffix list is now in UTF-8 format. For those use cases that\ninclude IDNA-encoded domains, the list must be converted. Publicsuffix2 includes idna\nencoding as a parameter of the PublicSuffixList initialization and is true by\ndefault. For UTF-8 use cases, set the idna parameter to False::\n\n    \u003e\u003e\u003e from publicsuffix2 import PublicSuffixList\n    \u003e\u003e\u003e psl = PublicSuffixList(idna=True)  # on by default\n    \u003e\u003e\u003e psl.get_public_suffix('www.google.com')\n    'google.com'\n    \u003e\u003e\u003e psl = PublicSuffixList(idna=False)  # use UTF-8 encodings\n    \u003e\u003e\u003e psl.get_public_suffix('食狮.com.cn')\n    '食狮.com.cn'\n\n**Ignore wildcards.** In some use cases, particularly those related to large-scale domain processing,\nthe user might want to ignore wildcards to create more aggregation. This is possible by setting\nthe parameter wildcard=False.::\n\n    \u003e\u003e\u003e psl.get_public_suffix('telinet.com.pg', wildcard=False)\n    'com.pg'\n    \u003e\u003e\u003e psl.get_public_suffix('telinet.com.pg', wildcard=True)\n    'telinet.com.pg'\n\n**Require valid eTLDs (strict).** In the publicsuffix2 module, a domain with an invalid TLD will still return\nreturn a base domain, e.g,::\n\n    \u003e\u003e\u003e psl.get_public_suffix('www.mine.local')\n    'mine.local'\n\nThis is useful for many use cases, while in others, we want to ensure that the domain includes a\nvalid eTLD. In this case, the boolean parameter strict provides a solution. If this flag is set,\nan invalid TLD will return None.::\n\n    \u003e\u003e\u003e psl.get_public_suffix('www.mine.local', strict=True) is None\n    True\n\n**Return eTLD only.** The standard use case for publicsuffix2 is to return the registrable,\nor base, domain\naccording to the public suffix list. In some cases, however, we only wish to find the eTLD\nitself. This is available via the get_tld() method.::\n\n    \u003e\u003e\u003e psl.get_tld('www.google.com')\n    'com'\n    \u003e\u003e\u003e psl.get_tld('www.google.co.uk')\n    'co.uk'\n\nAll of the methods and functions include the wildcard and strict parameters.\n\nFor convenience, the public method get_sld() is available. This is identical to the method\nget_public_suffix() and is intended to clarify the output for some users.\n\nTo **update the bundled suffix list** use the provided setup.py command::\n\n    python setup.py update_psl\n\nThe update list will be saved in `src/publicsuffix2/public_suffix_list.dat`\nand you can build a new wheel with this bundled data.\n\nAlternatively, there is a fetch() function that will fetch the latest version\nof a Public Suffix data file from https://publicsuffix.org/list/public_suffix_list.dat\nYou can use it this way::\n\n    \u003e\u003e\u003e from publicsuffix2 import get_public_suffix\n    \u003e\u003e\u003e from publicsuffix2 import fetch\n    \u003e\u003e\u003e psl_file = fetch()\n    \u003e\u003e\u003e get_public_suffix('www.example.com', psl_file)\n    'example.com'\n\nNote that the once loaded, the data file is cached and therefore fetched only\nonce.\n\nThe extracted public suffix list, that is the tlds and their modifiers, is put into\nan instance variable, tlds, which can be accessed as an attribute, tlds.::\n\n    \u003e\u003e\u003e psl = PublicSuffixList()\n    \u003e\u003e\u003e psl.tlds[:5]\n    ['ac',\n    'com.ac',\n    'edu.ac',\n    'gov.ac',\n    'net.ac']\n\n**Using the module in large-scale processing**\nIf using this library in large-scale pyspark processing, you should instantiate the class as\na global variable, not within a user function. The class methods can then be used within user\nfunctions for distributed processing.\n\nSource\n------\n\nGet a local copy of the development repository. The development takes\nplace in the ``develop`` branch. Stable releases are tagged in the ``master``\nbranch::\n\n    git clone https://github.com/nexB/python-publicsuffix2.git\n\n\nHistory\n-------\nThis code is forked from Tomaž Šolc's fork of David Wilson's code.\n\nTomaž Šolc's code originally at:\n\nhttps://www.tablix.org/~avian/git/publicsuffix.git\n\nCopyright (c) 2014 Tomaž Šolc \u003ctomaz.solc@tablix.org\u003e\n\nDavid Wilson's code was originally at:\n\nhttp://code.google.com/p/python-public-suffix-list/\n\nCopyright (c) 2009 David Wilson\n\n\nLicense\n-------\n\nThe code is MIT-licensed.\nThe vendored public suffix list data from Mozilla is under the MPL-2.0.\n\nCopyright (c) 2015 nexB Inc. and others.\n\nCopyright (c) 2014 Tomaž Šolc \u003ctomaz.solc@tablix.org\u003e\n\nCopyright (c) 2009 David Wilson\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the \"Software\"),\nto deal in the Software without restriction, including without limitation\nthe rights to use, copy, modify, merge, publish, distribute, sublicense,\nand/or sell copies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faboutcode-org%2Fpython-publicsuffix2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faboutcode-org%2Fpython-publicsuffix2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faboutcode-org%2Fpython-publicsuffix2/lists"}