heki
🧱 heki (壁, "wall") is a static checker for Python, written in Rust. It tracks side effects and mutations across function calls.
It catches blocking I/O in async code, database queries and HTTP clients in loops, and
quadratic loops. You can also add rules in pyproject.toml to restrict which functions may
mutate state or reach I/O.
By default, heki shows only exact reports: reports of a certified rule, built only from facts
heki established. To certify a rule, two reviewers check by hand every exact report it makes on
the development corpus (378 packages and 30.75 million lines, plus packages added for rules with
few reports), and one run on a frozen holdout of 100 packages is checked too. Neither may hold a
false claim. EFF101 and EFF103, the rules of the two examples below, had 287 and 103 reports
on the corpus and 152 and 122 on the holdout, none false.
Rule precision lists every certified rule.
Heuristic reports can be wrong about the code. They are opt-in (heki check --heuristic), and
every output labels them.
📚 Documentation · 🚀 Getting started · 📏 Rules
⚡ Try it in your project's root, without installing: uvx heki check
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) [warning] `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`
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).
note: 4 heuristic rule(s) are off; enable them with `--heuristic` or `lint.heuristic = true`
Ruff, ty, Pyrefly, pyright, and mypy report nothing for either example with their default settings.
What a first run shows
Run uvx heki check (or heki check once installed) in the directory with pyproject.toml:
- An error reports a bug: a wrong result, an exception, a lost update, a deadlock, or a broken contract. A warning reports slower code, like the two above, or a bug that is rarely harmful.
- Warnings are printed and do not fail the run (exit code 0). Errors fail it (exit code 1).
--fail-on warning(lint.fail-on = "warning") makes warnings fail it too. - A note at the end says how many heuristic rules were left off;
--heuristicruns them.
Your own conventions, too
The checks above need no configuration: EFF101 and EFF103 are exact and run by default.
The rules of your own project, which you keep today by review, by AST scripts, or by run-time
guards in tests, can be added as a few lines of it:
[[tool.heki.write-owners]]
name = "order-store"
targets = ["app.models.Order.items"]
allowed-writers = ["app.store.*"]
heki follows aliases, helpers, and subclasses, with no decorators and nothing running at run
time. The other contracts are read-owners, call-owners, readonly-returns, invalidation,
and effect-boundaries.
✨ Why heki?
Types say what values are; heki checks what code does:
- Aliases and in-place changes: which objects a function changes, through any alias, helper, or subclass.
- Contracts: who may write, read, or call what, and which code may reach I/O.
- Proven rewrites: quadratic patterns are rewritten only when the rewrite is proven, not guessed.
What code does, not what types it has
These rules are exact and 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 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 DataFrame or array concatenated with itself on every loop iteration | DATA101 |
| A quadratic list, dict, set, bytes, or queue pattern | OPT101-OPT103, OPT110, OPT111, OPT113, OPT120, OPT121, OPT130 |
The other rules are heuristic or opt-in, and the contract rules run once you declare a contract: see Rules and Rule precision.
A safety net for reviews and coding agents
- The language server checks while you edit and re-checks only what an edit can affect.
heki snapshotrecords what each public function does, andMUT103reports a function that gained an effect, which a diff does not show.- Coding agents get the same checks as JSON.
Fast, quiet, and easy to adopt
- A 100,000-line project is checked in a few seconds.
- A report needs evidence: when heki cannot tell, it stays quiet.
- Configuration, suppression comments, and output formats follow Ruff, and a baseline fails CI only on new findings.
🔓 What Python leaves open
Rust enforces ownership, Haskell puts IO in the type, and static types let a compiler prove a
rewrite. Python enforces none of these. heki checks what they would catch: objects changed
through helpers, effects behind a call, stale shared state, and quadratic patterns. See the
comparison.
🔍 How heki differs
Ruff models syntax, type checkers model declared types, and tach and import-linter model imports.
heki models effects and aliases, what code does, so use it next to them: the second example
passes mypy --strict and pyright's strict mode, yet sends one query per order. See the
comparison.
🔧 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 that the program behaves the same:
- it trusts no type annotation (a subclass can override
__add__); - any other reference to the object blocks an in-place update;
- evaluation order and exceptions are kept;
- builtins count only while the module does not rebind them.
A collections.deque rewrite also updates the annotation and adds the import:
$ heki check --diff --include-size-dependent jobs.py
--- a/jobs.py
+++ b/jobs.py
@@ -1,11 +1,12 @@
"""Job queue."""
+import collections
import os
def drain(jobs: list[int]) -> int:
- queue: list[int] = list(jobs)
+ queue: collections.deque[int] = collections.deque(list(jobs))
total = 0
while queue:
- total += queue.pop(0)
+ total += queue.popleft()
return total
Would fix 1 issue(s) in 1 file(s).
--fix alone applies the rewrites that are faster for every input (OPT101, OPT102); a
size-dependent one like this needs --include-size-dependent.
The scope analysis is checked against CPython's symtable on 3.11 to 3.15, and adversarial
programs that break a naive rewrite must all be blocked on CPython. When a proof fails, the
report names the missing obligation instead of offering a fix.
🎯 Scope
- Its knowledge comes from its own analysis, a catalog of library behavior, contracts you
declare in
pyproject.toml, and type annotations, which only help it resolve calls: rewrites never trust them. - When it cannot tell, it stays quiet. Annotations, catalog entries, and contracts close the findings it misses.
- It does not model
__getattr__proxies, metaclasses, or framework machinery, and it never runs your code.
See Scope and limitations for the details.
📦 Installation
$ uv tool install heki # or: pipx install heki / pip install heki
$ uvx heki check # run without installing
🏃 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
🪜 pre-commit and CI
A pre-commit hook (heki follows calls across files, so it checks the whole project):
# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: heki
name: heki
entry: uvx heki check
language: system # needs uv on PATH
types: [python]
pass_filenames: false
A GitHub Actions workflow with code-scanning alerts (SARIF) and annotations:
# .github/workflows/heki.yml
name: heki
on: [push, pull_request]
permissions:
contents: read
security-events: write # for the SARIF upload
jobs:
heki:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v10
- run: uvx heki check --output-format sarif > heki.sarif || test "$?" -eq 1
- uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: heki.sarif
- run: uvx heki check --output-format github
Errors fail the hook and the last step. Warnings, such as EFF101 and EFF103 reports, do not,
unless you add --fail-on warning or set fail-on = "warning" in [tool.heki.lint]. The SARIF
step keeps findings as alerts and fails only on a configuration, read, or syntax error. See
Adopting heki for a hook without uv and a Ratchet baseline.
📚 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 40 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.2.1
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.2.1.tar.gz | 1.7 MB | With provenance | Details for heki-0.2.1.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| heki-0.2.1-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for heki-0.2.1-py3-none-win_amd64.whl |
| heki-0.2.1-py3-none-musllinux_1_2_x86_64.whl | Python 3 | none | Linux musl 1.2+ x86-64 | Details for heki-0.2.1-py3-none-musllinux_1_2_x86_64.whl |
| heki-0.2.1-py3-none-manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.28+ x86-64 | Details for heki-0.2.1-py3-none-manylinux_2_28_x86_64.whl |
| heki-0.2.1-py3-none-manylinux_2_28_aarch64.whl | Python 3 | none | Linux glibc 2.28+ ARM64 | Details for heki-0.2.1-py3-none-manylinux_2_28_aarch64.whl |
| heki-0.2.1-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for heki-0.2.1-py3-none-macosx_11_0_arm64.whl |
| heki-0.2.1-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details for heki-0.2.1-py3-none-macosx_10_12_x86_64.whl |
Total release size: 48.4 MB
Release files / heki-0.2.1.tar.gz
| Download URL | heki-0.2.1.tar.gz |
|---|---|
| Size | 1.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b721660a85b596fa7960517ee6b42716832927d9d748337d53a82a39aa07d82
|
|
BLAKE2b-256 checksum How to use checksums |
4feddde045d5730740a0bc2a82003c9fd994a134f4a13dcba78bf8aa8430a9db
|
| 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 21, 2026.
Transparency logRelease files / heki-0.2.1-py3-none-win_amd64.whl
| Download URL | heki-0.2.1-py3-none-win_amd64.whl |
|---|---|
| Size | 7.3 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
3caf34b79ba9374bb4981b9c0a1747cdf0af27700ab7fb0c8bb5e43e1af4e247
|
|
BLAKE2b-256 checksum How to use checksums |
92b66b6eccbcd837ee7961453979bfde0570748832cc5fd0195d078ffb973df7
|
| 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 21, 2026.
Transparency logRelease files / heki-0.2.1-py3-none-musllinux_1_2_x86_64.whl
| Download URL | heki-0.2.1-py3-none-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 8.3 MB |
| Tags | Linux musl 1.2+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
8a3828ed23f46d3737340fc7965cd683f373ddaa309be5cd4c9b205bfc48bbff
|
|
BLAKE2b-256 checksum How to use checksums |
30637ae1ae851eee5ff05150b372572d7c2b76734c56dcc1061992a06d0225de
|
| 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 21, 2026.
Transparency logRelease files / heki-0.2.1-py3-none-manylinux_2_28_x86_64.whl
| Download URL | heki-0.2.1-py3-none-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 8.0 MB |
| Tags | Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
59bd72b531c0398b9998ab248d523633db4e165213b5617400bd9c2deb3b37e6
|
|
BLAKE2b-256 checksum How to use checksums |
497b5178176bfe7ed7cb551cdb845d2c1a84579e78d4c7d3ec7c2a85e5fd7afa
|
| 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 21, 2026.
Transparency logRelease files / heki-0.2.1-py3-none-manylinux_2_28_aarch64.whl
| Download URL | heki-0.2.1-py3-none-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 7.8 MB |
| Tags | Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
0ac470e45f791ebde881e21bcbfa47438eb5ef7f690215e47175699d8ea53a17
|
|
BLAKE2b-256 checksum How to use checksums |
37fab50405342ca4814749041136a7c231530a13c63a2e342678d7ac3e88f545
|
| 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 21, 2026.
Transparency logRelease files / heki-0.2.1-py3-none-macosx_11_0_arm64.whl
| Download URL | heki-0.2.1-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 7.4 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a79afb69cc96f16dd67f88be77f59397a3c518f10ef9b073effaeff7d16030c8
|
|
BLAKE2b-256 checksum How to use checksums |
0c8cc45224cad4ec68f4fbaa2f2d5211ddd77c5bc8512d43e9b9c8f2818a713f
|
| 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 21, 2026.
Transparency logRelease files / heki-0.2.1-py3-none-macosx_10_12_x86_64.whl
| Download URL | heki-0.2.1-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 7.8 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
ffa998b7c1453052ebd8cd94736b1bca49fa9b192023bade7ee651d7a0374f07
|
|
BLAKE2b-256 checksum How to use checksums |
0574db4db24af9eae70a5b345a12fa48d2a9399cb72fce1e97ccb903e1a5c7b3
|
| 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 21, 2026.
Transparency logSecurity for heki 0.2.1
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.2.1.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 21, 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.