linkmend
linkmend finds external links that have rotted (gone dead) inside a
static site's Markdown content, and mends them by swapping in the
closest-in-time archive capture it can find — from the Wayback Machine,
WebCite, or archive.today. It ships as both a linkmend CLI for
walking a content tree and a Python library for callers who want to
resolve individual URLs themselves.
Install
The core package has zero runtime dependencies:
pip install linkmend
Two optional extras unlock more:
# Needed by `linkmend check`: reads a post's frontmatter `date` (for
# picking a near-in-time capture) and walks comment sidecar files.
pip install linkmend[hugo]
# The bundled requests-backed HTTP client, used for live link probes
# and archive lookups. Skip this if you'll supply your own HTTPClient
# (see "How it picks a replacement" below) or only ever run --offline.
pip install linkmend[requests]
# Both, which is what `linkmend check` needs for a normal (online) run:
pip install "linkmend[hugo,requests]"
Quick start
CLI
Point check at a directory of Markdown content. By default it reports
what it finds without touching any files:
linkmend check --content path/to/site/content
Add --rewrite to swap dead links for archive replacements in place,
and --report to write a JSON summary you can keep or hand to
import-report later:
linkmend check --content path/to/site/content \
--rewrite \
--report rotted.json
Sample output:
files with external links: 2
external links checked: 4
rotted (with replacement): 2
rotted (no replacement): 1
Run --offline to resolve only from what's already cached (no network
calls at all — useful in CI, or to preview a rewrite before spending
API calls):
linkmend check --content path/to/site/content --offline --rewrite
To proactively archive a URL before it goes dead:
linkmend save-url https://example.com/some/page
On success this prints the archived URL and exits 0; if the Wayback
Machine declines or the request fails, it prints an error to stderr
and exits 1.
Run linkmend <subcommand> --help for the full flag list (check,
save-url, and import-report each have one).
Library
The same resolution check uses is available directly, for callers
who want to check individual URLs rather than walk a directory:
from datetime import UTC, datetime
from linkmend import ArchiveCapture, LinkCheckDB, LinkChecker
db_path = "linkmend.db"
# In practice this cache is already populated by a prior `check` run;
# seeded here so the example is self-contained.
db = LinkCheckDB(db_path)
now = datetime.now(UTC)
db.record_seen("http://dead.example/some/page", context_date=now)
db.record_archive_captures(
"http://dead.example/some/page",
[
ArchiveCapture(
provider="wayback",
archive_url="https://web.archive.org/web/20120602000000/http://dead.example/some/page",
captured_at=datetime(2012, 6, 2, tzinfo=UTC),
discovered_at=now,
)
],
)
db.close()
checker = LinkChecker(db_path, offline=True)
result = checker.check(
"http://dead.example/some/page",
context_date=datetime(2012, 6, 1, tzinfo=UTC),
)
print(result.is_alive, result.replacement_url, result.replacement_source)
# False https://web.archive.org/web/20120602000000/http://dead.example/some/page wayback
checker.close()
Drop offline=True and pass an http client (see
requests_http_client, or supply your
own — anything matching the HTTPClient protocol works) to probe
links live and query the archive providers.
How it picks a replacement
For each URL, check tries, in order:
- A cached probe result that's still fresh (alive and within the TTL).
- A live HTTP probe (unless
--offline). - Caller-supplied fallback URLs, if any were given.
- Archive providers, in
provider_priorityorder —wayback,webcitation, thenarchive.isby default.
Once a provider returns any captures for a dead URL, linkmend picks
the one closest in time to the post's publication date (its
frontmatter date, or the sidecar's parent post's date for comment
links) — not necessarily the newest or oldest capture. Ties (same
distance) are broken by provider_priority, so an equally-close
Wayback capture wins over an equally-close archive.today one. This
logic lives in LinkCheckDB.best_capture (src/linkmend/db.py) and is
shared by both the online and --offline resolution paths.
Cache location
linkmend keeps a SQLite cache of every URL it has seen, its latest
probe result, and any archive captures it has discovered, so repeat
runs don't re-probe or re-query archives needlessly. Resolved, in
order:
$LINKMEND_DB, if set — an explicit path to the database file.$XDG_DATA_HOME/linkmend/linkmend.db, ifXDG_DATA_HOMEis set.~/.local/share/linkmend/linkmend.db, otherwise.
Every subcommand also accepts --db PATH to override this directly
for a single invocation.
Reusing a previous report
import-report reseeds the archive_captures cache table from a
report check --report previously wrote:
linkmend import-report rotted.json
This exists as a recovery path: if the cache database is lost (a new
machine, a cleared CI cache, a deleted linkmend.db) but a report from
an earlier run survives, import-report restores the replacement URLs
it already found without re-querying rate-limited archive APIs from
scratch. It only imports entries that name an actual archive capture —
entries with no replacement, or where the replacement came from a
caller-supplied fallback rather than an archive, are skipped.
Limitations
- Inline Markdown links only. The extractor handles
[text](url "title")and the image-wrapped form[](target). Reference-style links ([text][ref]with a separate[ref]: urldefinition) and bare images are not detected and will be left untouched. - Comment sidecars are opt-in and schema-specific. The bundled
HUGO_COMMENT_SIDECARpreset expectscomments.jsonbeside a post'sindex.md. Other layouts need a customSidecarSpec. - Archive availability is not guaranteed. A dead link with no
capture in any provider is reported, not fixed. Do not put
linkmend checkin a deploy gate — a third-party archive outage would then break your deploy. - Soft-404 detection is extension-driven, and only one-way. A URL
ending in a non-HTML extension (
pdf,docx,zip,png, and a handful more) that answers200 text/htmlis judged dead: the host served its fallback shell instead of the file, which is what Cloudflare Pages, most SPA hosts, and many WordPress installs do in place of a 404. The converse is not detected — an extensionless URL answeringtext/htmlcould legitimately be anything, so a soft 404 on a plain page still reads as alive.401,403, and429remain ambiguous and are left alone regardless of content type. - A soft 404 on your own site gets archived, not fixed. Once a link
is judged dead it falls through to the archive providers, which is
right for a genuinely dead external link. If the soft 404 comes from
your own site — a file you moved or dropped during a migration —
the fix belongs upstream, in your content.
linkmendcannot tell the two apart and will not try.
The CLI wires up only the HUGO_COMMENT_SIDECAR preset in this
release (0.2.0); a different sidecar shape means using the library
directly with your own SidecarSpec, not a CLI flag.
Project structure
src/linkmend/
__init__.py Public API surface (__all__)
__main__.py `python -m linkmend` entry point
cli.py argparse CLI: check / save-url / import-report
checker.py LinkChecker — resolution policy (cache → probe → fallback → archive)
db.py SQLite persistence (LinkCheckDB, best_capture)
markdown.py Inline-Markdown-link extraction and rewriting
comments.py JSON comment-sidecar walking (SidecarSpec, HUGO_COMMENT_SIDECAR)
providers.py Archive provider integrations + HTTPClient protocol
report.py Report writer and import-report reader
tests/
test_*.py One test module per area above
Licence
Apache License 2.0 — see LICENSE.
Metadata
Release files for linkmend 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| linkmend-0.2.0.tar.gz | 73.2 kB | With provenance | Details for linkmend-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| linkmend-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for linkmend-0.2.0-py3-none-any.whl |
Total release size: 109.3 kB
Release files / linkmend-0.2.0.tar.gz
| Download URL | linkmend-0.2.0.tar.gz |
|---|---|
| Size | 73.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff4cfea9e66579e1e0a39283bf632f54be7b355cec3e47ee487ff5845eea50e3
|
|
BLAKE2b-256 checksum How to use checksums |
20ad6262c92ee385b6f1e3c99950afcd204d5c23ec6a447b89ae27c9f5feda0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.
Transparency logRelease files / linkmend-0.2.0-py3-none-any.whl
| Download URL | linkmend-0.2.0-py3-none-any.whl |
|---|---|
| Size | 36.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bbfbcc2f527eb14633f227df6b9603329f2b3200399b818f18cc8235d05a1bca
|
|
BLAKE2b-256 checksum How to use checksums |
268440a530ebc4c93fcf038542b9317ef06679a3c66ecaac242a92e9bc1cade5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.
Transparency logSecurity for linkmend 0.2.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for linkmend-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.
Transparency logA 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.