Skip to main content

Leesh

A leash for LLM-written Python.

Why?

Python written by LLMs sucks.

Leesh is the remedy for that. It's based on a handful of good ideas:

  • Functional Core, Imperative Shell.

  • Parse, don't validate.

  • The Zen of Python: "There should be one, and preferably only one, obvious way to do it."

  • Separate business logic from code that talks to the outside world (data you don't control).

  • Isolate side effects.

  • Build on pure functions and values.

  • Don't rely on global state.

  • Inject your dependencies; it makes testing easier.

  • Parse outside data with Pydantic, convert it to dataclasses, then run the business logic.

  • Model domain data as well-structured dataclasses.

  • Prefer functions to methods.

  • You rarely need subclassing.

  • Raise exceptions only in specific places.

  • No default arguments or default values. Be explicit: you're not the one writing the code, the LLM is.

How it works

Every file belongs to a layer, decided by its path: core, port, shell, adapter, router, boundary, transaction, test. Each layer has rules about what it may import and which effects it may perform. Imports are followed across packages, re-exports and __init__.py files, so a dependency can't be laundered through a re-export.

Install

Install Leesh from PyPI. The CLI runs a bundled Rust executable; clients do not need Cargo or a Rust toolchain.

uv tool install leesh
leesh check

Run it without installing a persistent tool:

uvx leesh check

For a project's development dependencies, use uv add --dev leesh and uv run leesh check. To pin the Git source instead:

uv add --dev 'leesh @ git+https://github.com/denismaciel/leesh.git@v0.23.0'

Or run it with pre-commit:

repos:
  - repo: https://github.com/denismaciel/leesh
    rev: v0.23.0
    hooks:
      - id: leesh

Git and source-distribution installs download the matching executable from that release and verify its pinned SHA-256. Installed packages run offline. Prebuilt wheels are also attached to the release. Supported platforms: Linux x86-64 and ARM64 (including musl), macOS Intel (10.13+) and Apple Silicon (11+), and Windows x86-64. Python 3.12+ remains required.

The Python import, CLI, configuration file (leesh.toml), and native executable (leesh-rust) use the Leesh name. The old module and command aliases are removed.

Use

leesh init --layout domains   # write a starter leesh.toml
leesh check                   # check the whole workspace
leesh check src/app/orders    # report findings under these paths only
leesh report                  # rank findings by rule, layer edge, target and area
leesh baseline                # record current findings so only new ones fail
leesh classify src            # show each file's layer and the pattern that matched
leesh explain LIT101          # show a rule's documentation
leesh rules                   # list every rule

check finds the workspace root from the nearest leesh.toml (or pyproject.toml if there is none), discovers every package with a pyproject.toml below it, and always analyzes the whole workspace so that imports are followed across files and packages. Output formats are text, json ({"findings": [...], "summary": {...}}) and github (workflow annotations). Exit status is 0 when clean, 1 when there are findings, and 2 for usage errors or a manifest that cannot be loaded. Files are analyzed with native worker threads; --jobs 1 uses one worker.

Adopting Leesh on an existing codebase

Describe the code you have instead of moving it first: a custom layout maps today's directories to layers, and custom layers name the roles that don't fit the built-in ones (a Temporal workflow is a deterministic router). Then:

  1. leesh report shows which rules, layer edges and imported modules produce the findings, so you can tell policy questions from real debt.
  2. Settle policy in the manifest: [[allowed_dependencies]] for modules that act as ports, [[ignore]] for a rule you are not adopting yet in a given place, [conventions] for your framework bases. Each needs a reason.
  3. Set workspace.baseline and run leesh baseline. check now fails only on new findings, and on baseline entries that no longer match until you run leesh baseline --prune, so the baseline can only shrink.

Layers

Layer Holds May import (default)
core decisions, values, policies core
port interfaces the core needs core, port
shell orchestration of core and ports core, port, shell
adapter implementations of ports core, port, adapter
router HTTP handlers shell, boundary, router, transaction
boundary entry points, configuration, schemas anything
transaction units of work, migrations anything
test tests and fixtures anything
marker __init__.py files anything (followed, never a target)

A package's layout maps paths to layers. The built-in layouts are domains (src/<pkg>/domains/<domain>/{core,model,policy,ports,service}.py, app/, db/, integrations/), hexagonal (domain/, application/, adapters/, web/), flat (everything is shell, except model.py, core.py, policy.py, ports.py, adapters/ and cli.py), boundary, and test-support. A conventional module may grow into a package of the same name: the files of domains/orders/core/ are core like domains/orders/core.py. A package's kind (server, client or library) controls whether other packages may depend on it. Custom layers ([layers.<name>]) follow a built-in layer's rules with their own dependency policy.

See docs/rules.md for every rule and docs/configuration.md for the manifest.

Rust implementation

Leesh is implemented in Rust and packaged with a thin Python launcher shim for PyPI and uvx distribution. To build Rust locally:

cargo build --locked --release --manifest-path rust/Cargo.toml
rust/target/release/leesh-rust check

It reuses Ruff's parser, parallelizes analysis, and exposes Leesh's rules and CLI commands. See build and verification instructions and the performance benchmarks.

Development

cargo build --locked --release --manifest-path rust/Cargo.toml
export LEESH_NATIVE_BINARY="$PWD/rust/target/release/leesh-rust"
make dev check test
make build release-check
uv run leesh rules --format markdown > docs/rules.md  # after changing rust/src/registry.json

Python packaging uses uv and uv_build with a small native-artifact adapter. See release instructions for preparation and tagged releases.

Rules live in rust/src/rules/ and are documented in rust/src/registry.json.

License

MIT. See LICENSE.

Metadata

Release files for leesh 0.23.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 leesh 0.23.0
File Size Uploaded Provenance Actions
leesh-0.23.0.tar.gz 496.1 kB With provenance Details for leesh-0.23.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for leesh 0.23.0
File Actions
leesh-0.23.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for leesh-0.23.0-py3-none-win_amd64.whl
leesh-0.23.0-py3-none-manylinux_2_28_x86_64.musllinux_1_2_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64, Linux musl 1.2+ x86-64 Details for leesh-0.23.0-py3-none-manylinux_2_28_x86_64.musllinux_1_2_x86_64.whl
leesh-0.23.0-py3-none-manylinux_2_28_aarch64.musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64, Linux glibc 2.28+ ARM64 Details for leesh-0.23.0-py3-none-manylinux_2_28_aarch64.musllinux_1_2_aarch64.whl
leesh-0.23.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for leesh-0.23.0-py3-none-macosx_11_0_arm64.whl
leesh-0.23.0-py3-none-macosx_10_13_x86_64.whl Python 3 none macOS 10.13+ x86-64 Details for leesh-0.23.0-py3-none-macosx_10_13_x86_64.whl

Total release size: 13.8 MB

Release files / leesh-0.23.0.tar.gz

Download URL leesh-0.23.0.tar.gz
Size 496.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0976678142c00e9a369ac58790c5c2385eaa96a85c3f6c08c5785ab7b284adf8
BLAKE2b-256 checksum
How to use checksums
6695c02f0e06be277144c9a5c1b5f308b09741743ba53b90288ea96c39fbb0fb
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 log

Release files / leesh-0.23.0-py3-none-win_amd64.whl

Download URL leesh-0.23.0-py3-none-win_amd64.whl
Size 2.5 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
2836d4403f975961eba9e66a16dfbcf4971777dd202adaa42115920a3e4b1769
BLAKE2b-256 checksum
How to use checksums
fc718a675969b5df49a5da816c015493ccd5c1affd43822b68c1399c72cb5358
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 log

Release files / leesh-0.23.0-py3-none-manylinux_2_28_x86_64.musllinux_1_2_x86_64.whl

Download URL leesh-0.23.0-py3-none-manylinux_2_28_x86_64.musllinux_1_2_x86_64.whl
Size 2.9 MB
Tags Linux glibc 2.28+ x86-64 Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
d9839609cbe734698243dd5dcf13c41b5dc73bbae62c3cb41e96a7fefcf5dda3
BLAKE2b-256 checksum
How to use checksums
cb4314c9f932105be98f99bd8c3f30eedd6b879de3ada8f197eafc8e7bf41f41
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 log

Release files / leesh-0.23.0-py3-none-manylinux_2_28_aarch64.musllinux_1_2_aarch64.whl

Download URL leesh-0.23.0-py3-none-manylinux_2_28_aarch64.musllinux_1_2_aarch64.whl
Size 2.7 MB
Tags Linux glibc 2.28+ ARM64 Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
d72c7d465af22e476c34c45161453d924ba4be16261f039ff080663df3cfaa36
BLAKE2b-256 checksum
How to use checksums
70b3dca8ca72a446755aa0a25012b97e0e652801b493515d51c0c274b8378098
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 log

Release files / leesh-0.23.0-py3-none-macosx_11_0_arm64.whl

Download URL leesh-0.23.0-py3-none-macosx_11_0_arm64.whl
Size 2.5 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
14d0c1f7cbed1a6ea670a2156dc07e00dc1bb603cc2150698d295cf7f486deac
BLAKE2b-256 checksum
How to use checksums
81501f6a274a8dbd1fc07f1c80acb87f2cd6639fe90c67e0daa0d94897931405
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 log

Release files / leesh-0.23.0-py3-none-macosx_10_13_x86_64.whl

Download URL leesh-0.23.0-py3-none-macosx_10_13_x86_64.whl
Size 2.7 MB
Tags Python 3 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
57019d4e647c9d366ac704d73aca4cece35a07947fac03119bc8d5930bede369
BLAKE2b-256 checksum
How to use checksums
b374eabd25ff1ea1268d1ece6739d04ee1f04e96b6da9aa47f71c89113d99d1f
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 log

Security for leesh 0.23.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 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for leesh-0.23.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 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