Skip to main content

pyrigor

PyPI version Downloads CI Publish Python 3.11-3.14 Ruff pre-commit Type hints: Pyright Type hints: mypy Type hints: ty Pylint pydocstyle Complexity: xenon Code complexity: radon Cognitive complexity: complexipy pytest: 100% coverage License: MIT actionlint Security: bandit Dead code: vulture codespell Checked with pyrigor

Catches the class of bug type checkers structurally cannot: a NamedTuple/keyword-only-argument/return-value-usage rule set for Python, inspired by safety-critical coding guidelines from other languages.

  • Enforced rules catching real, silent bugs mypy strict mode passes clean
  • Validated against real, public codebases: CPython's stdlib, Home Assistant, mypy, requests, hypothesis, abseil-py
  • Checks an 18,187-file real-world codebase in under a minute
  • Drop-in pre-commit integration, or run standalone

The tool pyrigor complements Python's tooling ecosystem. It does not try to replace it. If an established tool such as Pylint, Ruff, or a type checker already provides an adequate check, pyrigor will not duplicate that rule. Instead, pyrigor focuses on gaps where it can add distinct value.

Table of Contents

The problem, in one example

The Mars Climate Orbiter was lost because two teams silently disagreed about units. The code for that class of bug would still get past mypy today.

Thrust = NewType("Thrust", float)
FuelMass = NewType("FuelMass", float)


def compute_burn_time(*, thrust: Thrust, fuel_mass: FuelMass) -> float: ...


# Both floats. Nothing about a bare float stops this from running,
# type-checking cleanly, and silently swapping the two values.
compute_burn_time(thrust=fuel_mass, fuel_mass=thrust)

This is pyrigor's PYR201 rule, NewType for same-typed values at risk of being swapped. It is documented today, not yet enforced. What pyrigor already catches, right now:

$ pyrigor launch_sequence.py
launch_sequence.py:12:1: PYR402 Function 'compute_burn_time' has
positional parameters; all parameters should be keyword-only
(keyword-only-arguments)

Usage

pip install pyrigor
pyrigor path/to/file.py [path/to/another.py ...]

Every rule marked enforced in guidelines/RULES.md runs automatically. A violation exits non-zero and prints path:line:col: PYRxxx message (symbolic-name).

Run pyrigor --version to check the installed version. Use --select=CODE,CODE to restrict checking to specific rules, for example pyrigor --select=PYR401,keyword-only-arguments path/. Use --ignore=CODE,CODE to exclude specific rules instead, running every other one. Both may be combined — --ignore removes codes from --select's set (or from every rule, if --select is omitted). The codes may be given as the full code, the bare number, or the symbolic name, the same as suppression comments. An unrecognised code exits immediately with an error naming it, as does a --select/--ignore combination that leaves no rules to check. Use --exclude PATH to omit a file or directory and everything below it. Repeat the option to exclude multiple paths. This exclusion is applied by pyrigor itself, independently of any pre-commit file filter.

PYR402 can be fixed explicitly after reviewing the planned change:

pyrigor --fix --select PYR402 path/
pyrigor --diff --select=PYR402 path/

--fix writes only the selected safe fixes and reports changed files. The --diff flag previews the same changes without writing. Fixer modes require explicit PYR402 selection; ordinary linting remains read-only. Both --select PYR402 and --select=PYR402 are accepted.

For the machine-readable editor or tooling integration, use --output-format=json. It emits one JSON document containing diagnostics, read/parse errors, and suppression counts. The default human-readable format is unchanged. See guidelines/JSON_DIAGNOSTICS.md for the contract and schema.

To suppress a specific violation, add a same-line comment with a reason:

def f(weight, bias):  # pyrigor PYR402 # matches a fixed external API
    ...

Codes may be given as the full code (PYR402), the bare number (402), or the rule's symbolic name (keyword-only-arguments). Multiple codes: # pyrigor 402,403 # reason. A suppression comment without a reason is ignored, and a warning is printed. Suppressed violations are counted per rule in the summary (PYR402: 1 suppressed), not silently discarded.

When stacking with another tool's own suppression comment on the same line (# nosec, # complexipy: ignore, ...), put pyrigor's own comment last — # nosec # pyrigor PYR402 # reason. The pyrigor comment must come after any other tool's comment, since its reason captures to the end of the line.

A suppression comment may also go on the line directly above the violation, or anywhere within a multi-line statement's own span — useful when a long, descriptive name plus the mandatory reason would not fit on the violating line itself:

# pyrigor PYR402 # long test names plus a mandatory reason need more room
def apply_correction_for_the_pytest_fixture_injection_case(weight, bias): ...

The same-line still works exactly as before — these are additional locations, not a replacement. This flexibility is a deliberate design advantage over tools like ruff or bandit, which require the suppression comment to sit on the exact physical line of the violation, making it easy to place incorrectly on wrapped statements. The pyrigor suppression works anywhere within the violation's span, so placement matters less.

Adding pyrigor to your own project

Add pyrigor to your own .pre-commit-config.yaml as a pinned, remote hook, the same way you would add ruff or black:

- repo: https://github.com/jarl-hoyem/pyrigor
  rev: v0.12.0
  hooks:
    - id: pyrigor
      args: [--exclude, generated]

Pin rev: to a real, released tag, not main. Check the release page for the latest version.

Show it in your own README:

