# tld

Extract the top level domain (TLD) from the URL given. List of TLD names is taken from Mozilla.

Optionally raises exceptions on non-existing TLDs or silently fails (if `fail_silently` argument is set to True).

## Prerequisites

- Python 2.6, 2.7, 3.4, 3.5, 3.6 and PyPy

## Documentation

Documentation is available on Read the Docs.

## Installation

Latest stable version on PyPI:

    pip install tld

Or latest stable version from GitHub:

    pip install https://github.com/barseghyanartur/tld/archive/stable.tar.gz

Or latest stable version from BitBucket:

    pip install https://bitbucket.org/barseghyanartur/tld/get/stable.tar.gz

## Usage examples

### Get the TLD name as string from the URL given

    from tld import get_tld

    get_tld("http://www.google.co.uk")
    # 'co.uk'

    get_tld("http://www.google.idontexist", fail_silently=True)
    # None

### Get the TLD as an object

    from tld import get_tld

    res = get_tld("http://some.subdomain.google.co.uk", as_object=True)

    res
    # 'co.uk'

    res.subdomain
    # 'some.subdomain'

    res.domain
    # 'google'

    res.tld
    # 'co.uk'

    res.fld
    # 'google.co.uk'

    res.parsed_url
    # SplitResult(
    #     scheme='http',
    #     netloc='some.subdomain.google.co.uk',
    #     path='',
    #     query='',
    #     fragment=''
    # )

### Get TLD name, ignoring the missing protocol

    from tld import get_tld, get_fld

    get_tld("www.google.co.uk", fix_protocol=True)
    # 'co.uk'

    get_fld("www.google.co.uk", fix_protocol=True)
    # 'google.co.uk'

### Return TLD parts as tuple

    from tld import parse_tld

    parse_tld('http://www.google.com')
    # 'com', 'google', 'www'

### Get the first level domain name as string from the URL given

    from tld import get_fld

    get_fld("http://www.google.co.uk")
    # 'google.co.uk'

    get_fld("http://www.google.idontexist", fail_silently=True)
    # None

## Testing

Simply type:

    ./runtests.py

Or use tox:

    tox

Or use tox to check specific env:

    tox -e py36

## Writing documentation

Keep the following hierarchy.

    =====
    title
    =====

    header
    ======

    sub-header
    ----------

    sub-sub-header
    ~~~~~~~~~~~~~~

    sub-sub-sub-header
    ^^^^^^^^^^^^^^^^^^

    sub-sub-sub-sub-header
    ++++++++++++++++++++++

    sub-sub-sub-sub-sub-header
    **************************

## License

MPL 1.1/GPL 2.0/LGPL 2.1

## Support

For any issues contact me at the e-mail given in the Author section.

## Author

Artur Barseghyan <artur.barseghyan@gmail.com>

## Docs

Contents:

- tld
  - Prerequisites
  - Documentation
  - Installation
  - Usage examples
    - Get the TLD name as string from the URL given
    - Get the TLD as an object
    - Get TLD name, ignoring the missing protocol
    - Return TLD parts as tuple
    - Get the first level domain name as string from the URL given
  - Testing
  - Writing documentation
  - License
  - Support
  - Author
  - Docs
    - Release history and notes
      - 0.9.1
      - 0.9
      - 0.8
      - 0.7.10
      - 0.7.9
      - 0.7.8
      - 0.7.7
      - 0.7.6
      - 0.7.5
      - 0.7.4
      - 0.7.3
      - 0.7.2
      - 0.7.1
      - 0.7
      - 0.6.4
      - 0.6.3
      - 0.6.2
      - 0.6.1
      - 0.6
      - 0.5
      - 0.4
    - tld package
      - Subpackages
        - tld.commands package
          - Submodules
          - Module contents
        - tld.sources package
          - Submodules
          - tld.sources.mozilla module
          - Module contents
      - Submodules
      - tld.base module
      - tld.bench module
      - tld.conf module
      - tld.defaults module
      - tld.exceptions module
      - tld.helpers module
      - tld.tests module
      - tld.utils module
      - Module contents
  - Indices and tables
- Release history and notes
  - 0.9.1
  - 0.9
  - 0.8
  - 0.7.10
  - 0.7.9
  - 0.7.8
  - 0.7.7
  - 0.7.6
  - 0.7.5
  - 0.7.4
  - 0.7.3
  - 0.7.2
  - 0.7.1
  - 0.7
  - 0.6.4
  - 0.6.3
  - 0.6.2
  - 0.6.1
  - 0.6
  - 0.5
  - 0.4
- tld package
  - Subpackages
    - tld.commands package
      - Submodules
      - Module contents
    - tld.sources package
      - Submodules
      - tld.sources.mozilla module
      - Module contents
  - Submodules
  - tld.base module
  - tld.bench module
  - tld.conf module
  - tld.defaults module
  - tld.exceptions module
  - tld.helpers module
  - tld.tests module
  - tld.utils module
  - Module contents

## Indices and tables

- Index
- Module Index
- Search Page