explaingit

jzshischolar/pyleaner

14LeanAudience · researcherComplexity · 4/5Setup · hard

TLDR

PyLeaner bridges Python and Lean 4 so AI researchers can query formal proof state, extract theorem definitions, and run parallel proof-checking workloads from Python code.

Mindmap

mindmap
  root((PyLeaner))
    What it does
      Connect Python to Lean 4
      Query proof goals
      Extract declarations
      Fetch compiler errors
    Tech stack
      Python client
      Lean 4 server
      Worker pool
      pip install
    Use cases
      AI proof generation
      Parallel proof checking
      Theorem extraction
      ML research tooling
    Audience
      AI researchers
      Formal methods devs
      Math ML engineers
    Setup
      Lean project dep
      pip install
      No Mathlib required
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build an AI system that generates proof steps by querying what goals remain at each point in a Lean proof.

USE CASE 2

Extract all theorems and definitions from a Lean file into a structured format for training or analysis.

USE CASE 3

Run large batches of proof-checking requests in parallel using a managed pool of Lean server instances.

USE CASE 4

Retrieve compiler errors from Lean files programmatically inside a Python machine learning pipeline.

Tech stack

PythonLean 4Language ServerWorker Poolpip

Getting it running

Difficulty · hard Time to first run · 1h+

Requires a Lean 4 project with the PyLeaner dependency added, plus a separate pip install for the Python client. No Mathlib needed but works with Mathlib projects.

The explanation does not mention a license.

In plain English

PyLeaner is a library that lets Python code communicate with Lean 4, a programming language used for writing formal mathematical proofs. Lean 4 can check whether a proof is logically valid, and researchers working on AI systems that generate or verify proofs need a way to connect their Python-based machine learning code to Lean's internals. PyLeaner provides that connection. The library has two parts. One part is an extension for Lean's language server, which is a background process that Lean uses to analyze code in editors. The extension adds new capabilities to that server so that Python can ask it for things beyond what a standard editor would need. The second part is a Python client that talks to the server, manages multiple server instances at once for parallel workloads, and handles the lower-level details of the communication protocol automatically. From Python, you can load a Lean file and then ask questions about it. You can extract a structured list of all the definitions, theorems, and other declarations in the file, including their parameter names, types, and bodies. You can ask what proof goals remain at a specific point in a proof, which is useful when an AI system needs to decide what step to take next. You can also retrieve any errors or warnings the Lean compiler reported. The library manages concurrency through a worker pool. When you have many requests to process, the pool distributes them across multiple running Lean server instances and routes each request to whichever one is least busy. Each operation pairs the step of pushing updated file content to the server with the step of querying the result, so you always get a consistent answer. PyLeaner does not require Mathlib (the main Lean mathematics library) to be installed, but it works with Mathlib projects. Installation involves adding a dependency in your Lean project and installing the Python package separately with pip.

Copy-paste prompts

Prompt 1
Using PyLeaner, write a Python script that loads a Lean 4 file and prints out all theorem names, their parameter types, and their bodies.
Prompt 2
Using PyLeaner's worker pool, write a Python function that sends 50 proof-checking requests in parallel and collects the remaining proof goals for each.
Prompt 3
With PyLeaner, write a Python snippet that loads a Lean file and retrieves any compiler errors or warnings reported by the Lean server.
Prompt 4
Using PyLeaner, build a loop that iterates over proof goals returned at a specific cursor position in a Lean file and decides the next proof tactic using a language model.
Prompt 5
Show me how to set up PyLeaner in a Lean 4 project: what to add to the Lean project file and how to install the Python package with pip.
Open on GitHub → Explain another repo

← jzshischolar on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.