Skip to main content

gruff-py

gruff-py is the Python port of gruff, a static quality analyser built to keep AI-generated code legible, safe, and reviewable. It walks Python projects, scores findings across quality pillars, and outputs reports for terminals, CI annotations, SARIF code scanning, static HTML, and a local dashboard.

Mission

A coding agent wrote the change, and a person who did not write it has to review and trust it. Every rule, severity, and score serves that reviewer, not abstract style. Wired into a coding-agent hook, gruff-py guides the agent with advisory findings and gates it with --fail-on warning and error findings so changes stay:

  • Legible enough to verify — a reviewer can follow the control flow and confirm it does what was asked, without holding the whole function in their head.
  • Secure where the eye fails — it flags the dangerous patterns and leaked secrets human review is worst at catching, because those are the failures the eye skips.
  • Tested for real, not padded — it rewards tests that exercise behaviour and flags low-signal ceremony (assertion-free tests, tautologies, mock-only theatre) that inflates coverage without earning trust.

Doc comments are mandatory, even on a private one-liner. Agents often write code that looks like it works while misreading the requirement; stating intent, usage, contract, and failure behaviour gives the reviewer something to check the code against, and a mismatch is itself a reason to look closer.

gruff-py is heuristic static analysis. It complements ruff, mypy, pytest, security scanners, and human review; it does not replace them. docs/mission.md has the full statement.

Status At A Glance

Field Value
Release line 0.6.0 package line
Runtime Python 3.11+
Package gruff-py
Import package gruffpy with py.typed
Binary gruff-py
Rule catalogue Generated from RuleRegistry.defaults(); see Rules
Primary config .gruff-py.yaml; [tool.gruff-py] in pyproject.toml is also supported
Analysis schema gruff.analysis.v3
Baseline schema gruff.baseline.v3; gruff-py.baseline.v1 and gruff.baseline.v1 fail closed with a migration command
Severity gate --fail-on with none, advisory, warning, error; project default via failOn: in .gruff-py.yaml / pyproject.toml
Dashboard 127.0.0.1:8765 by default

Finding fingerprints are 16-character SHA-256 prefixes kept byte-compatible with gruff-php wherever rule and finding identities match. Analysis JSON uses the shared gruff.analysis.v3 schema, while hotspot and config schemas stay language-prefixed (gruff-py.*).

Each JSON finding also includes stableIdentity, a line-insensitive companion to fingerprint that lets baselines and external diff tools match the same logical finding across line shifts. See docs/output-formats.md for the exact fields hashed into each identity.

Requirements

  • Python 3.11+.
  • uv for source-checkout development.
  • Git only for diff and branch-review modes.
  • Optional external mutation tooling only when mutation flags are explicitly used.

Install

Install as a project dev dependency:

uv add --dev gruff-py
uv run gruff-py init
uv run gruff-py summary

From a source checkout:

uv sync
uv run gruff-py --help
./bin/gruff-py --help

Quick Start

# Create the project config.
uv run gruff-py init

# Review the current finding mix.
uv run gruff-py summary

# Explore without failing because of findings.
uv run gruff-py analyse src/ --fail-on none

# Gate on warning and error findings.
uv run gruff-py analyse src/ --fail-on warning

# Emit SARIF for code scanning.
uv run gruff-py analyse src/ --format sarif --fail-on none > gruff.sarif

# Generate a fresh-start baseline.
uv run gruff-py analyse src/ --generate-baseline --fail-on none

# Start the local dashboard.
uv run gruff-py dashboard src/ --report-interactive

Open http://127.0.0.1:8765/ for the dashboard.

Commands

