heki
🧱 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.
📚 Documentation · 🚀 Getting started · 📏 Rules · 📜 Contracts
⚡ 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, or one keeping a memo dict it fills itself, 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.setup rebinds or patches app.api.run or sys.stdin |
write-owners |
targets = ["app.api:run", "sys.stdin"], allowed-writers = ["app.setup.*"] |
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.*"] |
Tests read the expected outputs under tests/data/expected only through the helper that stores them |
path-boundaries (experimental) |
roots = ["tests/data/expected"], scopes = ["tests.*"], forbid = ["read", "copy", "list"], sanitizers = ["tests.conftest.stored_expected"] |
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 anAGENTS.mdsection in one run.- List
heki.tomlandheki-baseline.tomlinCODEOWNERS: moving a wall takes a review. - With
allowance-reasons = "required", every exception in anallowed-*list comes from a group that says why (Reasons for allowances). - With
baseline-exact = true, a baseline entry that can shrink fails the run, so a fixed finding cannot come back unnoticed (Exact baselines). - With
baseline-reasons = "required", every baseline entry is in a group that says why it is still there (Reasons for entries). - With
unused-allowances = "error", an exception in an owner,import-boundaries,invalidation, oreffect-boundariescontract that no longer allows any access fails the run, so it cannot hide a later break (Unused allowances). - Run
heki check --report-suppressed <PATH>in CI: it lists every inline# heki: ignoreand# noqathat silences a report, and every report a contract'sexempt-decoratorshid, so a change that goes around a wall shows in review (details). - A contract's
messagestarts 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 thatgit applytakes, annotations only.--output-format jsongives 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
-
In your project's root (the directory with
pyproject.toml), runuvx heki check. An exact error, likeMUT114above, fails the run (exit code 1). Warnings are printed but don't fail it unless you pass--fail-on warning. -
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.storewritesOrder.items, so heki proposes that wall with the keys to add. Getting started shows more of the report. -
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.13.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.13.0
hooks:
- id: heki
# A step of a GitHub Actions job that has uv
- run: uvx heki==0.13.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
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.
- 🚀 Getting started - run heki on a project, read a diagnostic, apply a fix
- ⚙️ Configuration & Contracts - rule selection, contracts, the Python version
- 📏 Rules - every rule, with its tier
- 📐 Rule precision - exact and heuristic rules, and how they are measured
- 🔧 Fixes and safety - how rewrites are proven safe
- 🪜 Adopting heki - Ratchet baselines, pre-commit, CI
- 🖥️ Editors (LSP) - VS Code, Neovim, and any LSP client
- 🤖 Coding agents - JSON output and agent setup
- ⌨️ CLI reference - every command and option
- 🛠️ Development - building, testing, and the gates
- 📝 Changelog
📛 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
Metadata
Release files for heki 0.13.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| heki-0.13.0.tar.gz | 4.6 MB | With provenance | Details for heki-0.13.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| heki-0.13.0-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for heki-0.13.0-py3-none-win_amd64.whl |
| heki-0.13.0-py3-none-musllinux_1_2_x86_64.whl | Python 3 | none | Linux musl 1.2+ x86-64 | Details for heki-0.13.0-py3-none-musllinux_1_2_x86_64.whl |
| heki-0.13.0-py3-none-manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.28+ x86-64 | Details for heki-0.13.0-py3-none-manylinux_2_28_x86_64.whl |
| heki-0.13.0-py3-none-manylinux_2_28_aarch64.whl | Python 3 | none | Linux glibc 2.28+ ARM64 | Details for heki-0.13.0-py3-none-manylinux_2_28_aarch64.whl |
| heki-0.13.0-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for heki-0.13.0-py3-none-macosx_11_0_arm64.whl |
| heki-0.13.0-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details for heki-0.13.0-py3-none-macosx_10_12_x86_64.whl |
Total release size: 96.3 MB
Release files / heki-0.13.0.tar.gz
| Download URL | heki-0.13.0.tar.gz |
|---|---|
| Size | 4.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bcec126c87f4796ee7373bf885687fdd6a803cc063d7cecc2e4a7e95a1b734ac
|
|
BLAKE2b-256 checksum How to use checksums |
a4abea16b5a2db57d6d5fb28c20fed27e56130746dcad620587de3223b010431
|
| 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 logRelease files / heki-0.13.0-py3-none-win_amd64.whl
| Download URL | heki-0.13.0-py3-none-win_amd64.whl |
|---|---|
| Size | 14.5 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6f9c705a5d6b5c38c855c5c7d6b611a028a5d53e1e5d07494f8501ef2b0ec253
|
|
BLAKE2b-256 checksum How to use checksums |
64b54f0f7ff30d01cc6cb7042aba5edcf2f3d215a4e72bd72eb9cd8c919fae55
|
| 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 logRelease files / heki-0.13.0-py3-none-musllinux_1_2_x86_64.whl
| Download URL | heki-0.13.0-py3-none-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 16.3 MB |
| Tags | Linux musl 1.2+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
45d654209bf2d28db85117c15c7a3df62156bec1f96de49da3ebc4016194fbf0
|
|
BLAKE2b-256 checksum How to use checksums |
eeebf98e54fb36b3944cec10b108d0f12b002a5ceadcbb2f3fcae5b0f376fd14
|
| 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 logRelease files / heki-0.13.0-py3-none-manylinux_2_28_x86_64.whl
| Download URL | heki-0.13.0-py3-none-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 15.7 MB |
| Tags | Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
468c7487f0b1f4e36580b82f59551b92f754b1ab4092e1f0b21571ea0480ec61
|
|
BLAKE2b-256 checksum How to use checksums |
c406e2d23ab6a31728b483640e69bd2321dd59d69c4d424b44986c1c4c9a0d0a
|
| 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 logRelease files / heki-0.13.0-py3-none-manylinux_2_28_aarch64.whl
| Download URL | heki-0.13.0-py3-none-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 15.3 MB |
| Tags | Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
f094a85f6f298bed60bb2488ea960bfef2dd1da34b8033c784edf50905f7730f
|
|
BLAKE2b-256 checksum How to use checksums |
8c42c2e8294a2aeb98fee73cd3a1f88523ebe0e6d26b995135c224f15049b014
|
| 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 logRelease files / heki-0.13.0-py3-none-macosx_11_0_arm64.whl
| Download URL | heki-0.13.0-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 14.6 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
bd976c7398ec5e3f4a3d446f9be07e7ce868c655028f919f6bdc7edd012ab6d9
|
|
BLAKE2b-256 checksum How to use checksums |
9a5efd58faf2d8a458f653543812b61bfce05ce01817df1ee4c776e979de6362
|
| 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 logRelease files / heki-0.13.0-py3-none-macosx_10_12_x86_64.whl
| Download URL | heki-0.13.0-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 15.3 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
d8246b5a61fc1d8effafea9ebb710ca01d77168fdb1609e8e07cd8a3112a1162
|
|
BLAKE2b-256 checksum How to use checksums |
823d2c885c80192f7a5aeec06790a5b9b26b8e722cb5a809ab4a5396f6914749
|
| 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 logSecurity for heki 0.13.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.
Attestation for heki-0.13.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 logA 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.