Skip to main content

heki

heki: a snake in front of a brick wall

🧱 heki (壁, Japanese for "wall") is a static checker for Python, written in Rust. It tracks side effects and mutations across function calls.

By default, 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 add rules in pyproject.toml to restrict which functions may mutate state or reach I/O.

heki check in a terminal: EFF101 reports a blocking call two helpers below an async def, and EFF103 a database query one helper below a loop, each with its call chain

These reports are exact: built only from facts heki established, by rules whose every report on a corpus was checked by hand (Rule precision).

📚 Documentation · 🚀 Getting started · 📏 Rules

PyPI Python versions CI License: MIT

⚡ 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) [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: 3 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).
note: 3 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.

How heki differs

The difference is the model, not reaching across files: type checkers already follow types across modules. heki models effects and aliases, what code does:

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 arguments
tach, import-linter which modules may import which which functions write or read a field, call a function, or reach I/O; which modules may import which, knowing when each import runs (experimental); planned: these tools' contracts read as heki contracts

Their stricter settings do not close the gap. The second example above is fully annotated and passes Ruff's annotation rules (ANN), mypy --strict, pyright's strict mode, and Pyrefly's strict preset, yet it sends one query per order: the types are right, and what the code does is slow. heki leaves syntax, style, and types to these tools, and keeps doing so as they grow: use it next to them.

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 that can be critical: a wrong result, an exception, a lost update, a deadlock, an event loop held up for every other task, like the first example above, or a broken contract. A warning reports slower code, like the second, or a bug that is rarely harmful.
  • An exact error fails the run (exit code 1). Warnings, and heuristic reports, which can be wrong about the code, are printed and do not fail it (exit code 0). --fail-on warning (lint.fail-on = "warning") makes them fail it too.
  • A note at the end says how many heuristic rules were left off; --heuristic runs them.
  • Next, heki recommend (experimental) says which rules would report on the project, what heki could not see, and the contracts the code already keeps, with the keys to add.

Your conventions, checked instead of reviewed

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, and which a coding agent cannot know unless a check tells it, can be added as a few lines of it.

For example, these lines say that only the functions in app.store may change Order.items:

