# tld package

## Subpackages

- tld.commands package
  - Submodules
  - Module contents
- tld.sources package
  - Submodules
  - tld.sources.mozilla module
  - Module contents

## Submodules

## tld.base module

class `tld.base.``BaseTLDSource`

  Bases: `object`

  Base TLD source.

  `uid` = None

## tld.bench module

## tld.conf module

## tld.defaults module

## tld.exceptions module

exception `tld.exceptions.``TldBadUrl`(url)

  Bases: `ValueError`

  TldBadUrl.

  Supposed to be thrown when bad URL is given.

exception `tld.exceptions.``TldDomainNotFound`(domain_name)

  Bases: `ValueError`

  TldDomainNotFound.

  Supposed to be thrown when domain name is not found (didn’t match) the local TLD policy.

exception `tld.exceptions.``TldImproperlyConfigured`(msg=None)

  Bases: `Exception`

  TldImproperlyConfigured.

  Supposed to be thrown when code is improperly configured. Typical use-case is when user tries to use get_tld function with both search_public and search_private set to False.

exception `tld.exceptions.``TldIOError`(msg=None)

  Bases: `OSError`

  TldIOError.

  Supposed to be thrown when problems with reading/writing occur.

## tld.helpers module

`tld.helpers.``project_dir`(base)

  Project dir.

`tld.helpers.``PROJECT_DIR`(base)

  Project dir.

## tld.tests module

class `tld.tests.``TldTest`(methodName='runTest')

  Bases: `unittest.case.TestCase`

  Tld tests.

  `setUp`()

    Set up.

  `test_0_tld_names_loaded`(*args, **kwargs)

    Inner.

  `test_10_tld_bad_patterns_pass`(*args, **kwargs)

    Inner.

  `test_11_parse_tld_good_patterns`(*args, **kwargs)

    Inner.

  `test_2_fld_good_patterns_pass`(*args, **kwargs)

    Inner.

  `test_3_fld_bad_patterns_pass`(*args, **kwargs)

    Inner.

  `test_4_override_settings`(*args, **kwargs)

    Inner.

  `test_5_tld_good_patterns_pass_parsed_object`(*args, **kwargs)

    Inner.

  `test_6_override_full_names_path`(*args, **kwargs)

    Inner.

  `test_7_public_private`(*args, **kwargs)

    Inner.

  `test_8_fld_bad_patterns_exceptions`(*args, **kwargs)

    Inner.

  `test_9_tld_good_patterns_pass`(*args, **kwargs)

    Inner.

## tld.utils module

`tld.utils.``get_fld`(url, fail_silently=False, fix_protocol=False, search_public=True, search_private=True, **kwargs)

  Extract the first level domain.

  Extract the top level domain based on the mozilla’s effective TLD names dat file. Returns a string. May throw `TldBadUrl` or `TldDomainNotFound` exceptions if there’s bad URL provided or no TLD match found respectively.

  Parameters:

  - url (str) – URL to get top level domain from.
  - fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
  - fix_protocol (bool) – If set to True, missing or wrong protocol is ignored (https is appended instead).
  - search_public (bool) – If set to True, search in public domains.
  - search_private (bool) – If set to True, search in private domains.

  Returns: | String with top level domain (if `as_object` argument is set to False) or a `tld.utils.Result` object (if `as_object` argument is set to True); returns None on failure.
  Return type: | str

`tld.utils.``get_tld`(url, fail_silently=False, as_object=False, fix_protocol=False, search_public=True, search_private=True)

  Extract the top level domain.

  Extract the top level domain based on the mozilla’s effective TLD names dat file. Returns a string. May throw `TldBadUrl` or `TldDomainNotFound` exceptions if there’s bad URL provided or no TLD match found respectively.

  Parameters:

  - url (str) – URL to get top level domain from.
  - fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
  - as_object (bool) – If set to True, `tld.utils.Result` object is returned, `domain`, `suffix` and `tld` properties.
  - fix_protocol (bool) – If set to True, missing or wrong protocol is ignored (https is appended instead).
  - search_public (bool) – If set to True, search in public domains.
  - search_private (bool) – If set to True, search in private domains.

  Returns: | String with top level domain (if `as_object` argument is set to False) or a `tld.utils.Result` object (if `as_object` argument is set to True); returns None on failure.
  Return type: | str

