What is LeanFlow?
LeanFlow is an easy-to-use, scalable Python interface to Lean 4.
It lets you run Lean code, interact with proofs, and evaluate formal statements from Python. Ideal for researchers in autoformalization, theorem proving, and experimentation.
Fast & Efficient
LeanFlow is built for efficiency, allowing you to execute large-scale workloads simultaneously with minimal overhead.
Easy to Use
A small, Pythonic API that feels intuitive. Start running Lean in just a few lines of code.
Flexible Deployment
Use interactive mode for local development or server mode for scalable experiments. Switch between them with a small config change.
Evaluation Tools
Built-in metrics for autoformalization evaluation: TypeCheck, BEq+, LLM Grader, and more.
Installation
Get Started in 3 Lines
The simplest way to run Lean from Python:
from leanflow import SyncREPL
repl = SyncREPL(lean_version="4.24.0", require_mathlib=True)
print(repl.run("#eval 1 + 1"))
That's it! LeanFlow automatically downloads Lean and sets up the environment.
Built for Performance
LeanFlow is built on asyncio for high-throughput parallel execution. The synchronous API shown above is perfect for getting started, scripts, and notebooks. For production workloads with parallel evaluation, see the async API.
Two Ways to Run Lean
Evaluation Metrics
LeanFlow includes built-in metrics for autoformalization evaluation, including type checking and semantic equivalence checks:
from leanflow import TypeCheck, BEqPlus
header = "import Mathlib"
thm1 = "theorem infinite_primes (n : Nat) : ∃ p, n < p ∧ Nat.Prime p := sorry"
thm2 = "theorem infinite_primes_alt (k : Nat) : ∃ q, k < q ∧ Nat.Prime q := sorry"
# Type checking
metric = TypeCheck(repl_config={"lean_version": "4.24.0"})
result = metric.compute(thm1, header=header)
print(result) # True
# Semantic equivalence (BEq+)
metric = BEqPlus(repl_config={"lean_version": "4.24.0"})
result = metric.compute(thm1, thm2, header=header)
print(result) # True
Run evaluations at scale with the CLI:
What's Next?
-
Quickstart
Get up and running in 5 minutes with our step-by-step guide
-
User Guide
Learn about REPL, Server, and CLI in depth
-
API Reference
Complete reference for all classes and methods
Inspiration & Acknowledgements
This project builds upon the incredible work of the Lean community. We are deeply grateful to the authors of the following projects, which directly inspired LeanFlow:
- LeanInteract by Auguste Poiroux
- Rethinking and Improving Autoformalization by Qi Liu
- Kimina by Project Numina
We highly recommend checking out these projects!
Special thanks to the Lean community, the contributors to Mathlib, and the authors of the Lean REPL, whose tools make this ecosystem possible.
Community & Support
- GitHub: Report issues and contribute
- Discussions: Ask questions