Skip to main content

heki

heki: a snake in front of a brick wall

🧱 heki (壁, Japanese for "wall") checks the semantics of Python code. It does not replace Ruff or your type checker (mypy, Pyright, Pyrefly, or ty): it is a third layer that runs next to them. Ruff checks syntax and style, and the type checkers check declared types. heki follows aliases, helpers, and file boundaries to find which function a call really runs, which state it changes, and which effects it has. It is written in Rust and checks a 100,000-line project in a few seconds.

This stops a pull request that passes the syntax checks and strict type checking but changes what the code does. With no configuration, heki check reports a shared cache changed in place, a read-only argument changed by a helper, a database query in a loop, a lock taken again while it is held, and a blocking call in async code. The same run enforces the rules only your project knows: who owns a piece of state, which change must invalidate a cache, and where I/O may happen.

You write those rules as contracts. A contract uses the results of the same analysis to decide, in every pull request, whether a change, a call, or an I/O is allowed. The async checks are one use of that analysis among the others.

heki check in a terminal: MUT114 reports, with no configuration, a dict that an lru_cache function returned and another file changes in place, and MUT201 a write to Order.items through a helper outside the functions a contract allows, with its call chain

📚 Documentation · 🚀 Getting started · 📏 Rules · 📜 Contracts

PyPI Python versions CI License: MIT

⚡ Try it in your project's root, without installing: uvx heki check. Then follow Try it in 5 minutes.


A bug found with no configuration

Each file looks fine on its own, and the types are right: the bug is in what the cache shares.

# app/config.py
from functools import lru_cache


@lru_cache(maxsize=64)
def base_headers(region: str) -> dict[str, str]:
    return {"Accept": "application/json", "X-Region": region}
# app/api.py
from app.config import base_headers


def request_headers(region: str, token: str) -> dict[str, str]:
    headers = base_headers(region)
    headers["Authorization"] = f"Bearer {token}"
    return headers

lru_cache hands the same dict to every call with the same region. request_headers writes a token into it, so a later caller of base_headers for that region sends the token of whoever called request_headers last.

A wall your project writes

Only the functions in app.store may change Order.items. Write that down once:

# heki.toml
[[write-owners]]
name = "order-store"
targets = ["app.models.Order.items"]
allowed-writers = ["app.store.*"]
message = "change Order.items through app.store"
fail = true   # a report of this contract fails the run
# app/models.py
class Order:
    def __init__(self) -> None:
        self.items: list[str] = []
# app/store.py
from app.models import Order


def add_item(order: Order, item: str) -> None:
    order.items.append(item)

app/checkout.py changes the list through a helper in another file:

# app/util.py
def append_to(items: list[str], item: str) -> None:
    items.append(item)
# app/checkout.py
from app.models import Order
from app.util import append_to


def add_gift_wrap(order: Order) -> None:
    append_to(order.items, "gift-wrap")

tach and import-linter stop at the import layers, and every import here is allowed; heki follows the write through the helper, as it follows any change, call, or I/O across helpers and aliases.

The image at the top is heki check on these examples: MUT114 with no configuration, and MUT201 from the contract. The same code passes Ruff, and mypy, Pyright, Pyrefly, and ty in strict mode (mypy --strict, Pyright's strict, Pyrefly's strict preset, every ty rule as an error). Ruff with every rule on asks only for docstrings, copyright lines, and an __init__.py.

Works alongside Ruff, your type checker, and import-linter

heki does not replace these tools: run it next to them. Each one models one layer of the code, and heki checks what the code does across files.

Tool Models heki adds
Ruff syntax and style the behavior behind a call, across files: the state it changes, a shared cache changed in place, a database query in a loop, a lock taken again while it is held, I/O where it should not happen, a blocking call in async code
mypy, Pyright, Pyrefly, ty declared types in-place changes, through aliases and helpers, to frozen, ReadOnly, and Final fields and to Sequence / Mapping / AbstractSet arguments
tach, import-linter the import layers: which modules may import which which functions write or read a field, call a function, or reach I/O, and which changes must invalidate a cache, through helpers and aliases; import rules that know when each import runs (experimental); planned: reading these tools' contracts as heki contracts

