Skip to main content

Shopify Image Audit

CI Python 3.11+ ruff tests

A Lighthouse-based image audit tool for Shopify stores. Produces per-image scores, role assignments, optimisation recommendations, and a before/after comparison workflow that proves image-optimisation ROI to paying customers.

Designed for the 99–199 € audit-on-demand business model: run the audit, deliver a customer-ready HTML report, optionally compare live metrics after the customer implements the recommendations.


Quickstart

git clone https://github.com/xopsio/shopify-image-audit.git
cd shopify-image-audit
python -m venv .venv && source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -e ".[dev]"

# Verify the install
audit version
pytest -q                                              # 390 tests

CLI commands

The tool ships with a single Typer app. Run audit --help for the full list; below are the high-value entry points.

audit run <url> — full Lighthouse + audit pipeline

audit run https://kauppa.myshopify.com --device mobile --runs 3 \
    --out-dir artifacts
# -> artifacts/lhr_run1.json, audit_result.json (schema-compliant)

audit baseline <lhr.json> --save baseline.json — capture baseline

audit baseline fixtures/before_after/before_lcp.json \
    --save baseline.json \
    --url https://demo.myshopify.com
# -> Baseline saved to baseline.json

audit compare <baseline> <current> — before/after (file or URL)

# File vs file (offline)
audit compare baseline.json fixtures/before_after/after_lcp.json \
    -o comparison.html --json comparison.json

# File vs live URL (fetches via PageSpeed Insights API)
audit compare baseline.json https://demo.myshopify.com \
    --strategy mobile --api-key YOUR_KEY \
    -o comparison.html

# HTML report includes a per-image delta table (bytes, score, status per image).
# PDF export via --pdf flag.

Exit codes: 0 success, 2 invalid args, 10 backend failure.

audit report <audit_result.json> — HTML or PDF report

audit report baseline.json -o report.html          # HTML
audit report baseline.json -o report.pdf --pdf     # PDF (WeasyPrint)

audit measure <url> — live PageSpeed metrics only

audit measure https://demo.myshopify.com --strategy mobile
# -> JSON metrics to stdout (or --output metrics.json)

audit shopify <auth|inventory> <store> — Shopify Admin API

# Verify a token
audit shopify auth mystore.myshopify.com --access-token shpat_xxx
# -> Token valid, prints shop info

# List all image URLs (products + theme assets)
audit shopify inventory mystore.myshopify.com --access-token shpat_xxx -o inventory.json

Read-only scopes required (read_products, read_themes, read_shop). See docs/integrations/SHOPIFY_ADMIN.md for token-acquisition steps.

audit score <audit_input.json> --ranker {heuristic|ml}

audit score extracted.json                    # default: heuristic
audit score extracted.json --ranker ml        # weighted feature ensemble

Full reference: docs/spec/cli_v0_1.md.


Scoring algorithms

The pipeline assigns each image a role, a score (0–100), and a recommendation. Two rankers ship, switchable via --ranker ml:

Ranker Formula Use case
heuristic (default) bytes per displayed pixel (bpp) + LCP penalty fast, predictable baseline
ml weighted ensemble: f_size, f_density, f_format, f_dim_match + LCP strictness richer signal, more honest scoring

Both produce the same output contract (role + score + recommendation). The ML ranker is a hand-coded feature ensemble, not a statistical model — see src/audit/ranker_ml.py for the design rationale (no model deps, deterministic, fully explainable via ml_features()).


Architecture

