skip to navigation
skip to content

tldextract 1.7.5

Accurately separate the TLD from the registered domain andsubdomains of a URL, using the Public Suffix List.

tldextract accurately separates the gTLD or ccTLD (generic or country code top-level domain) from the registered domain and subdomains of a URL.

>>> import tldextract
>>> tldextract.extract('')
ExtractResult(subdomain='', domain='cnn', suffix='com')
>>> tldextract.extract('') # United Kingdom
ExtractResult(subdomain='forums', domain='bbc', suffix='')
>>> tldextract.extract('') # Kyrgyzstan
ExtractResult(subdomain='www', domain='worldbank', suffix='')

ExtractResult is a namedtuple, so it’s simple to access the parts you want.

>>> ext = tldextract.extract('')
>>> (ext.subdomain, ext.domain, ext.suffix)
('forums', 'bbc', '')
>>> # rejoin subdomain and domain
>>> '.'.join(ext[:2])
>>> # a common alias
>>> ext.registered_domain
File Type Py Version Uploaded on Size
tldextract-1.7.5.tar.gz (md5) Source 2016-02-07 62KB
  • Downloads (All Versions):
  • 4407 downloads in the last day
  • 18986 downloads in the last week
  • 111121 downloads in the last month