Skip to main content

Collects and extracts URLs from given text.

Project description

URLExtract is python class for collecting (extracting) URLs from given text based on locating TLD.

Build Status Git tag Python Version Compatibility

How does it work

It tries to find any occurrence of TLD in given text. If TLD is found it starts from that position to expand boundaries to both sides searching for “stop character” (usually whitespace, comma, single or double quote).

A dns check option is available to also reject invalid domain names.

NOTE: List of TLDs is downloaded from to keep you up to date with new TLDs.


Package is available on PyPI - you can install it via pip.
pip install urlextract


Online documentation is published at


  • IDNA for converting links to IDNA format

  • uritools for domain name validation

  • appdirs for determining user’s cache directory

  • dnspython to cache DNS results

    pip install idna
    pip install uritools
    pip install appdirs
    pip install dnspython


You can look at command line program at the end of But everything you need to know is this:

from urlextract import URLExtract

extractor = URLExtract()
urls = extractor.find_urls("Text with URLs. Let's have URL as an example.")
print(urls) # prints: ['']

Or you can get generator over URLs in text by:

from urlextract import URLExtract

extractor = URLExtract()
example_text = "Text with URLs. Let's have URL as an example."

for url in extractor.gen_urls(example_text):
    print(url) # prints: ['']

Or if you want to just check if there is at least one URL you can do:

from urlextract import URLExtract

extractor = URLExtract()
example_text = "Text with URLs. Let's have URL as an example."

if extractor.has_urls(example_text):
    print("Given text contains some URL")

If you want to have up to date list of TLDs you can use update():

from urlextract import URLExtract

extractor = URLExtract()

or update_when_older() method:

from urlextract import URLExtract

extractor = URLExtract()
extractor.update_when_older(7) # updates when list is older that 7 days

Known issues

Since TLD can be not only shortcut but also some meaningful word we might see “false matches” when we are searching for URL in some HTML pages. The false match can occur for example in css or JS when you are referring to HTML item using its classes.

Example HTML code:

<p class="bold name">Jan</p>
<style> {
    font-weight: bold;

If this HTML snippet is on the input of urlextract.find_urls() it will return as an URL. Behavior of urlextract is correct, because .name is valid TLD and urlextract just see that there is valid domain name and p is valid sub-domain.


This piece of code is licensed under The MIT License.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for urlextract, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size urlextract-1.0.0-py3-none-any.whl (19.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size urlextract-1.0.0.tar.gz (28.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page