src/
├── audit/                    # scoring + reporting
│   ├── models.py             # Pydantic v2 schemas (AuditResult, ComparisonResult, ImageDelta)
│   ├── parser.py             # Lighthouse / fixture JSON parser
│   ├── ranker_heuristic.py   # default ranker (bpp-based)
│   ├── ranker_ml.py          # opt-in ML-style ranker (weighted ensemble)
│   └── report.py             # HTML/PDF report renderer (split into _render_* funcs)
├── core/                     # core algorithms
│   ├── image_extractor.py    # LHR image audit extraction
│   ├── image_signals.py      # shared displayed_area, assign_role, _safe_int
│   └── baseline_manager.py   # save/load baselines + compare() + per-image matching
├── engine/                   # orchestration + CLI
│   ├── cli.py                # Typer app (run, measure, baseline, compare, shopify, ...)
│   ├── cli_helpers/          # extracted CLI helpers (validators, dispatchers, table, errors)
│   └── audit_orchestrator.py # run_audit() pipeline
└── integrations/             # external APIs
    ├── pagespeed_api.py      # PageSpeed Insights (measure + fetch_lighthouse_json)
    └── shopify_admin.py      # Shopify Admin API (auth, products, theme_assets)

schemas/audit_result.schema.json    # JSON Schema contract (validated by tests)
tests/                              # 390 tests, single-writer (ZCode)
docs/examples/                       # live demo report + comparison JSON
docs/integrations/                   # Shopify Admin API token guide

The codebase is governed by a single ZCode agent (see docs/governance.md v1.3).


Testing

pytest -q                                # 606 tests, single-writer discipline
pytest --cov=src --cov-report=term       # ~87% coverage
ruff check src/ tests/                   # 0 violations

The CI workflow runs pytest -q + ruff check on Python 3.11 and 3.12 for every PR. Branch protection on main requires both checks to pass before merge. See .github/workflows/ci.yml.


Customer deliverables (Phase 1)


Roadmap

  • ✅ Sprint 1 — v0.1.0 baseline (parser, ranker, orchestrator, CLI, HTML report, 103 tests)
  • ✅ Sprint 2 — before/after workflow, customer docs, ML ranker, live URL compare, CI, governance cleanup (276 tests)
  • ✅ Sprint 3 — PDF export, per-image deltas, Shopify Admin API, v0.2.0 release prep (390 tests)
  • ✅ Sprint 4 — Branded reports, ROI-ranked recs, audit history, v0.3.0 (489 tests)
    • Branded report templates (--brand-logo, --brand-color)
    • ROI-ranked recommendations (ComparisonRecommendation model)
    • Audit history + trend view (HistoryStore, audit history list/show)
  • ✅ Sprint 5 — Snapshot tests, CLI coverage, error decorator wiring, history diff, v0.4.0 (546 tests)
    • Snapshot testing infrastructure (syrupy) for HTML renderers
    • CLI coverage for all 10 commands
    • Error decorator wiring + consistency pass (RuntimeError → exit 10)
    • audit history diff with stable entry-ids
    • CHANGELOG.md and --cov-fail-under=85 CI gate

Further reading

Download files

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

Source Distribution

shopify_image_audit-0.5.0.tar.gz (119.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shopify_image_audit-0.5.0-py3-none-any.whl (73.4 kB view details)

Uploaded Python 3

File details

Details for the file shopify_image_audit-0.5.0.tar.gz.

File metadata

  • Download URL: shopify_image_audit-0.5.0.tar.gz
  • Upload date:
  • Size: 119.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for shopify_image_audit-0.5.0.tar.gz
Algorithm Hash digest
SHA256 69e9d4f7a2e1b858fef83eff1a4f6356f1d824721942fcd8f11f8f83e259b3e7
MD5 ac0dd1412ac1d02c9e9d997ecceebc00
BLAKE2b-256 e981c1551e5e31ee2d6d29391b2d0a40188a2a3549b4eb9f5e6888e09b6932b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for shopify_image_audit-0.5.0.tar.gz:

Publisher: release.yml on xopsio/shopify-image-audit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shopify_image_audit-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for shopify_image_audit-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95c79607e761070d9659f4840685087b68e3509ac63734226be757ef893facf1
MD5 d6246aa5ec8b3107e7280c619458574d
BLAKE2b-256 dcc3297c011b5dbe3f5d0a52f7412499b6b604c71ad30684a21d14ee55f509c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for shopify_image_audit-0.5.0-py3-none-any.whl:

Publisher: release.yml on xopsio/shopify-image-audit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page