heki
🧱 heki (壁, Japanese for "wall") is a static checker for Python, written in Rust. It tracks side effects and mutations across function calls, and checks a 100,000-line project in a few seconds.
Ruff checks syntax and style, and ty, mypy, and Pyright check types. heki checks what your code does: which effects a call reaches and which state it changes, across functions and files.
Out of the box, it catches blocking calls in async code, database queries in loops, quadratic
loops, and in-place changes to read-only parameters and to lru_cache results. You can also
write your project's own rules as contracts,
such as which functions may change a field or reach I/O.
📚 Documentation · 🚀 Getting started · 📏 Rules
⚡ Try it in your project's root, without installing: uvx heki==0.9.0 check. Then follow
Try it in 5 minutes.
A blocking call two helpers below an async def
# app/users.py
import requests
def fetch_name(user_id: int) -> str:
return requests.get(f"https://api.example.com/users/{user_id}", timeout=5).text
def load_user(user_id: int) -> dict[str, str]:
return {"id": str(user_id), "name": fetch_name(user_id)}
# app/api.py
from app.users import load_user
async def get_user(user_id: int) -> dict[str, str]:
return load_user(user_id)
$ heki check
app/api.py:5:12: EFF101 (async-blocking-call) [error] `app.users.load_user` always runs the waiting call `requests.get` on the event loop (2 calls down, on every path)
|
5 | return load_user(user_id)
| ^
= related: app/api.py:5:12: `get_user` calls `app.users.load_user`
= related: app/users.py:8:41: `load_user` calls `app.users.fetch_name`
= related: app/users.py:5:12: `fetch_name` calls `requests.get`
= help: offload it with `asyncio.to_thread`, or use an async client
Found 1 diagnostic(s) in 2 file(s).
note: 4 heuristic rule(s) are off; enable them with `--heuristic` or `lint.heuristic = true`
EFF101 (async-blocking-call): `heki rule EFF101`, https://heki.koxudaxi.dev/rules/async-blocking-call/
A query one helper below a loop
# app/orders.py
import sqlite3
def customer_name(cursor: sqlite3.Cursor, customer_id: int) -> str:
cursor.execute("SELECT name FROM customers WHERE id = ?", (customer_id,))
return str(cursor.fetchone()[0])
def order_summaries(cursor: sqlite3.Cursor, orders: list[tuple[int, int]]) -> list[str]:
lines: list[str] = []
for order_id, customer_id in orders:
lines.append(f"#{order_id} {customer_name(cursor, customer_id)}")
return lines
$ heki check
app/orders.py:11:37: EFF103 (loop-db-query) [warning] every iteration over parameter `orders` sends a database statement: `sqlite3.Cursor.execute` (through `app.orders.customer_name`)
|
11 | lines.append(f"#{order_id} {customer_name(cursor, customer_id)}")
| ^
= related: app/orders.py:11:37: `order_summaries` calls `app.orders.customer_name`
= related: app/orders.py:5:5: `customer_name` calls `sqlite3.Cursor.execute`
= help: batch the queries, or load the data once before the loop
Found 1 diagnostic(s) in 1 file(s).
heki check does not fail on 1 report(s) shown now: warnings, and heuristic reports, which can be wrong about the code and count as warnings; `fail-on = "warning"` in the lint settings makes them fail it.
note: 4 heuristic rule(s) are off; enable them with `--heuristic` or `lint.heuristic = true`
EFF103 (loop-db-query): `heki rule EFF103`, https://heki.koxudaxi.dev/rules/loop-db-query/
Ruff, ty, Pyrefly, pyright, and mypy report nothing for either example with their default settings.
Strict settings don't help either: the second example is fully annotated and passes Ruff's ANN
rules, mypy --strict, pyright's strict mode, and Pyrefly's strict preset. It still sends one
query per order.
How heki differs
| Tool | Models | heki adds |
|---|---|---|
| Ruff | syntax and style | the effects behind a call: a blocking call, a query, or a write, wherever it happens |
| ty, Pyrefly, pyright, mypy | declared types | in-place changes, through aliases and helpers, to frozen, ReadOnly, and Final fields and to Sequence / Mapping / AbstractSet arguments |
| tach, import-linter | which modules may import which | which functions write or read a field, call a function, or reach I/O; import rules that know when each import runs (experimental); planned: reading these tools' contracts as heki contracts |
heki leaves syntax, style, and types to these tools, so use it next to them. Its configuration, suppression comments, and output formats follow Ruff's. What Python leaves open compares its checks with what Rust and Haskell enforce.
Installation
$ uv tool install heki # or: pipx install heki / pip install heki
$ uvx heki check # run without installing
Try it in 5 minutes
-
In your project's root (the directory with
pyproject.toml), runuvx heki==0.9.0 check. An exact error, like the first example above, fails the run (exit code 1). Warnings, like the second, 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 it helps most when the first step finds nothing, as on the sample service in heki's tests:$ uvx heki==0.9.0 check All checks passed (4 file(s)). ... hint: `heki recommend` (experimental) lists the rules and contracts that fit this project, and what heki could not see $ uvx heki==0.9.0 recommend heki recommend (experimental) on .: 4 file(s), 10 function(s) ... What heki cannot see (no report either way) calls of packages heki's catalog does not cover: 1 call(s) of 1 name(s) in 1 package(s) name calls async loops if it waits if it sends a query stripe.Charge.create 1 1 0 EFF101 1 exact - ... 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) ...
heki's catalog doesn't say what
stripe.Charge.createdoes, so heki reports nothing through it. If the call waits on the network,EFF101would report it inasync def checkout. Onlyapp.storewritesOrder.items, so the report ends with the keys that make that a contract. -
Keep it running with the pre-commit hook and a CI step. If the project has findings today, record them in a Ratchet baseline so only new ones fail:
uvx heki==0.9.0 check --baseline heki-baseline.toml --update-baseline, thenbaseline = "heki-baseline.toml"in[tool.heki]. The starter recipes have these setups ready to copy.
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 EFF101 # explain a rule
$ heki server # LSP server for editors
$ heki inspect app.users.load_user # what one function does (experimental)
$ heki recommend # configuration advice (experimental)
✅ Exact rules
These rules run by default. Each report shows the chain of calls that leads to it.
| What goes wrong | Rule |
|---|---|
A blocking call that a call in an async def always runs, several helpers below |
EFF101 |
| A database statement on every iteration of a loop over data | EFF103 |
A Sequence / Mapping / AbstractSet argument changed in place by a helper |
MUT110 |
A list, dict, or set that an lru_cache / cache function returned, changed in place |
MUT114 |
A change of a builtin container that is lost because the object is new and nothing holds it (list(xs).sort()) |
MUT119 |
| 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, because the loops they report were rarely large enough to matter.
Two reviewers check by hand every report an exact rule makes on the development corpus (378
packages and 30.75 million lines, plus packages added for rules with few reports). Every report of
one run on a frozen holdout of 100 packages is checked too. A rule is certified only when both
have zero false claims. EFF101 and EFF103 had 287 and 103 reports on the corpus and 152 and
122 on the holdout. Rule precision lists every
certified rule. The other rules are heuristic or opt-in; see
Rules.
📜 Contracts
Most projects have rules of their own, kept today by code review, AST scripts, or run-time checks
in tests. With heki you write them down as contracts, in heki.toml or under [tool.heki] in
pyproject.toml. This one says that only the functions in app.store may change Order.items:
# 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
A function in app/api.py that appends to order.items through a helper breaks it:
$ heki check
app/api.py:9:5: MUT201 (write-owner-violation) [error, heuristic] `add_gift_wrap` writes `app.models.Order.items` (through a helper) via `app.api._append` outside the write owners of `order-store`
|
9 | _append(order.items, "gift-wrap")
| ^
= related: app/api.py:9:5: `add_gift_wrap` calls `app.api._append`
= help: change Order.items through app.store
Found 1 diagnostic(s) in 3 file(s).
The run exits with code 1.
heki follows aliases, helpers, and subclasses, with no decorators and nothing added at run time.
The contract rules aren't certified yet, so
their reports are warnings. fail = true makes that table's reports fail the run. Record today's
findings in a Ratchet baseline first.
There is a contract for each kind of rule:
| 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"] |
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.
🤖 Teams and coding agents
A coding agent can miss a rule written in AGENTS.md or CLAUDE.md. Write it as a contract
instead, and heki check enforces it. List heki.toml and heki-baseline.toml in CODEOWNERS.
Then moving a wall takes a reviewed change, and an agent can't move one to make a report go away.
- The contract's
messagestarts the help line of its reports, so the agent reads it as the fix. - A Stop hook runs
heki checkwhen Claude Code is about to end its turn and sends a failing report back, so the agent keeps working until the check passes. heki inspect app.api.checkout(experimental) shows what one function reaches, changes, keeps, and returns, with the call chains, so an agent doesn't have to read its callees.--output-format jsongives agents every check as JSON, and the Agent Skill (experimental) teaches them the routine after an edit and how to adopt heki in a repository.heki snapshotwithMUT103reports a function that gained an effect, which a diff doesn't show.- The whole setup, end to end has the CI workflow that checks each pull request against these walls, the hook, and the skill.
🔧 Rewrites proven under CPython's semantics
The OPT rules find quadratic list, dict, set, bytes, and queue patterns. heki check --fix
rewrites one only when it proves the program behaves the same. It trusts no type annotation and
keeps evaluation order and exceptions. It doesn't update an object in place while anything else
refers to it, or count on a builtin the module rebinds. When a proof fails, the report names the
missing obligation instead of offering a fix.
--fix alone applies the rewrites that are faster for every input (OPT101, OPT102).
--include-size-dependent adds the size-dependent ones, such as a collections.deque for
list.pop(0) (OPT120). Fixes and safety shows each rewrite
and what it must prove.
🪜 pre-commit and CI
# .pre-commit-config.yaml
repos:
- repo: https://github.com/koxudaxi/heki-pre-commit
rev: v0.9.0
hooks:
- id: heki
# A step of a GitHub Actions job that has uv
- run: uvx heki==0.9.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.
🎯 Scope
When heki isn't sure, it doesn't report. It works from its own analysis, a catalog of library behavior, and the contracts you declare. Scope and limitations says what it checks and what it leaves to other tools.
📚 Documentation
- 🚀 Getting started - run heki on a project, read a diagnostic, apply a fix
- 🎯 Scope and limitations - what heki checks and what it leaves to other tools
- ⚙️ Configuration - rule selection, contracts, the Python version
- 📏 Rules - all 53 rules
- 📐 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.9.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.9.0.tar.gz | 3.4 MB | With provenance | Details for heki-0.9.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| heki-0.9.0-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for heki-0.9.0-py3-none-win_amd64.whl |
| heki-0.9.0-py3-none-musllinux_1_2_x86_64.whl | Python 3 | none | Linux musl 1.2+ x86-64 | Details for heki-0.9.0-py3-none-musllinux_1_2_x86_64.whl |
| heki-0.9.0-py3-none-manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.28+ x86-64 | Details for heki-0.9.0-py3-none-manylinux_2_28_x86_64.whl |
| heki-0.9.0-py3-none-manylinux_2_28_aarch64.whl | Python 3 | none | Linux glibc 2.28+ ARM64 | Details for heki-0.9.0-py3-none-manylinux_2_28_aarch64.whl |
| heki-0.9.0-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for heki-0.9.0-py3-none-macosx_11_0_arm64.whl |
| heki-0.9.0-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details for heki-0.9.0-py3-none-macosx_10_12_x86_64.whl |
Total release size: 78.3 MB
Release files / heki-0.9.0.tar.gz
| Download URL | heki-0.9.0.tar.gz |
|---|---|
| Size | 3.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a59cde9e797348875c21022a1a4f0894a258cc39203033e2a3d080b4d1dba39
|
|
BLAKE2b-256 checksum How to use checksums |
0ca9149492809e350b4a8b16dd94c068bae9407e9e23df4a6eeb44822574e024
|
| 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 26, 2026.
Transparency logRelease files / heki-0.9.0-py3-none-win_amd64.whl
| Download URL | heki-0.9.0-py3-none-win_amd64.whl |
|---|---|
| Size | 11.8 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
ff765c08f0f5cc8712d6c73cb33046f1d479a932ea95c39bb753863a3e96bd0b
|
|
BLAKE2b-256 checksum How to use checksums |
be95e7db85f24ee22209453a58382fe987f2f953421a5ec47752119d0c649477
|
| 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 26, 2026.
Transparency logRelease files / heki-0.9.0-py3-none-musllinux_1_2_x86_64.whl
| Download URL | heki-0.9.0-py3-none-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 13.4 MB |
| Tags | Linux musl 1.2+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
805458c391e8f873104c0b877e5c396f316378839f4c828aaef9f746027e7ed7
|
|
BLAKE2b-256 checksum How to use checksums |
48f46aed8457291867ab8cf21185961846df5262aebc8fb724a634d1a8dc34eb
|
| 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 26, 2026.
Transparency logRelease files / heki-0.9.0-py3-none-manylinux_2_28_x86_64.whl
| Download URL | heki-0.9.0-py3-none-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 12.8 MB |
| Tags | Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
c5f806c3bcdedbc0f7264701cb556d8339ba39dd0cc40fe47c49c510249afd1a
|
|
BLAKE2b-256 checksum How to use checksums |
56e247fb659623a90824b634a8c508dab6d22c4cb26e7900bdbd12d62cc08503
|
| 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 26, 2026.
Transparency logRelease files / heki-0.9.0-py3-none-manylinux_2_28_aarch64.whl
| Download URL | heki-0.9.0-py3-none-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 12.5 MB |
| Tags | Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
86cef46bb6fbbc0ef1edec32cf120c52d903d6585692b3536d3d1c3b9c4719c1
|
|
BLAKE2b-256 checksum How to use checksums |
1cf538eed9f701817235df1b93a9efa9f1c61ec3f96915c70f5d9aeec256a638
|
| 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 26, 2026.
Transparency logRelease files / heki-0.9.0-py3-none-macosx_11_0_arm64.whl
| Download URL | heki-0.9.0-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 11.9 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e409ffaa141f4729a65af6ed181725279febbae197c6880e57810200eb0cf1d9
|
|
BLAKE2b-256 checksum How to use checksums |
6027a771459160e0c0cdae763954ebb05ef9b3e1ba2b4d38bbf3aebcd5988065
|
| 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 26, 2026.
Transparency logRelease files / heki-0.9.0-py3-none-macosx_10_12_x86_64.whl
| Download URL | heki-0.9.0-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 12.6 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
8a87d715d6c01c00976346fa030f189a3997e5259d262767e69a4723f92bdfcb
|
|
BLAKE2b-256 checksum How to use checksums |
eafaf04848407e2cc1d9cc28dd92a105e498fba6ab521cad4793387115c78f1e
|
| 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 26, 2026.
Transparency logSecurity for heki 0.9.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.9.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 26, 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.