Command Purpose
init Write a default .gruff-py.yaml to the current directory.
analyse [paths...] Run the analyser and print findings.
summary [paths...] Print compact score, pillar, rule, and file summaries.
report [paths...] Render an HTML or JSON report to stdout or --output.
list-rules [rule-id] Print rule metadata as text or JSON; pass a rule id for explain mode.
check-ignore [paths...] Report whether each path is ignored, and why (exit codes mirror git check-ignore).
hook [paths...] Run analysis for a coding-agent hook; emits gruff.hook.v2 JSON.
migrate-config Rewrite legacy config keys to the current schema; --dry-run prints the diff.
dashboard [paths...] Serve the local browser dashboard.
completion [shell] Print a shell completion script.
list, help Show command lists and command-specific help.

Global options mirror the broader gruff CLI surface: --silent, --quiet, --version, --ansi / --no-ansi, --no-interaction, and --verbose.

Output Formats

analyse --format <fmt> accepts:

Format Use it for
text Human terminal output.
json Full gruff.analysis.v3 report.
html Self-contained inspection report.
markdown Pull-request or issue comment summary.
github GitHub Actions workflow annotations.
hotspot gruff-py.hotspot.v1 file-offender JSON.
sarif SARIF 2.1.0 for code scanning.

report --format <fmt> accepts html and json.

Exit Codes

Code Meaning
0 Run completed and no finding met --fail-on.
1 At least one finding met --fail-on.
2 Fatal diagnostic such as input, parse, configuration, baseline, or diff failure.

--fail-on gates findings only. A parse error is a fatal diagnostic and exits 2 even with --fail-on none; none makes findings report-only, not diagnostics.

analyse defaults to --fail-on advisory. Set failOn.analyse in .gruff-py.yaml to change the default per-project (see docs/configuration.md).

CI Usage

Generic CI command:

uv run gruff-py analyse src tests --format github --fail-on warning

SARIF jobs can write an artifact for code scanning:

uv run gruff-py analyse src tests --format sarif --fail-on none > gruff-py.sarif

Use --no-baseline on security gates, so a finding already recorded in the adoption baseline still fails the run.

Configuration

Config is optional. Precedence is:

  1. --config <path>
  2. .gruff-py.yaml in the project root
  3. [tool.gruff-py] in pyproject.toml
  4. Built-in defaults

Example .gruff-py.yaml:

schemaVersion: gruff-py.config.v0.1

paths:
  ignore:
    - "tests/fixtures/**"

selection:
  excludeRules:
    - docs.missing-module-docstring

rules:
  size.file-length:
    threshold: 900
    severity: error

See Configuration for the full shape.

Rules And Pillars

docs/rules.md is generated from RuleRegistry.defaults() and lists every rule ID, pillar, default, and remediation note. Check that the committed copy is current without rewriting it:

uv run python -m gruffpy.command.rule_docs --check docs/rules.md

coupling, architecture, and mutation are reserved schema names with no shipping rules in 0.6.0. modernisation and maintainability lost their last rules in 0.6.0 but still count toward the composite, scoring 100 whenever files are evaluated.

Baselines And Changed-Code Scans

Baselines suppress reviewed findings by a line-free identity and a count, so an unrelated edit that shifts line numbers does not re-open reviewed debt:

uv run gruff-py analyse src/ --generate-baseline --fail-on none
uv run gruff-py analyse src/ --baseline gruff-baseline.json --fail-on warning
uv run gruff-py analyse src/ --no-baseline --fail-on none

Changed-code scans are changed-region aware: a finding is kept when its location or enclosing function/class overlaps the changed hunk. JSON output reports the findings excluded as out of scope at summary.suppressedFindings and diff.filteredFindings.

uv run gruff-py analyse --format json --changed-ranges "3-3,8-10" src/foo.py
uv run gruff-py analyse --format json --since HEAD src/foo.py
git diff | uv run gruff-py analyse --format json --diff - src/foo.py

Narrow path scans that leave project-wide rules enabled include a partial-context caveat in JSON run metadata and text output because conclusions can differ from a full-project scan.

