Skip to main content

LeanExplore

A search engine for Lean 4 declarations

PyPI version Read the Paper last update license

A search engine for Lean 4 declarations. This project provides tools and resources for exploring the Lean 4 ecosystem.

The current indexed projects include:

  • Batteries
  • CSLib
  • FLT (Fermat's Last Theorem)
  • FormalConjectures
  • Init
  • Lean
  • Mathlib
  • PhysLean
  • Std

Installation

The base package connects to the remote API and does not require heavy ML dependencies:

pip install lean-explore

To run the local search backend (which uses on-device embedding and reranking models), install the extra ML dependencies:

pip install lean-explore[local]

Then fetch the data files and start the local MCP server:

lean-explore data fetch
lean-explore mcp serve --backend local

Claude Code and Codex plugin

The repository includes a plugin for both Claude Code and Codex. It connects to the hosted MCP server, so it does not need a Python install, a local search index, account, API key, or browser authorization. The tools are available as soon as the plugin is installed.

The hosted endpoint allows 30 POST requests per client IP in any 60-second window. Protocol initialization and tool-discovery requests count toward the limit, and clients sharing a public IP share the same budget.

Agents should begin with the token-efficient search_summary tool, then use the per-field retrieval tools for the declarations they need. The older full-result search MCP tool is deprecated and remains only for compatibility. All LeanExplore MCP tools are read-only and cannot modify Lean packages or external systems.

In Claude Code:

/plugin marketplace add justincasher/lean-explore
/plugin install lean-explore@lean-explore
/reload-plugins

In Codex:

codex plugin marketplace add https://github.com/justincasher/lean-explore
codex plugin add lean-explore@lean-explore

Start a new Codex session after installation so the MCP tools are loaded.

Documentation

Full docs live in the docs/ folder, or at https://www.leanexplore.com/docs.

Page Description
Getting Started Install and run your first search.
CLI Reference Every lean-explore command and flag.
MCP Server Wire LeanExplore into Claude, Cursor, or any MCP client.
API Client Use ApiClient from Python.
Local Search Backend How hybrid BM25 + FAISS + reranking works.
Configuration Environment variables and data layout.
Data Models SearchResult, SearchResponse, and related types.
Extraction Pipeline Rebuild the dataset from Lean source (contributors).

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines on code style, testing, and development setup.

Cite

If you use LeanExplore in your research or work, please cite it as follows:

General Citation:

Justin Asher. (2025). LeanExplore: A search engine for Lean 4 declarations. https://arxiv.org/abs/2506.11085

BibTeX Entry:

@software{Asher_LeanExplore_2025,
  author = {Asher, Justin},
  title = {{LeanExplore: A search engine for Lean 4 declarations}},
  year = {2025},
  url = {https://arxiv.org/abs/2506.11085}
}

License

This code is distributed under an Apache License (see LICENSE).

Metadata

Release files for lean-explore 1.3.0

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

Source distribution (sdist)

Source distribution for lean-explore 1.3.0
File Size Uploaded
lean_explore-1.3.0.tar.gz 73.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lean-explore 1.3.0
File Interpreter ABI Platform
lean_explore-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 157.7 kB

Release files / lean_explore-1.3.0.tar.gz

Download URL lean_explore-1.3.0.tar.gz
Size 73.0 kB
Tags Source
SHA-256 checksum
How to use checksums
011d27d544218ba897800ea8b3a23e6e0388d92d9bd23ff62816475fdd5aa139
BLAKE2b-256 checksum
How to use checksums
d92f196a50a444c3ba7740420ea4eac8bc944e1747b94afb4081643b2ea17067
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release files / lean_explore-1.3.0-py3-none-any.whl

Download URL lean_explore-1.3.0-py3-none-any.whl
Size 84.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc999708ac6ce7229f4cea4df9313c8cca708d4b219b2cad95eec631a519ec85
BLAKE2b-256 checksum
How to use checksums
5c4365714f832d292c98a53263f5245c990fb485ca9fdb105ec23a2233c30944
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

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