Skip to main content

A search engine for Lean 4 declarations.

Project description

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. Lean Explore enables semantic search across multiple Lean projects including Mathlib, Batteries, Std, PhysLean, Init, and Lean, helping you discover relevant theorems, definitions, and other declarations using natural language queries.

Features

  • 🔍 Semantic Search: Find Lean declarations using natural language queries
  • 📚 Multi-Project Support: Search across Mathlib, Batteries, Std, PhysLean, Init, and Lean
  • 🚀 Multiple Interfaces: Use via CLI, Python API, HTTP server, or MCP server
  • 🏠 Local Backend: Run searches locally with your own data (no API key required)
  • 🔗 Dependency Tracking: Explore relationships between declarations
  • 📊 Ranked Results: Results are ranked using semantic similarity, PageRank, and lexical matching

Installation

Install from PyPI:

pip install lean-xplore

Requirements

  • Python 3.10 or higher
  • pip (Python package installer)

Quick Start

Getting an API Key

To use the remote API, you'll need an API key. API keys can be obtained from https://www.leanexplore.com. Once you have your API key, configure it using:

leanexplore configure api-key YOUR_API_KEY

Alternatively, you can use the local backend without an API key (see Local Backend below).

Command Line

Search for Lean declarations:

# Basic search
leanexplore search "natural numbers"

# Search with package filters (limit results to specific packages)
leanexplore search "monoid" --pkg Mathlib --pkg Batteries

# Limit the number of results
leanexplore search "topology" --limit 5

The CLI will automatically use your configured API key, or you can use the local backend:

# Use local backend (no API key needed)
leanexplore search "natural numbers" --backend local

Python API

import asyncio
from lean_explore.api.client import Client

async def main():
    # Initialize client with API key
    client = Client(api_key="your-api-key")
    
    # Perform a search
    results = await client.search("natural numbers")
    
    # Display results
    print(f"Found {len(results.items)} results")
    for item in results.items[:5]:
        print(f"{item.primary_declaration.lean_name}: {item.informal_name}")
        if item.informal_description:
            print(f"  {item.informal_description[:100]}...")

asyncio.run(main())

You can also search multiple queries at once:

async def main():
    client = Client(api_key="your-api-key")
    
    # Search multiple queries
    results = await client.search([
        "natural numbers",
        "group theory",
        "topology"
    ])
    
    for result in results:
        print(f"\nQuery: {result.query}")
        print(f"Results: {len(result.items)}")

asyncio.run(main())

Local Backend

Run searches locally without an API key. This is useful for offline access, faster queries, or when you want full control over the data.

# Download local data (database, embeddings, and search index)
leanexplore data fetch

# Start local HTTP server
leanexplore http start --backend local

The server will be available at http://localhost:8000. You can query it via HTTP or use the Python client:

from lean_explore.api.client import Client

# Connect to local server
client = Client(base_url="http://localhost:8000")

# Use as normal (no API key needed)
results = await client.search("natural numbers")

Additional Features

  • MCP Server: Integrate with AI agents using the Model Context Protocol

    leanexplore mcp start --backend api --api-key YOUR_API_KEY
    
  • HTTP Server: Run your own API server

    leanexplore http start --backend local
    
  • AI Chat: Interact with an AI agent that can search Lean code

    leanexplore chat --backend api --api-key YOUR_API_KEY
    

Documentation

For detailed documentation, API reference, configuration options, and more examples, visit https://kellyjdavis.github.io/lean-explore.

The documentation includes:

  • Complete installation and setup guides
  • Detailed CLI usage and options
  • Python API reference with examples
  • HTTP server configuration
  • MCP server integration
  • Local backend setup and data management
  • Development guides and contributing information

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

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. LeanExplore.com. (GitHub: https://github.com/justincasher/lean-explore).

BibTeX Entry:

@software{Asher_LeanExplore_2025,
  author = {Asher, Justin},
  title = {{LeanExplore: A search engine for Lean 4 declarations}},
  year = {2025},
  url = {http://www.leanexplore.com},
  note = {GitHub repository: https://github.com/justincasher/lean-explore}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lean_xplore-0.4.0.tar.gz (220.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lean_xplore-0.4.0-py3-none-any.whl (309.3 kB view details)

Uploaded Python 3

File details

Details for the file lean_xplore-0.4.0.tar.gz.

File metadata

  • Download URL: lean_xplore-0.4.0.tar.gz
  • Upload date:
  • Size: 220.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for lean_xplore-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5158a2608cdaa7152f6ad46556429fb7aae4ff907f41405b032b1cf42784ffa5
MD5 c1558b527b8c327779c79c214764a3a7
BLAKE2b-256 69716f21468bd1f9f10b5e8a1c09c86d9a47a4de72c5e3350d73c9852a9c066c

See more details on using hashes here.

File details

Details for the file lean_xplore-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: lean_xplore-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 309.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for lean_xplore-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 592f67873644daacf4b7796b7376cd74512db7c46d49942738404dd45b3846a7
MD5 02805499bc1caae83e91d8596f52c52f
BLAKE2b-256 d2d17aac87029ea6096e030b8bb93ee0ebaae9368703ca783192c4c12b9b790c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page