Its configuration, suppression comments, and output formats follow Ruff's. Design Philosophy says why heki works this way and compares its checks with what Rust and Haskell enforce.

🧭 What heki can do

✅ Bug checks with no configuration

These rules run by default, and each report shows the chain of calls that leads to it. Every report they made on 378 packages (about 30.75 million lines) and on a frozen holdout of 100 more was checked by hand, with no false claim (Rule precision).

What goes wrong Rule
A list, dict, or set that an lru_cache / cache function returned, changed in place MUT114
A Sequence / Mapping / AbstractSet argument changed in place by a helper MUT110
A change of a builtin container that is lost because the object is new and nothing holds it (list(xs).sort()) MUT119
A database statement on every iteration of a loop over data EFF103
A new HTTP, database, or RPC client (or a request without a session) on every iteration of a loop over data EFF102
A lock that is not reentrant, taken again while it is held, so the thread or task waits for itself EFF109
A call of a generator function whose generator nothing iterates, so its body never runs EFF116
A blocking call that a call in an async def always runs, several helpers below EFF101
A DataFrame or array concatenated with itself on every loop iteration DATA101
A list rebuilt, or a dict or set merged, on every loop iteration, and a nested-loop join OPT101, OPT102, OPT113

The size-dependent rewrites (OPT103, OPT110, OPT111, OPT120, OPT121, OPT130) are exact too, but opt-in. The other rules are heuristic or opt-in (Rules).

A call on the result of a builtin or standard-library call is followed too (text.strip().lower(), shlex.split(line)[0].upper()), with result types from typeshed's stubs: heki infers a method's or function's result, a library attribute, an enumeration member and its value, and a match class pattern's subject. It stays unresolved where overloads join to no single type (d.get(key).upper()), for module variables, and for packages outside the standard library (How a call is resolved).

heki check --fix applies an OPT rewrite only when it proves, under CPython's semantics, that the program behaves the same (Fixes and safety). More by problem: async and execution effects, state ownership and mutation, and imports and module boundaries.

📜 Walls you write: contracts and coding agents

Write the rules your project keeps by review today as contract tables in heki.toml or under [tool.heki]. heki follows aliases, helpers, and subclasses, with nothing added at run time. Contract reports are heuristic, so they are warnings until the table sets fail = true.

What you want to keep Contract Main keys
Only app.store changes Order.items write-owners targets = ["Order.items"], allowed-writers = ["app.store.*"]
Only app.billing reads Order.card_token read-owners targets = ["Order.card_token"], allowed-readers = ["app.billing.*"]
Only app.admin calls app.db.reset call-owners targets = ["app.db.reset"], allowed-callers = ["app.admin.*"]
No caller changes the settings load_settings returns to everyone readonly-returns producers = ["app.config.load_settings"], deep = true
Every change of Order.items is followed by order_changed() invalidation targets = ["Order.items"], invalidators = ["app.cache.order_changed"]
Code in app.render makes no blocking call effect-boundaries scopes = ["app.render.*"], forbid = ["blocking"]
Code in app.render reads no Config attribute except the ones listed effect-boundaries scopes = ["app.render.*"], read-universe = ["Config.*"], allow-reads = ["Config.debug"]
app.domain imports nothing from app.web, even lazily or inside a function import-boundaries (experimental) importers = ["app.domain.*"], forbidden-imports = ["app.web", "app.web.*"]

See Contracts for every key. A coding agent can miss a rule written in its instructions, but not a contract that heki check enforces:

  • heki init (experimental) writes the configuration, a Ratchet baseline of today's reports, and the Agent Skill and an AGENTS.md section in one run.
  • List heki.toml and heki-baseline.toml in CODEOWNERS: moving a wall takes a review.
  • Run heki check --report-suppressed <PATH> in CI: it lists every inline # heki: ignore and # noqa that silences a report, so a change that goes around a wall shows in review (details).
  • A contract's message starts the help line of its reports, so the agent reads it as the fix.
  • A Stop hook sends a failing check back before the agent ends its turn.
  • heki inspect (experimental) shows what one function reaches, changes, and returns.
  • heki recommend --focus types --diff (experimental) prints the exact type suggestions as one patch that git apply takes, annotations only.
  • --output-format json gives every check as JSON, and the Agent Skill (experimental) teaches the routine after an edit. Coding agents has the whole setup.