`tld.utils.``get_tld_names`(fail_silently=False, retry_count=0)

  Build the `tlds` list if empty. Recursive.

  Parameters:

  - fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
  - retry_count (int) – If greater than 1, we raise an exception in order to avoid infinite loops.

  Returns: | List of TLD names
  Type: | iterable

`tld.utils.``process_url`(url, fail_silently=False, fix_protocol=False, search_public=True, search_private=True)

  Process URL.

  Parameters:

  - url –
  - fail_silently –
  - fix_protocol –
  - search_public –
  - search_private –

  Returns: |

class `tld.utils.``Result`(tld, domain, subdomain, parsed_url)

  Bases: `object`

  Container.

  `domain`
  `extension`

    Alias of `tld`.

    Return str: |

  `fld`

    First level domain.

    Returns: |
    Return type: | str

  `parsed_url`
  `subdomain`
  `suffix`

    Alias of `tld`.

    Return str: |

  `tld`

`tld.utils.``parse_tld`(url, fail_silently=False, fix_protocol=False, search_public=True, search_private=True)

  Parse TLD into parts.

  Parameters:

  - url –
  - fail_silently –
  - fix_protocol –
  - search_public –
  - search_private –

  Returns: |
  Return type: | tuple

## Module contents

`tld.``get_fld`(url, fail_silently=False, fix_protocol=False, search_public=True, search_private=True, **kwargs)

  Extract the first level domain.

  Extract the top level domain based on the mozilla’s effective TLD names dat file. Returns a string. May throw `TldBadUrl` or `TldDomainNotFound` exceptions if there’s bad URL provided or no TLD match found respectively.

  Parameters:

  - url (str) – URL to get top level domain from.
  - fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
  - fix_protocol (bool) – If set to True, missing or wrong protocol is ignored (https is appended instead).
  - search_public (bool) – If set to True, search in public domains.
  - search_private (bool) – If set to True, search in private domains.

  Returns: | String with top level domain (if `as_object` argument is set to False) or a `tld.utils.Result` object (if `as_object` argument is set to True); returns None on failure.
  Return type: | str

`tld.``get_tld`(url, fail_silently=False, as_object=False, fix_protocol=False, search_public=True, search_private=True)

  Extract the top level domain.

  Extract the top level domain based on the mozilla’s effective TLD names dat file. Returns a string. May throw `TldBadUrl` or `TldDomainNotFound` exceptions if there’s bad URL provided or no TLD match found respectively.

  Parameters:

  - url (str) – URL to get top level domain from.
  - fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
  - as_object (bool) – If set to True, `tld.utils.Result` object is returned, `domain`, `suffix` and `tld` properties.
  - fix_protocol (bool) – If set to True, missing or wrong protocol is ignored (https is appended instead).
  - search_public (bool) – If set to True, search in public domains.
  - search_private (bool) – If set to True, search in private domains.

  Returns: | String with top level domain (if `as_object` argument is set to False) or a `tld.utils.Result` object (if `as_object` argument is set to True); returns None on failure.
  Return type: | str

`tld.``get_tld_names`(fail_silently=False, retry_count=0)

  Build the `tlds` list if empty. Recursive.

  Parameters:

  - fail_silently (bool) – If set to True, no exceptions are raised and None is returned on failure.
  - retry_count (int) – If greater than 1, we raise an exception in order to avoid infinite loops.

  Returns: | List of TLD names
  Type: | iterable

`tld.``parse_tld`(url, fail_silently=False, fix_protocol=False, search_public=True, search_private=True)

  Parse TLD into parts.

  Parameters:

  - url –
  - fail_silently –
  - fix_protocol –
  - search_public –
  - search_private –

  Returns: |
  Return type: | tuple

class `tld.``Result`(tld, domain, subdomain, parsed_url)

  Bases: `object`

  Container.

  `domain`
  `extension`

    Alias of `tld`.

    Return str: |

  `fld`

    First level domain.

    Returns: |
    Return type: | str

  `parsed_url`
  `subdomain`
  `suffix`

    Alias of `tld`.

    Return str: |

  `tld`