{"id":16641183,"url":"https://github.com/barseghyanartur/tld","last_synced_at":"2026-03-07T01:16:45.085Z","repository":{"id":9775077,"uuid":"11746687","full_name":"barseghyanartur/tld","owner":"barseghyanartur","description":"Extracts the top level domain (TLD) from the URL given.","archived":false,"fork":false,"pushed_at":"2023-08-31T05:33:46.000Z","size":1902,"stargazers_count":182,"open_issues_count":8,"forks_count":35,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-08T08:05:29.300Z","etag":null,"topics":["domain-parsing","python","tld","top-level-domain","url-parsing"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/tld","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"macmillian/cs193p-winter-2015","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/barseghyanartur.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE.rst","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null}},"created_at":"2013-07-29T18:33:46.000Z","updated_at":"2025-04-11T07:00:11.000Z","dependencies_parsed_at":"2023-10-20T18:18:09.959Z","dependency_job_id":null,"html_url":"https://github.com/barseghyanartur/tld","commit_stats":{"total_commits":361,"total_committers":17,"mean_commits":"21.235294117647058","dds":"0.13296398891966754","last_synced_commit":"e7d6c0b62adaf7140e9a2232898844290e9610a0"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barseghyanartur%2Ftld","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barseghyanartur%2Ftld/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barseghyanartur%2Ftld/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barseghyanartur%2Ftld/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barseghyanartur","download_url":"https://codeload.github.com/barseghyanartur/tld/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["domain-parsing","python","tld","top-level-domain","url-parsing"],"created_at":"2024-10-12T07:45:42.558Z","updated_at":"2026-03-07T01:16:45.015Z","avatar_url":"https://github.com/barseghyanartur.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"===\ntld\n===\nExtract the top level domain (TLD) from the URL given. List of TLD names is\ntaken from `Public Suffix \u003chttps://publicsuffix.org/list/public_suffix_list.dat\u003e`_.\n\nOptionally raises exceptions on non-existing TLDs or silently fails (if\n``fail_silently`` argument is set to True).\n\n.. image:: https://img.shields.io/pypi/v/tld.svg\n   :target: https://pypi.python.org/pypi/tld\n   :alt: PyPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/tld.svg\n    :target: https://pypi.python.org/pypi/tld/\n    :alt: Supported Python versions\n\n.. image:: https://github.com/barseghyanartur/tld/workflows/test/badge.svg\n   :target: https://github.com/barseghyanartur/tld/actions\n   :alt: Build Status\n\n.. image:: https://readthedocs.org/projects/tld/badge/?version=latest\n    :target: http://tld.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n\n.. image:: https://img.shields.io/badge/license-MPL--1.1%20OR%20GPL--2.0--only%20OR%20LGPL--2.1--or--later-blue.svg\n   :target: https://github.com/barseghyanartur/tld/#License\n   :alt: MPL-1.1 OR GPL-2.0-only OR LGPL-2.1-or-later\n\n.. image:: https://coveralls.io/repos/github/barseghyanartur/tld/badge.svg?branch=master\u0026service=github\n    :target: https://coveralls.io/github/barseghyanartur/tld?branch=master\n    :alt: Coverage\n\nPrerequisites\n=============\n- Python 3.7, 3.8, 3.9, 3.10 or 3.11.\n\nDocumentation\n=============\nDocumentation is available on `Read the Docs\n\u003chttp://tld.readthedocs.io/\u003e`_.\n\nInstallation\n============\nLatest stable version on PyPI:\n\n.. code-block:: sh\n\n    pip install tld\n\nOr latest stable version from GitHub:\n\n.. code-block:: sh\n\n    pip install https://github.com/barseghyanartur/tld/archive/stable.tar.gz\n\nUsage examples\n==============\nIn addition to examples below, see the `jupyter notebook \u003cjupyter/\u003e`_\nworkbook file.\n\nGet the TLD name **as string** from the URL given\n-------------------------------------------------\n.. code-block:: python\n\n    from tld import get_tld\n\n    get_tld(\"http://www.google.co.uk\")\n    # 'co.uk'\n\n    get_tld(\"http://www.google.idontexist\", fail_silently=True)\n    # None\n\nGet the TLD as **an object**\n----------------------------\n.. code-block:: python\n\n    from tld import get_tld\n\n    res = get_tld(\"http://some.subdomain.google.co.uk\", as_object=True)\n\n    res\n    # 'co.uk'\n\n    res.subdomain\n    # 'some.subdomain'\n\n    res.domain\n    # 'google'\n\n    res.tld\n    # 'co.uk'\n\n    res.fld\n    # 'google.co.uk'\n\n    res.parsed_url\n    # SplitResult(\n    #     scheme='http',\n    #     netloc='some.subdomain.google.co.uk',\n    #     path='',\n    #     query='',\n    #     fragment=''\n    # )\n\nGet TLD name, **ignoring the missing protocol**\n-----------------------------------------------\n.. code-block:: python\n\n    from tld import get_tld, get_fld\n\n    get_tld(\"www.google.co.uk\", fix_protocol=True)\n    # 'co.uk'\n\n    get_fld(\"www.google.co.uk\", fix_protocol=True)\n    # 'google.co.uk'\n\nReturn TLD parts as tuple\n-------------------------\n.. code-block:: python\n\n    from tld import parse_tld\n\n    parse_tld('http://www.google.com')\n    # 'com', 'google', 'www'\n\nGet the first level domain name **as string** from the URL given\n----------------------------------------------------------------\n.. code-block:: python\n\n    from tld import get_fld\n\n    get_fld(\"http://www.google.co.uk\")\n    # 'google.co.uk'\n\n    get_fld(\"http://www.google.idontexist\", fail_silently=True)\n    # None\n\nCheck if some tld is a valid tld\n--------------------------------\n\n.. code-block:: python\n\n    from tld import is_tld\n\n    is_tld('co.uk)\n    # True\n\n    is_tld('uk')\n    # True\n\n    is_tld('tld.doesnotexist')\n    # False\n\n    is_tld('www.google.com')\n    # False\n\nUpdate the list of TLD names\n============================\nTo update/sync the tld names with the most recent versions run the following\nfrom your terminal:\n\n.. code-block:: sh\n\n    update-tld-names\n\nOr simply do:\n\n.. code-block:: python\n\n    from tld.utils import update_tld_names\n\n    update_tld_names()\n\nNote, that this will update all registered TLD source parsers (not only the\nlist of TLD names taken from Mozilla). In order to run the update for a single\nparser, append ``uid`` of that parser as argument.\n\n.. code-block:: sh\n\n    update-tld-names mozilla\n\nCustom TLD parsers\n==================\nBy default list of TLD names is taken from Mozilla. Parsing implemented in\nthe ``tld.utils.MozillaTLDSourceParser`` class. If you want to use another\nparser, subclass the ``tld.base.BaseTLDSourceParser``, provide ``uid``,\n``source_url``, ``local_path`` and implement the ``get_tld_names`` method.\nTake the ``tld.utils.MozillaTLDSourceParser`` as a good example of such\nimplementation. You could then use ``get_tld`` (as well as other ``tld``\nmodule functions) as shown below:\n\n.. code-block:: python\n\n    from tld import get_tld\n    from some.module import CustomTLDSourceParser\n\n    get_tld(\n        \"http://www.google.co.uk\",\n        parser_class=CustomTLDSourceParser\n    )\n\nCustom list of TLD names\n========================\nYou could maintain your own custom version of the TLD names list (even multiple\nones) and use them simultaneously with built in TLD names list.\n\nYou would then store them locally and provide a path to it as shown below:\n\n.. code-block:: python\n\n    from tld import get_tld\n    from tld.utils import BaseMozillaTLDSourceParser\n\n    class CustomBaseMozillaTLDSourceParser(BaseMozillaTLDSourceParser):\n\n        uid: str = 'custom_mozilla'\n        local_path: str = 'tests/res/effective_tld_names_custom.dat.txt'\n\n    get_tld(\n        \"http://www.foreverchild\",\n        parser_class=CustomBaseMozillaTLDSourceParser\n    )\n    # 'foreverchild'\n\nSame goes for first level domain names:\n\n.. code-block:: python\n\n    from tld import get_fld\n\n    get_fld(\n        \"http://www.foreverchild\",\n        parser_class=CustomBaseMozillaTLDSourceParser\n    )\n    # 'www.foreverchild'\n\nNote, that in both examples shown above, there the original TLD names file has\nbeen modified in the following way:\n\n.. code-block:: text\n\n    ...\n    // ===BEGIN ICANN DOMAINS===\n\n    // This one actually does not exist, added for testing purposes\n    foreverchild\n    ...\n\nFree up resources\n=================\nTo free up memory occupied by loading of custom TLD names, use\n``reset_tld_names`` function with ``tld_names_local_path`` parameter.\n\n.. code-block:: python\n\n    from tld import get_tld, reset_tld_names\n\n    # Get TLD from a custom TLD names parser\n    get_tld(\n        \"http://www.foreverchild\",\n        parser_class=CustomBaseMozillaTLDSourceParser\n    )\n\n    # Free resources occupied by the custom TLD names list\n    reset_tld_names(\"tests/res/effective_tld_names_custom.dat.txt\")\n\nTroubleshooting\n===============\nIf somehow domain names listed `here \u003chttps://publicsuffix.org/list/public_suffix_list.dat\u003e`_\nare not recognised, make sure you have the most recent version of TLD names in\nyour virtual environment:\n\n.. code-block:: sh\n\n    update-tld-names\n\nTo update TLD names list for a single parser, specify it as an argument:\n\n.. code-block:: sh\n\n    update-tld-names mozilla\n\nTesting\n=======\nSimply type:\n\n.. code-block:: sh\n\n    pytest\n\nOr use tox:\n\n.. code-block:: sh\n\n    tox\n\nOr use tox to check specific env:\n\n.. code-block:: sh\n\n    tox -e py39\n\nWriting documentation\n=====================\n\nKeep the following hierarchy.\n\n.. code-block:: text\n\n    =====\n    title\n    =====\n\n    header\n    ======\n\n    sub-header\n    ----------\n\n    sub-sub-header\n    ~~~~~~~~~~~~~~\n\n    sub-sub-sub-header\n    ^^^^^^^^^^^^^^^^^^\n\n    sub-sub-sub-sub-header\n    ++++++++++++++++++++++\n\n    sub-sub-sub-sub-sub-header\n    **************************\n\nLicense\n=======\nMPL-1.1 OR GPL-2.0-only OR LGPL-2.1-or-later\n\nSupport\n=======\nFor security issues contact me at the e-mail given in the `Author`_ section.\n\nFor overall issues, go to `GitHub \u003chttps://github.com/barseghyanartur/tld/issues\u003e`_.\n\nAuthor\n======\nArtur Barseghyan \u003cartur.barseghyan@gmail.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarseghyanartur%2Ftld","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarseghyanartur%2Ftld","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarseghyanartur%2Ftld/lists"}