[![Checked with pyrigor](https://img.shields.io/badge/checked%20with-pyrigor-blue)](https://github.com/jarl-hoyem/pyrigor)

Seeing violations in your editor

The tool pyrigor writes file:line:column: message, which most editors parse without needing a plugin. Configuring your existing tools beats installing another one.

In PyCharm, add a File Watcher under Settings, Tools, File Watchers:

Setting Value
File type Python
Scope Project Files
Program $ProjectFileDir$/.venv/Scripts/pyrigor.exe
Arguments $FilePath$
Working directory $ProjectFileDir$
Show console Never
Output filters $FILE_PATH$:$LINE$:$COLUMN$: $MESSAGE$

On macOS and Linux the program path is $ProjectFileDir$/.venv/bin/pyrigor.

Two settings are not straightforward. The Show console: Never matters because pyrigor exits 1 whenever it finds anything, so any other value opens a console on every save. And Output filters is not a plain text field, it needs the browse button next to it, otherwise the value is silently discarded.

Violations then appear in the Problems view, clickable, as you save.

Other editors read the same lines. In Vim or Neovim, makeprg=pyrigor\ % with errorformat=%f:%l:%c:\ %m fills the quickfix list from :make. In Emacs, M-x compile running pyrigor . needs no configuration at all, because compilation mode already recognises this format. In Visual Studio Code, a task in .vscode/tasks.json whose problemMatcher pattern is ^(.+):(\d+):(\d+): (.+)$ fills the Problems panel, and that file is normally committed, so it reaches everyone on the project. Sublime Text takes the same expression as a build system's file_regex.

The text line is the lowest common denominator. Where an editor can consume structured output, --output-format=json carries more: a severity per violation, the end line and column, the symbolic name, and whether a safe fix exists. An integration built on that can show ranges and colour them by severity, which the plain line cannot express.

What this is

Python's failure modes are often silent: implicit type coercion, positional-argument swaps between same-typed parameters, mutable default arguments, float equality checks, and tuple-unpacking that "type-checks" while being semantically wrong are all real, tool-catchable classes of bugs that slip past mypy, pylint, and ruff's default rule sets.

pyrigor is a set of guidelines, with real, working tooling enforcing them today, growing as more rules are built out.

Status

Early stage.

See guidelines/RULES.md for the full, generated list of every rule and whether it is enforced yet.

  • Guideline documentation
  • Standalone AST-based checkers (pre-commit local hooks)
  • Editor integration (deferred until real demand exists, see #152)

Guidelines

See guidelines/ for the full list. Each guideline has a rule ID, rationale, example, and — once implemented — a link to its enforcing check.

guidelines/RULES.md has a generated table of every rule and whether it is enforced yet — generated from the real guideline docs and CHECKERS, never hand-maintained, so it cannot drift the way this table once did.

Philosophy

Prefer explicit over implicit. Make illegal states unrepresentable. Do not rely on convention or code review where a tool can enforce correctness instead.

The tool pyrigor is prescriptive by design: each guideline does not just flag a risky pattern, it commits to one specific, verified fix. This is a deliberate choice, not an oversight — a codebase where every developer independently improvises their own fix for the same problem is exactly the inconsistency pyrigor exists to close.

Contributing

Participation is governed by the Code of Conduct.

  1. Every change starts with an issue. Check open issues labeled ready for a well-scoped starting point, or open a new one.
  2. Adding a new rule? Follow guidelines/ADDING_A_RULE.md step by step.
  3. Run just check before pushing.
  4. Open a Pull Request.

See CONTRIBUTING.md for full setup and workflow details.

Feedback

Evaluating pyrigor for your own project? Open an issue and tell the team about your use case — the maintainers want to use real adoption signals to drive priorities.

Acknowledgements

The tool pyrigor's own rules draw directly on real, external sources, not invented in isolation: Steve McConnell's Code Complete, the OSSF Secure Coding Guide for Python, and Google's Python Style Guide. Built on the shoulders of the real, open source tooling, it runs alongside every day: ruff, pylint, mypy, pyright, and pytest, among others credited throughout this project's own guideline docs.

Contact

Created and maintained by jarl-hoyem. For questions or ideas, open an issue.

License

MIT

Metadata

Release files for pyrigor 0.13.1

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

Source distribution (sdist)

Source distribution for pyrigor 0.13.1
File Size Uploaded
pyrigor-0.13.1.tar.gz 72.2 kB Details

Built distribution (wheel)

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

Total release size: 113.3 kB

Release files / pyrigor-0.13.1.tar.gz

Download URL pyrigor-0.13.1.tar.gz
Size 72.2 kB
Tags Source
SHA-256 checksum
How to use checksums
29680e1457aa86399b8cd2ae530401c04e10dcf8c8e24cbc10a7b3508ee0e212
BLAKE2b-256 checksum
How to use checksums
304d8af04ab51e0aca9046b0f532c7614c10c1077c926133a54492a7e375a074
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 18, 2026.

Transparency log

Release files / pyrigor-0.13.1-py3-none-any.whl

Download URL pyrigor-0.13.1-py3-none-any.whl
Size 41.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d2fc0d5626ed3ef8b41dc6b57ec8d3a853dafff9eb1e4e179417f66aa9e90f2
BLAKE2b-256 checksum
How to use checksums
0dfa843c841093f83d0caaf73e6ce31535525f5117c4a86bb8ed4e21208c9e7c
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 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.13.1 This release

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.4

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.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.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