leanfran for Python: write Lean blocks with lean(...), expose Lean types as pydantic models, and verify supported Python functions against Lean specifications.
uv add leanfran
nix profile install 'github:conao3/lean-leanfran#python'Generation also requires Lean 4.35.0 (lean and lake) on PATH. Generated modules run with the Python package and pydantic.
Create src/myapp/__init__.py and put this in src/myapp/arith.py:
from leanfran import lean
arith = lean("arith", r"""
def double (n : Nat) : Nat := n + n
theorem double_eq (n : Nat) : double n = 2 * n := by
unfold double; omega
""")Generate the Python modules:
leanfran sync --package src/myappThen call the function from your application:
from myapp.arith import arith
assert arith.double(21) == 42Commit src/myapp/_lean/ with your package, and add .leanfran/ to .gitignore. Run sync again when you change a Lean block.
- Full Python guide: pydantic models, JSON,
@model, verification, CLI and limitations. - Samples, including pricing, word count and step-by-step examples.
- Development and implementation notes.