Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Update README, and make default initialiser use data file in module

  • Loading branch information...
commit a34004bbd907c6a6068dca767ddaf2344bedd13d 1 parent 602b245
@rboulton authored
Showing with 21 additions and 15 deletions.
  1. +13 −12 README.rst
  2. +6 −1 fastpublicsuffix/
  3. +2 −2
25 README.rst
@@ -1,31 +1,32 @@
This module provides a Python interface to the `Public Suffix List`_.
-The Public Suffix List (PSL) is a set of rules describing
-"effective top-level domains" and can be used to determine the registered
-domain for a given host name.
+The Public Suffix List (PSL) is a set of rules describing "effective top-level
+domains" and can be used to determine the registered domain for a given host
-This branch is maintained by `MixRank`_, we reimplemented it using a different data structure (a prefix tree)
-in order to improve performance.
+This module is maintained by Richard Boulton, based on a fork of a module from
-You will need to download the `list`_ yourself.
+You can download the `list` yourself, or use the version distributed along with
+the module.
-Call the ``init_suffix_tree`` function with the location of the list. Then call
+Call the ``init_suffix_tree`` function. Then call
`get_root_domain` to find the registered domain. This branch does not support asking
for the (E)TLD.
Find the registered domain::
- >>> publicsuffix.init_suffix_tree('names.dat')
- >>> publicsuffix.domain('')
+ >>> fastpublicsuffix.init_suffix_tree()
+ >>> fastpublicsuffix.domain('')
.. _`Public Suffix List`:
.. _`list`:
-.. _`MixRank`:
+.. _`MixRank`:
7 fastpublicsuffix/
@@ -16,6 +16,9 @@
# limitations under the License.
+import os.path
@@ -163,8 +166,10 @@ def _is_ip(address):
suffixtree = None
-def init_suffix_tree(tld_file):
+def init_suffix_tree(tld_file=None):
"""Call this first to initialize the suffix tree"""
+ if tld_file is None:
+ tld_file = os.path.join(os.path.dirname(__file__), 'public_suffix_list.txt')
fp = open(tld_file)
suffix_lines = fp.readlines()
suffix_rules = _tokenize(suffix_lines)
@@ -1,4 +1,4 @@
-from publicsuffix import init_suffix_tree, get_root_domain
+from fastpublicsuffix import init_suffix_tree, get_root_domain
def test(domain, expected):
result = get_root_domain(domain)
@@ -9,7 +9,7 @@ def test(domain, expected):
if __name__ == "__main__":
- init_suffix_tree('names.dat')
+ init_suffix_tree()
# The first set of tests here are derived from
Please sign in to comment.
Something went wrong with that request. Please try again.