[[tool.heki.write-owners]]
name = "order-store"
targets = ["app.models.Order.items"]
allowed-writers = ["app.store.*"]

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`

The report is heuristic: the contract rules are not certified yet, and a MUT201 report can rest on an alias or a helper's write on one path only.

heki follows aliases, helpers, and subclasses, with no decorators and nothing running at run time. Each kind of rule has its own contract:

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 importers = ["app.domain.*"], forbidden-imports = ["app.web", "app.web.*"]

See Contracts for every key.

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 snapshot records what each public function does, and MUT103 reports a function that gained an effect, which a diff does not show.
  • Coding agents get the same checks as JSON, and an Agent Skill teaches them the workflow.
  • heki inspect (experimental) says what one function does, so an agent does not read its callees to find out.

✨ 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, which code may reach I/O, and which modules may import which.
  • 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 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: the loops they report were rarely large enough to matter (Rule precision).

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 above, 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.

The other rules are heuristic or opt-in, and the contract rules run once you declare a contract: see Rules and Rule precision.

Fast, quiet, and easy to adopt

  • A 100,000-line project is checked in a few seconds.
  • heki recommend (experimental) prints advice on the project's configuration, with the keys to add to [tool.heki].
  • 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.

🔧 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 comes from an opt-in rule: --include-size-dependent runs those rules and applies their rewrites.

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
$ heki inspect app.users.load_user              # what one function does (experimental)
$ heki recommend                                # configuration advice (experimental)

See Coding agents for heki inspect and Configuration advice for heki recommend.

🪜 pre-commit and CI

A pre-commit hook. heki follows calls across files, so the hook analyzes the whole project and passes the staged files to --touched: it shows and fails on the reports in those files and the reports whose call chain reaches them, so old findings elsewhere do not block a commit. The heki-pre-commit repository installs heki from its PyPI wheel, so there is no compile and no Rust toolchain:

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/koxudaxi/heki-pre-commit
    rev: v0.2.7
    hooks:
      - id: heki

Its tags follow heki releases, so pre-commit autoupdate works. To build heki from source instead, use repo: https://github.com/koxudaxi/heki with a release rev; pre-commit then builds that release with cargo on the first run, which takes a few minutes, and installs Rust for the build when cargo is missing.

A local hook can run any version of the PyPI wheel, also without a compile:

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: heki
        name: heki
        entry: uvx heki check --touched
        language: system   # needs uv on PATH
        types: [python]
        pass_filenames: true
        require_serial: true
        verbose: true      # show warnings: they do not fail the hook

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

Exact errors, such as EFF101 reports, fail the hook and the last step. Warnings, such as EFF103 reports, and heuristic 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 that records today's errors, so that only new ones fail.

📚 Documentation

👉 heki.koxudaxi.dev

📛 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.4.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.4.0
File Size Uploaded Provenance Actions
heki-0.4.0.tar.gz 3.0 MB With provenance Details for heki-0.4.0.tar.gz

Built distributions (wheels)

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

Total release size: 70.3 MB

Release files / heki-0.4.0.tar.gz

Download URL heki-0.4.0.tar.gz
Size 3.0 MB
Tags Source
SHA-256 checksum
How to use checksums
c56527de33970cf9dfae53a6b197dc22f2e3ed797892a0adca87ad1f33a15dff
BLAKE2b-256 checksum
How to use checksums
12c83467799bff554befa2323b12bc435f093ad319b38121ef6566d50dfc3163
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 24, 2026.

Transparency log

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

Download URL heki-0.4.0-py3-none-win_amd64.whl
Size 10.6 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
168a7210c0e822e97c47d19a9e18e03ac981862f355ef376ea4f899fa2af0aed
BLAKE2b-256 checksum
How to use checksums
316cb63a1b685adf10c3246878ef8cbcfd5f06f9541ad6d70ea9cba5ac690fff
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 24, 2026.

Transparency log

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

Download URL heki-0.4.0-py3-none-musllinux_1_2_x86_64.whl
Size 12.0 MB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
daaf7fa4cd37b0c66445a3f92bf79ee8c0a63747c957b56426b9854567124589
BLAKE2b-256 checksum
How to use checksums
3eb594ad72de5fc871e36fc178f8477adb2040fca3c46df86d319ceb0140a226
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 24, 2026.

Transparency log

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

Download URL heki-0.4.0-py3-none-manylinux_2_28_x86_64.whl
Size 11.6 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
07569879d8759f97af64ba8f9dad43c9a76a620a9a51662a2713e37ba2b9c702
BLAKE2b-256 checksum
How to use checksums
ed2b3ad86d2e1e62c682d7df43edeecc586ba042fbf9f8ed31d268aa868db7f6
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 24, 2026.

Transparency log

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

Download URL heki-0.4.0-py3-none-manylinux_2_28_aarch64.whl
Size 11.2 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
f55ab87fa9590f6df4ab7862848feb66587fad5c5b6cec58ce5a58306e89af1b
BLAKE2b-256 checksum
How to use checksums
b47f60d3ddcdaad5cc5d866298d1fe7b01e244575acd09b10da67eeefb484ece
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 24, 2026.

Transparency log

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

Download URL heki-0.4.0-py3-none-macosx_11_0_arm64.whl
Size 10.7 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a44446b9c2effdda79a73b483a9a0bdab8854676a6f4b4b9a2f5bdaf5b7c942b
BLAKE2b-256 checksum
How to use checksums
d3a0776f58e8ae6bc18a5d01ac336e8028137347bf6fb2623908469764e4e546
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 24, 2026.

Transparency log

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

Download URL heki-0.4.0-py3-none-macosx_10_12_x86_64.whl
Size 11.3 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
731359d05f0196bab3e11ba0a81e0c28eaf3187726ee5922defd8cbe5cbc2b1c
BLAKE2b-256 checksum
How to use checksums
e77999b9bb0b4a85ffde2dbf888b181a8613d5b86e9b926d6f4c5cf0350f3da6
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 24, 2026.

Transparency log

Security for heki 0.4.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.4.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 24, 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