Skip to main content
Change of provenance

The repository or configuration that created this release differ from a previous release. View details.

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.21.0'

Or run it with pre-commit:

repos:
  - repo: https://github.com/denismaciel/leesh
    rev: v0.21.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
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

The installed CLI uses Rust. The original Python implementation remains in the package for compatibility and differential testing. 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 preserves Leesh's rules and CLI commands. See build and verification instructions and the Python/Rust performance comparison.

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 a rule docstring

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

A rule is a class with a code, a name, a docstring (its documentation) and check(file: SourceFile). Register it in src/leesh/rules/registry.py.

License

MIT. See LICENSE.

Metadata

Release files for leesh 0.21.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Change of provenance

The repository or configuration that created these release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Source distribution (sdist)

Source distribution for leesh 0.21.0
File Size Uploaded Provenance Actions
leesh-0.21.0.tar.gz 462.7 kB With provenance Details for leesh-0.21.0.tar.gz

Built distributions (wheels)

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

Total release size: 13.0 MB

Release files / leesh-0.21.0.tar.gz

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL leesh-0.21.0.tar.gz
Size 462.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e0fa6427430dd765512887468f7f55dd52b78ade4f95c81c5dd6171ffaaf559e
BLAKE2b-256 checksum
How to use checksums
458d2b1cfa0c200116fb1a3ea7392d1baf7a8c80b206c623e9d0c28befaa2db1
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 16, 2026.

Transparency log

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

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL leesh-0.21.0-py3-none-win_amd64.whl
Size 2.4 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
3deed25f8389bdc928f1911e3a0b43eda5f7bbc80eb14d92c5ce59014181aaad
BLAKE2b-256 checksum
How to use checksums
02ebb60c030e3f760bbfae5815a0bdf5a26c01a6e7f3eb5e404a888ef189ca3d
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 16, 2026.

Transparency log

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

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL leesh-0.21.0-py3-none-manylinux_2_28_x86_64.musllinux_1_2_x86_64.whl
Size 2.7 MB
Tags Linux glibc 2.28+ x86-64 Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
b35e3888c5b301b495f5c06b22511d7dc0c6b91b50a625e9c3b00916c2985a54
BLAKE2b-256 checksum
How to use checksums
6d86b964b2b6b24ab6b563a32a824e86e2a96bee9fd972733123eb8cf7e5a18a
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 16, 2026.

Transparency log

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

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL leesh-0.21.0-py3-none-manylinux_2_28_aarch64.musllinux_1_2_aarch64.whl
Size 2.6 MB
Tags Linux glibc 2.28+ ARM64 Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
786868a28a2483f8796ff70ac12304d43c9343977a0c8ab7261157a668d923fe
BLAKE2b-256 checksum
How to use checksums
b782058c101a92507015ee99ac4fdf6ded36640d07841dc8c3a97e29e53dec8b
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 16, 2026.

Transparency log

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

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL leesh-0.21.0-py3-none-macosx_11_0_arm64.whl
Size 2.4 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
43da87a9c39f7cc11b843f33eee70396aa77072f7207d620ebd9c063856dc5dc
BLAKE2b-256 checksum
How to use checksums
2be216f820c9ba4079df84a218dd6e1275cffb6e3996134ab6b4f3059bed9c9e
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 16, 2026.

Transparency log

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

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL leesh-0.21.0-py3-none-macosx_10_13_x86_64.whl
Size 2.5 MB
Tags Python 3 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
97a33e8bf236f4cc392b0d06f30cbf818aeb098192cec8082c8720e44af9d415
BLAKE2b-256 checksum
How to use checksums
0049823402bba4e786145970a8d912861e64cabc81746d0a110642d380db414d
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 16, 2026.

Transparency log

Security for leesh 0.21.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.

Change of provenance

The repository and configuration that created this release differ from a previous release.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Select from 6 files

Attestation for leesh-0.21.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 16, 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