Skip to content

smilliken/publicsuffix

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

publicsuffix

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.

Usage

The public_suffix_list function, called without arguments, will download the PSL and return an instance of the SuffixList class containing the current rules.

Find the registered domain:

>>> psl = publicsuffix.public_suffix_list()
>>> psl.domain('www.python.org')
u'python.org'

Find the (E)TLD:

>>> psl.tld('www.bbc.co.uk')
u'co.uk'

>>> psl.tld('parliament.uk')
u'uk'

Caching

By default, public_suffix_list downloads the PSL each time it is called. To avoid being wasteful, the function accepts optional http and headers arguments. The object provided as http must support the httplib2 interface and will be called to download the PSL.

For example, to cache the PSL for one day:

>>> psl = publicsuffix.public_suffix_list(
...     http=httplib2.Http('/path/to/cache'),
...     headers={'cache-control': 'max-age=%d' % (60*60*24)}
... )

About

Python interface to the Public Suffix List

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published