Rust-accelerated pixelmatch and SSIM for PNG bytes
Maintained. Last release 2 weeks ago, commits in 3 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install pixelhogpixelhog
Fast visual regression primitives for Python, implemented in Rust.
pixelhog compares screenshots in two complementary ways:
diff: exact pixel-level differences (with anti-alias handling), optional diff image outputssim: perceptual similarity score in[0.0, 1.0]
It also provides spatial clustering (where on the page did things change), early-exit checks,
and WebP thumbnail generation — all accessible through a stateful Comparison object that
decodes images once and exposes methods on demand.
Install (local dev)
uv venv .venv --python 3.12
source .venv/bin/activate
uv pip install -U pip maturin
maturin develop --release
Quickstart
from pixelhog import Comparison, thumbnail
cmp = Comparison(baseline_png, current_png)
count = cmp.diff_count() # pixel mismatch count
score = cmp.ssim() # perceptual similarity
png = cmp.diff_image() # diff visualization (PNG bytes)
thumb = cmp.current_thumbnail(width=200) # lossless WebP thumbnail
# Spatial clustering — where did things change?
result = cmp.clusters(dilation=8, merge_gap=60)
for cluster in result.clusters:
print(cluster.bbox.x, cluster.bbox.y, cluster.bbox.width, cluster.bbox.height)
# Early exit — fail fast if too many diffs
capped = cmp.diff_count_capped(max_diffs=1000)
# Standalone thumbnail (lossless WebP, Lanczos3 downscale, top-crop)
thumb = thumbnail(current_png, width=200, height=150)
API at a glance
Comparison
| Method | Returns | Notes |
|---|---|---|
Comparison(baseline_png, current_png) | Comparison | Decode pair once, call methods on demand |
Comparison.from_rgba(...) | Comparison | Pre-decoded RGBA buffers |
Comparison.batch(pairs) | list[Comparison] | Parallel decode |
.diff_count(threshold, include_aa) | int | Pixel mismatch count |
.diff_count_capped(max_diffs, ...) | int | Early-exit count |
.ssim() |