🚀 Try it in 5 minutes

  1. In your project's root (the directory with pyproject.toml), run uvx heki check. An exact error, like MUT114 above, fails the run (exit code 1). Warnings are printed but don't fail it unless you pass --fail-on warning.

  2. Ask what fits the project with heki recommend (experimental). It writes no file and helps most when the first step finds nothing, as on heki's sample service:

    $ uvx heki check
    All checks passed (4 file(s)).
    ...
    $ uvx heki recommend
    ...
    Contract candidates
      write-owners  app.models:Order.*  high
        written by 1 function(s), all in app.store (add_item), changed in place; read in 2 other module(s)
    

    Only app.store writes Order.items, so heki proposes that wall with the keys to add. Getting started shows more of the report.

  3. Keep it running with the pre-commit hook and a CI step, and record today's findings in a Ratchet baseline so only new ones fail: uvx heki==0.12.0 check --baseline heki-baseline.toml --update-baseline. The starter recipes have these setups ready to copy.

📦 Installation

$ uv tool install heki      # or: pipx install heki / pip install heki
$ uvx heki check            # run without installing

heki ships prebuilt wheels on PyPI for Linux (x86-64, AArch64, x86-64 musl), macOS (Apple silicon, Intel), and Windows (x86-64). uvx heki, pip install heki, and the pre-commit hook need no Rust toolchain and compile nothing. Building from source is for other platforms and for development: see Installation.

⌨️ Usage

$ heki check                                    # check the project
$ heki check --heuristic                        # also run the heuristic rules
$ heki check --diff                             # preview proven-safe fixes
$ heki check --fix                              # apply them
$ heki check --baseline heki-baseline.toml      # fail only on new findings
$ heki rule MUT114                              # explain a rule
$ heki server                                   # LSP server for editors
$ heki inspect app.api.request_headers          # what one function does (experimental)
$ heki recommend                                # configuration advice (experimental)

🪜 pre-commit and CI

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/koxudaxi/heki-pre-commit
    rev: v0.12.0
    hooks:
      - id: heki
# A step of a GitHub Actions job that has uv
- run: uvx heki==0.12.0 check

The hook runs heki check --touched on the staged files, so old findings in other files don't block a commit. It still fails on a report in an unstaged file whose call chain passes through a staged file, and, with a baseline, on every regression. Run the whole project in CI. In GitHub Actions, the reports show up as annotations. Adopting heki has the SARIF run for code-scanning alerts, a local hook, and how to check only the files a pull request changes.

🛡️ Stability

On the way to 1.0, heki keeps these stable: the exit codes 0, 1, and 2, the exact rules that run by default, the format of the Ratchet baseline, the contract tables write-owners, read-owners, call-owners, readonly-returns, invalidation, and effect-boundaries with fail = true and [lint] fail = [...], and the json, sarif, and github output formats. A change to one of them is listed under "Breaking changes" in the release notes. The experimental features can change in any release: heki recommend, heki inspect, heki skill, --generate-prompt, and the rules marked experimental (the list).

📚 Documentation

👉 heki.koxudaxi.dev

When heki isn't sure, it doesn't report. Scope and limitations says what it checks, where its knowledge comes from, and what it leaves to other tools.

📛 Name

heki is 壁, "wall", in its Sino-Japanese (on) reading, the one used in compounds such as 防火壁 (bōkaheki, "firewall"). On its own the character is usually read kabe.

📄 License

MIT

Metadata

