Skip to main content

PyAnchor

PyPI version GitHub

Dead links are an annoyance for websites with an extensive amount of content. A side from the negative impact on SEO, dead links are an annoyance for any user that clicks on one.

PyAnchor is primarily for checking the HTTP response on all links on a page. You can integrate it into your development workflow so that users never see a 404 in the first place.

Install

Requires Python 3.10 and above.

It is recommended that you install this package in a virtual or isolated environment. The easiest way to do this is with pipx.

pipx install pyanchor

Alternatively, you can install it with pip into your virtual environment:

MacOS / Linux:

python3 -m pip install pyanchor

Windows:

python -m pip install pyanchor

Using the CLI

The CLI can be invoked with the pyanchor command. A URL must be provided unless it's the help page.

To get the help page:

pyanchor --help

Example Gif

Basic example for a single page:

Note: all provided URLs must include a valid HTTP scheme.

pyanchor https://mysite.com/

Example Gif

If you want to check all links on a website, and not just a single page, a sitemap.xml URL may be provided and flagged with --sitemap.

Example:

pyanchor https://mysite.com/sitemap.xml --sitemap

Example Gif

By default, successful requests are not printed to the terminal. To see all urls with a 200 response add the --verbose flag.

pyanchor https://mysite.com --verbose

Example Gif

pyanchor https://mysite.com/sitemap.xml --sitemap --verbose

Example Gif

If you wish the output the results to a csv file, instead of to the terminal (default), then you may wish to use the --output-csv flag:

pyanchor https://mysite.com --output-csv output/path/to/file

But wait, there's more...

To integrate PyAnchor into your application, you can import the LinkResults class. LinkResults requires a URL.

Example:

>>> from pyanchor.link_checker import LinkResults
>>> r = LinkResults("https://mysite.com/")
>>> r.results
{200: ["https://mysite.com/about/", "https://mysite.com/contact/"], 500: ["https://mysite.com/doh!/"]}

As you can see the results attribute is a dictionary containing all response codes returned as a dictionary key, with a list of URLs that achieve that response code as the dictionary value.

PyAnchor give you the ability to use the LinkAnalysis class to check the links in a given URL for unsafe and obsolete attributes.

To check for obsolete attributes use the obsolete_attrs property:

>>> from pyanchor.link_checker import LinkAnalysis
>>> r = LinkAnalysis("https://mysite.com/")
>>> r.obsolete_attrs
{'/about/link-1': ['charset', 'rev'], '/about/link-2': ['name']}

Likewise you can check for unsafe linkes with unsafe_attrs:

>>> from pyanchor.link_checker import LinkAnalysis
>>> r = LinkAnalysis("https://mysite.com/")
>>> r.unsafe_attrs
{<a href="/about/link-4" target="_blank">Link 4</a>: True, <a href="/about/link-5" rel="noreferrer noopener" target="_blank">Link 5</a>: False}

Any link that does not include rel="noopener" when the target attribute is used will return True. As in, it is True that this link is unsafe. Therfore, links with appropriate attributes will return False.

Feedback

If you find a bug, please file an issue.

If you have feature requests, please file an issue and use the appropriate label.

Support

If you would like to show your support for the project, you can sponsor me on GitHub? 🤓

How to Contribute

Please raise an issue before making a PR, so that the issue and implementation can be discussed before you write any code. This will save you time, and increase the chances of your PR being merged without significant changes.

Please make PR's on a new branch, and not on main/master.

Please include tests for any PR's that include code (unless current tests cover your code contribution).

Please add documentation for any new features or flags.

Contributors

Thank you to:

Metadata

Release files for pyanchor 0.9.0

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

Source distribution (sdist)

Source distribution for pyanchor 0.9.0
File Size Uploaded
pyanchor-0.9.0.tar.gz 281.8 kB Details

Built distribution (wheel)

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

Total release size: 289.6 kB

Release files / pyanchor-0.9.0.tar.gz

Download URL pyanchor-0.9.0.tar.gz
Size 281.8 kB
Tags Source
SHA-256 checksum
How to use checksums
529c6e82293dc1581c9e37f894037556cec4abb71ae3505d6c9464acc9ecad9c
BLAKE2b-256 checksum
How to use checksums
f2074ce66e399d8be56ca4ef279218df3deed62a2cee8a49181e2338ab3cdbd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / pyanchor-0.9.0-py3-none-any.whl

Download URL pyanchor-0.9.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c6b1cbd41f4348e67231170f429b9f40f0ad34081e3f5dc6c79864868e9b6bf
BLAKE2b-256 checksum
How to use checksums
e0add7db4ff6ba1a65f1bfa125f6410cceec6e466495a715ac30ad66caa49500
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5

2 release files

0.4

2 release files

0.3.1

2 release files

0.3

2 release files

0.2.1

2 release files

0.2

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

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