skip to navigation
skip to content

Not Logged In

tldextract 1.7.1

Accurately separate the TLD from the registered domain and subdomains 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.1.tar.gz (md5) Source 2015-08-23 57KB
  • Downloads (All Versions):
  • 5417 downloads in the last day
  • 33177 downloads in the last week
  • 128792 downloads in the last month