Build Lean Server from Source
This guide walks you through setting up the Lean Server from source code, providing a high-performance REST API for executing and verifying Lean 4 mathematical proofs.
Prerequisites
Before starting, ensure you have the following installed on your system:
- uv or Conda: We strongly recommend using uv. You can follow this link for installation.
- elan: You can follow this tutorial to install elan.
Installation Steps
1. Clone the Repository
Choose your preferred method to clone the repository:
2. Set Up Python Environment
Create and activate a Python virtual environment with the required Python version:
3. Install Server Package
Install the server package in editable mode to enable development:
4. Build Lean Dependencies
Build the Lean workspace and install required mathematical libraries:
# Navigate to the Lean playground
cd playground
# Build all Lean dependencies (this may take several minutes)
lake build
# Return to the project root
cd ..
Build Time
The initial build process downloads and compiles Mathlib4 and other dependencies, which can take 10-30 minutes depending on your system.
Customize Lean Dependencies
You can customize the Lean dependencies by modifying the lean-runner/playground/lakefile.toml
file, or completely replace the lean-runner/playground
directory with your own Lean workspace.
Running the Server
Basic Server Startup
Start the server with default settings:
# Ensure virtual environment is activated
source .venv/bin/activate
# Start the server
lean-server --port=8888 --concurrency=32
Command Line Options
The lean-server
command supports the following options:
Option | Default | Description |
---|---|---|
--host | 127.0.0.1 | Host address to bind to |
--port | 8000 | Port number to listen on |
--concurrency | 10 | Maximum number of concurrent proof verifications |
--config | config.yaml | Path to configuration file |
--log-level | INFO | Logging level (DEBUG, INFO, WARNING, ERROR) |
Example Configurations
Features:
- Local access only
- Auto-reload on code changes
- Detailed debug logging
- Good for development and testing
Features:
- External access enabled
- Moderate concurrency
- Standard logging
- Balanced performance
Verify Installation
Test that the server is working correctly:
1. Check Server Status
Expected response:
2. Test Proof Verification
Next Steps
After successful installation:
- Read the Client Documentation to learn how to interact with the server
- Explore the API Documentation for detailed endpoint reference