The tlds module provides a a set of valid TLDs directly taken from IANA. The package is automatically updated daily.
Available on PyPI.
>>> from tlds import tld_set >>> 'com' in tld_set True >>> 'foobar' in tld_set False >>> 'pizza' in tld_set True >>>