Skip to main content

fastlinkcheck

Check for broken external and internal links.

fastlinkcheck checks for broken links in HTML documents. This occurs in parallel so performance is fast. Both external links and internal links are checked. Internal links are checked by verifying local files.

To get started, read the documentation.

Install

pip install fastlinkcheck

Usage

After installing fastlinkcheck, the cli command link_check is available from the command line. We can see various options with the --help flag.

link_check --help
usage: link_check [-h] [--host HOST] [--config_file CONFIG_FILE] [--pdb]
                  [--xtra XTRA]
                  path

Check for broken links recursively in `path`.

positional arguments:
  path                  Root directory searched recursively for HTML files

optional arguments:
  -h, --help            show this help message and exit
  --host HOST           Host and path (without protocol) of web server
  --config_file CONFIG_FILE
                        Location of file with urls to ignore
  --pdb                 Run in pdb debugger (default: False)
  --xtra XTRA           Parse for additional args (default: '')

We can search the directory _example/broken_links in this repo recursively for broken links like this:

link_check _example/broken_links 
ERROR: The Following Broken Links or Paths were found:

- 'http://fastlinkcheck.com/test.html' was found in the following pages:
  - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`

- 'http://somecdn.com/doesntexist.html' was found in the following pages:
  - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`

- Path('/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.js') was found in the following pages:
  - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`

Specifying the --host parameter allows you detect links that are internal by identifying links with that host name. External links are verified by making a request to the appropriate website. On the other hand, internal links are verified by inspecting the presence and content of local files.

We must be careful when using the --host argument to only pass the host (and path, if necessary) without the protocol. For example, this is how we specify the hostname if your site's url is http://fastlinkcheck.com/test.html:

link_check _example/broken_links --host fastlinkcheck.com
ERROR: The Following Broken Links or Paths were found:

- 'http://somecdn.com/doesntexist.html' was found in the following pages:
  - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`

- Path('/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.js') was found in the following pages:
  - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`

We now have one less broken link as there is indeed a file named test.html in the root of the path we are searching. However, if we add a path to the end of --host , such as fastlinkcheck.com/mysite the link would again be listed as broken because _example/broken_links/mysite/test.html does not exist:

link_check _example/broken_links --host fastlinkcheck.com/mysite
ERROR: The Following Broken Links or Paths were found:

- 'http://fastlinkcheck.com/test.html' was found in the following pages:
  - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`

- 'http://somecdn.com/doesntexist.html' was found in the following pages:
  - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`

- Path('/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.js') was found in the following pages:
  - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`

You can ignore links by creating a text file that contains a list of urls and paths to ignore. For example, the file _example/broken_links/linkcheck.rc contains:

cat _example/broken_links/linkcheck.rc
test.js
https://www.google.com

We can use this file to ignore urls and paths with the --config_file argument. This will filter out references to the broken link /test.js from our earlier results:

link_check _example/broken_links --host fastlinkcheck.com --config_file _example/broken_links/linkcheck.rc
ERROR: The Following Broken Links or Paths were found:

- 'http://somecdn.com/doesntexist.html' was found in the following pages:
  - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`

Finally, if there are no broken links, link_check will not return anything. The directory _example/no_broken_links/ does not contain any HTML files with broken links:

link_check _example/no_broken_links
No broken links found!

Python

You can also use these utilities from python instead of the terminal. Please see these docs for more information.

Here is an example of how you can use this utility in GitHub Actions:

name: Check Links
on: [workflow_dispatch, push]

jobs:
  check-links:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
    - name: check for broken links
      run: |
        pip install fastlinkcheck
        link_check _example 

We can a few more lines of code to open an issue instead when a broken link is found, using the gh cli:

...
    - name: check for broken links
      run: |
        pip install fastlinkcheck
        link_check _example 2> err || true
        export GITHUB_TOKEN="YOUR_TOKEN"
        [[ -s err ]] &&  gh issue create -t "Broken links found" -b "$(< err)" -R "yourusername/yourrepo"

We can extend this even further to only open an issue when another issue with a specific label isn't already open:

...
    - name: check for broken links
      run: |
       pip install fastlinkcheck
       link_check "docs/_site" --host "docs.fast.ai" 2> err || true
        export GITHUB_TOKEN="YOUR_TOKEN"
        if [[ -z $(gh issue list -l "broken-link")) && (-s err) ]]; then
          gh issue create -t "Broken links found" -b "$(< err)" -l "broken-link" -R "yourusername/yourrepo"
        fi

See the GitHub Actions docs for more information.

Metadata

Release files for fastlinkcheck 0.0.28

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastlinkcheck 0.0.28
File Size Uploaded Provenance
fastlinkcheck-0.0.28.tar.gz 11.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fastlinkcheck 0.0.28
File Interpreter ABI Platform
fastlinkcheck-0.0.28-py3-none-any.whl Python 3 none any Details

Total release size: 21.6 kB

Release files / fastlinkcheck-0.0.28.tar.gz

Download URL fastlinkcheck-0.0.28.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
be0f453bac41dd682501623fc35d90af7da050e6a479f811cc9397c17db21d91
BLAKE2b-256 checksum
How to use checksums
9afead2e7abb71270d01598a0cb65c7117bd6bdd2577642b6f85fc3f74b94710
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / fastlinkcheck-0.0.28-py3-none-any.whl

Download URL fastlinkcheck-0.0.28-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a99db557e806c687cb0bfb28a9ed9a32658f691079359ea85d18ea5669fdbc0
BLAKE2b-256 checksum
How to use checksums
d47822c112d1368ed8cf7ff12ad75281d748469f338d026e25727a601e8f3797
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Security for fastlinkcheck 0.0.28

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page