Write it in Lean. Prove it in Lean. Run it in your language.
Get started · Languages · Features · Documentation & examples · Contribution
leanfran brings Lean 4 to your programming language. Write functions and proofs together, compile them to your application's language, and call them through native types. The generated code runs with a small host-language runtime; Lean is needed to check and generate code, not to run the result.
def double (n : Nat) : Nat := n + n
theorem double_eq (n : Nat) : double n = 2 * n := by
unfold double
omegaleanfran compiles Lean's compiler IR into source code for the selected language. You can generate code from a Lean project or embed Lean blocks directly in host-language source files. Proofs are checked by Lean during generation and erased from the executable code.
| Language | Start here | Package | Integration |
|---|---|---|---|
| Rust | Rust quick start | leanfran on crates.io | lean!, Rust types, Cargo build integration |
| Python | Python quick start | leanfran on PyPI | lean(...), pydantic models, Python modules |
| TypeScript | TypeScript quick start | leanfran on npm | lean(...), TypeScript types, Standard Schema |
| Clojure | Clojure quick start | io.github.conao3/leanfran on Clojars | deflean, Clojure values, JVM namespaces |
- Proved functions in your application. Keep an algorithm and its correctness proof together, then call the generated function from your application.
- Validated data at the boundary. Lean structures and inductive types map to host-language values. Supported proof fields become runtime checks for the invariants your proofs assume.
- Specifications for host-language code. Bind supported Rust, Python, TypeScript or Clojure functions to Lean specifications, translate them to Lean, and check proof obligations. Each language guide describes its supported subset and verification tools.
The backends share Lean's semantics and are tested against Lean's native C backend. Their supported types, externs and host-language integrations are documented in the language guides.
Choose a language above and install its host package and compiler. Lean 4.35.0 is required for generation and proof checking. With Nix, install a compiler from this repository:
nix profile install 'github:conao3/lean-leanfran#python'Use #rust, #typescript or #clojure for the other targets. The Rust package also includes the Cargo CLI and Aeneas verification tools. Follow the language quick start for dependencies, project setup and generation commands.
| Language | Quick start | Full guide | Examples |
|---|---|---|---|
| Rust | Setup and first block | Types, verification and CLI | Rust samples |
| Python | Setup and first block | Models, verification and CLI | Python samples |
| TypeScript | Setup and first block | Schemas, verification and CLI | TypeScript samples |
| Clojure | Setup and first block | Types, verification and CLI | Clojure samples |
New language support is welcome! Use the latest Claude Opus, OpenAI Sol, or a model with a comparable score on the Artificial Analysis Intelligence Index, and ask your coding agent to follow this guide:
Read docs/add-language.md and add support for <LANGUAGE> to leanfran.
The repository has one Nix environment and Lean toolchain, with language-specific source and packages in langs/Rust/, langs/Python/, langs/TypeScript/ and langs/Clojure/.
nix develop
make check
make check BACKENDS=PythonSee CONTRIBUTING.md for build targets, formatting, packaging and the coordinated release process. Implementation notes live in docs/; maintenance tools live in maint/.