Release files for heki 0.12.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 heki 0.12.0
File Size Uploaded Provenance Actions
heki-0.12.0.tar.gz 4.2 MB With provenance Details for heki-0.12.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for heki 0.12.0
File Actions
heki-0.12.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for heki-0.12.0-py3-none-win_amd64.whl
heki-0.12.0-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details for heki-0.12.0-py3-none-musllinux_1_2_x86_64.whl
heki-0.12.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for heki-0.12.0-py3-none-manylinux_2_28_x86_64.whl
heki-0.12.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for heki-0.12.0-py3-none-manylinux_2_28_aarch64.whl
heki-0.12.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for heki-0.12.0-py3-none-macosx_11_0_arm64.whl
heki-0.12.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for heki-0.12.0-py3-none-macosx_10_12_x86_64.whl

Total release size: 89.6 MB

Release files / heki-0.12.0.tar.gz

Download URL heki-0.12.0.tar.gz
Size 4.2 MB
Tags Source
SHA-256 checksum
How to use checksums
a67dd6ce45a3808c8b05bc038ddd16649bc60e083810e12503afdd4b032377ea
BLAKE2b-256 checksum
How to use checksums
160cc2a6d82dc41f80e1ac92be0e6e342b06fb2dcdc689385c1d551fbe330a95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / heki-0.12.0-py3-none-win_amd64.whl

Download URL heki-0.12.0-py3-none-win_amd64.whl
Size 13.5 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
42c94bc845001efca6b96780961e13ebaf187a9b0084f57eff9843f8ea6e2c39
BLAKE2b-256 checksum
How to use checksums
6e0379a9aaf0a4e483735c5d7292000e9be56f0eddc91a37b5321527bcd6fc56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / heki-0.12.0-py3-none-musllinux_1_2_x86_64.whl

Download URL heki-0.12.0-py3-none-musllinux_1_2_x86_64.whl
Size 15.2 MB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
ec64efb8738fc1154ae93538b933558922513c4d8892c2c9651a0565a30d37a5
BLAKE2b-256 checksum
How to use checksums
73c92dab4e1865ae1da04ac132ccf9a5d05a03dbd7738673f97b24195a72bac9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / heki-0.12.0-py3-none-manylinux_2_28_x86_64.whl

Download URL heki-0.12.0-py3-none-manylinux_2_28_x86_64.whl
Size 14.6 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
1d3acf7c954b277737ed4b29d7c8d99417a7ed4107f6537b000f85fe6daaf60b
BLAKE2b-256 checksum
How to use checksums
b4449a29eb9b141c4cb5c6d916745f9a1c0b43bea7975abe8e8e9ce4a0054911
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / heki-0.12.0-py3-none-manylinux_2_28_aarch64.whl

Download URL heki-0.12.0-py3-none-manylinux_2_28_aarch64.whl
Size 14.2 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
2938998ee0f3f6b31b6ab3cfd85caf352f361ae5847e658ecb00edf499de1c17
BLAKE2b-256 checksum
How to use checksums
58bca7b7c0a2dae907484e5a76dffce31c77233b321331baeb7afd57f739823e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / heki-0.12.0-py3-none-macosx_11_0_arm64.whl

Download URL heki-0.12.0-py3-none-macosx_11_0_arm64.whl
Size 13.5 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4dabaac448f9e2161dd4eb5fb887e3f9408f4a9187fd0a4f7236b9e07cf10cd9
BLAKE2b-256 checksum
How to use checksums
d382bcf812f74fc63605eb31feca653eb97b6e9177e98bb5110588f999147f42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / heki-0.12.0-py3-none-macosx_10_12_x86_64.whl

Download URL heki-0.12.0-py3-none-macosx_10_12_x86_64.whl
Size 14.3 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
51e88c66ec01dbd17313778a5934b12b0b7c600cf45dfbed625008d88a026a76
BLAKE2b-256 checksum
How to use checksums
7483b33615ec917ec7278a0dc04b5e209624b2d05bc868baa5fe205571ca79e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Security for heki 0.12.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

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for heki-0.12.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 Nov 29, 2026.

Transparency log

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