--exclude-rule, --include-rule, --exclude-pillar, and --include-pillar are execution-level: the excluded rules do not run, so the score and the exit code move with them. Display filters such as --min-severity, --hide-rule, and --show-rule reduce rendered analyse output without changing which rules execute, the score, or the exit code. Text output discloses when findings are hidden by these filters.

Dashboard

uv run gruff-py dashboard src/ --host 127.0.0.1 --port 8765 --report-interactive

The dashboard serves a local browser UI for repeated scans. It has no authentication and is intended for local development. Non-loopback hosts are refused unless you pass --allow-public; that acknowledgment warns that remote users can scan any directory readable by the server process. See Dashboard for supported controls and safety notes.

In polyglot repositories, gruff-go, gruff-php, and gruff-py all default to port 8765 (gruff-rs uses 8766 and gruff-ts 8767); pass --port when running several dashboards at once.

Trust Boundary

Default scans are local source inspections. gruff-py parses Python source and selected project metadata; it does not execute target application code, run tests, query vulnerability feeds, or contact package registries. Git is used only for explicit diff modes. External mutation tooling is used only when explicitly requested by mutation flags. Sensitive-data previews are redacted before they reach terminal, JSON, SARIF, GitHub, Markdown, hotspot, or HTML output.

Stability Contract

Through the 0.x line, rule IDs, finding fingerprints, baseline identity, gruff.analysis.v3, gruff.summary.v3, gruff.baseline.v3, gruff-py.hotspot.v1, gruff.hook.v2, SARIF rendering, and CLI exit semantics are compatibility-sensitive. Before 1.0, a minor bump (such as 0.5.x to 0.6.0) may break them; every break carries a BREAKING: marker and a migration path in CHANGELOG.md, and UPGRADING.md explains how to migrate or pin back.

How It Compares

Tool Relationship
ruff Fast linting and formatting. gruff-py adds scoring, baselines, reports, dashboard, and project-quality rules.
mypy / Pyright Type checking. gruff-py does not prove type correctness.
pytest Runtime tests. gruff-py can flag test-quality smells but does not prove behavior.
Bandit / Semgrep / vulnerability scanners Security-focused checks. gruff-py reports local static signals and does not replace specialized scanners.
Vulture / dead-code tools Focused unused-code detection. gruff-py includes broader quality scoring and reporting.

Development

uv sync --extra dev
uv run ruff check src tests
uv run ruff format --check src tests
uv run mypy src
uv run pytest
make check

make check uses the lint target, which runs ruff check --fix. Use the explicit commands above when you need non-mutating release verification.

Documentation

Author

Built by Matthew Hansen.

License

MIT

Metadata

Release files for gruff-py 0.6.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 gruff-py 0.6.0
File Size Uploaded Provenance Actions
gruff_py-0.6.0.tar.gz 956.9 kB Without provenance Details for gruff_py-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gruff-py 0.6.0
File Interpreter ABI Platform Actions
gruff_py-0.6.0-py3-none-any.whl Python 3 none any Details for gruff_py-0.6.0-py3-none-any.whl

Total release size: 1.6 MB

Release files / gruff_py-0.6.0.tar.gz

Download URL gruff_py-0.6.0.tar.gz
Size 956.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cd9c8dbe85dc23ca3fd4698813eb3d9133e6786161570e3cf1bf8db09b30339e
BLAKE2b-256 checksum
How to use checksums
31698079949963c72de4e1a8afcbbe9eaaba465a9ba838604d67d6f04929ea16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / gruff_py-0.6.0-py3-none-any.whl

Download URL gruff_py-0.6.0-py3-none-any.whl
Size 682.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52577f749c8df39198a66ce1ff52b8d9437fde9ac01de4ef49cc741267118939
BLAKE2b-256 checksum
How to use checksums
79cd135d6e34143e953748d63ef5663362850c7a658eaa91b1b302c7de1e05a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for gruff-py 0.6.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.

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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