Skip to main content

haki

Haki is a fast, zero-runtime static analysis tool that scans your FastAPI project and tells you which endpoints have no test written for them, before you run a single line of code.

Built in Rust, exposed as a Python package.

Why

pytest --cov tells you coverage after running your entire test suite. That requires a running server, dependencies, databases, all of it.

Haki answers a simpler question earlier: did someone actually write a test function for this endpoint? It runs in milliseconds, needs no server, and is perfect as a pre-commit hook or CI lint step on every PR. Please keep in my mind that i am a student and know for sure that this may not be the best code and could've been most likely better in the eyes of alot of very good programmers, so please make a issue! Hopefully i can learn alot and improve this project.

Installation

pip install haki

Usage

As a Python package

import haki
import json

results = json.loads(haki.check_endpoints("/path/to/your/fastapi/project"))

for ep in results:
    status = "✓" if ep["has_test"] else "✗"
    print(f"{status} {ep['method']} {ep['path']} — {ep['name']}")

Output

[
  {
    "name": "get_workflow",
    "path": "/{workflow_id}",
    "method": "Get",
    "file_path": "/project/routers/workflows.py",
    "has_test": true
  },
  {
    "name": "delete_workflow",
    "path": "/{workflow_id}",
    "method": "Delete",
    "file_path": "/project/routers/workflows.py",
    "has_test": false
  }
]

In CI (fail the pipeline if any endpoint is untested)

import haki
import json
import sys

results = json.loads(haki.check_endpoints("."))
missing = [ep for ep in results if not ep["has_test"]]

if missing:
    print("Missing tests for:")
    for ep in missing:
        print(f"  ✗ {ep['method']} {ep['path']} ({ep['name']})")
    sys.exit(1)

How it works

Haki uses tree-sitter to parse your Python source files into AST trees without executing any code. It then:

  1. Scans all .py files for FastAPI route decorators (@app.get, @router.post etc.) and extracts the function name, path, and HTTP method
  2. Scans your tests/ or test/ directory for functions named test_*
  3. Matches each endpoint to a test by prefix — get_workflow is considered tested if any function named test_get_workflow* exists

Naming convention

Haki follows pytest convention. Your test functions must be named test_<endpoint_function_name>. Variants like test_get_workflow_returns_404 or test_get_workflow_unauthorised are all matched correctly.

# endpoint
@router.get("/{workflow_id}")
async def get_workflow(workflow_id: str):
    ...

# all of these count as a test for get_workflow
def test_get_workflow(): ...
def test_get_workflow_not_found(): ...
def test_get_workflow_returns_401(): ...

Requirements

  • Python 3.9+
  • FastAPI project using decorator-based routing (@app.get, @router.post etc.)
  • Tests follow test_<function_name> naming convention in a tests/ or test/ directory

Limitations

  • FastAPI only (Flask, Django not supported yet)
  • Matches by function name convention, not by which routes are actually called in tests
  • Does not replace pytest --cov — use both
  • Plugin system will be added in the future and custom naming convention

License

MIT

Metadata

Release files for haki 0.1.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 haki 0.1.0
File Size Uploaded Provenance Actions
haki-0.1.0.tar.gz 12.2 kB Without provenance Details for haki-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for haki 0.1.0
File Interpreter ABI Platform Actions
haki-0.1.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for haki-0.1.0-cp314-cp314-win_amd64.whl

Total release size: 2.0 MB

Release files / haki-0.1.0.tar.gz

Download URL haki-0.1.0.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0a35753ed9f253af6402433f2aa42f4b16f79d0a0fb582bcd8bfe08b9102ccc0
BLAKE2b-256 checksum
How to use checksums
c40d54e5a0e35b50a7a4c15f3744a231266b34e09e7f421f6c31d7e6a9162581
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / haki-0.1.0-cp314-cp314-win_amd64.whl

Download URL haki-0.1.0-cp314-cp314-win_amd64.whl
Size 2.0 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
f1330b3fbba67ea56425ba8d424499c94d988be6326aee8ed77c450a69ac9cad
BLAKE2b-256 checksum
How to use checksums
05478aa199c4bd6026f7248c19938201ecf21ff61adad5aa31da8a6d093ddc01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Security for haki 0.1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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