Kimina Lean Server - FastAPI server for checking Lean 4 code at scale
Project description
Kimina AST Server
FastAPI server for checking Lean 4 code at scale via REPL and AST export.
Installation
Install from PyPI:
pip install kimina-ast-server
Quick Start
1. Set up the workspace
The server requires a Lean workspace with repl, ast_export, and mathlib4 repositories.
Set it up automatically:
# Setup in current directory
kimina-ast-server setup
# Or setup in a specific directory
kimina-ast-server setup --workspace ~/lean-workspace
# Setup and save configuration
kimina-ast-server setup --workspace ~/lean-workspace --save-config
This will:
- Install Elan (Lean version manager)
- Clone and build the
replrepository - Clone and build the
ast_exportrepository - Clone and build
mathlib4(this may take a while)
2. Start the server
# If you ran setup in current directory, just run:
kimina-ast-server
# If workspace is elsewhere, set the environment variable:
export LEAN_SERVER_WORKSPACE=~/lean-workspace
kimina-ast-server
# Or if you used --save-config, run from the workspace directory:
cd ~/lean-workspace
kimina-ast-server
The server will start on http://0.0.0.0:8000 by default.
Configuration
Environment Variables
| Variable | Default | Description |
|---|---|---|
LEAN_SERVER_WORKSPACE |
Auto-detected | Path to workspace directory containing repl/, ast_export/, and mathlib4/ |
LEAN_SERVER_HOST |
0.0.0.0 |
Host address to bind the server |
LEAN_SERVER_PORT |
8000 |
Port number for the server |
LEAN_SERVER_LOG_LEVEL |
INFO |
Logging level (DEBUG, INFO, ERROR, etc.) |
LEAN_SERVER_ENVIRONMENT |
dev |
Environment dev or prod |
LEAN_SERVER_LEAN_VERSION |
v4.15.0 |
Lean version to use |
LEAN_SERVER_MAX_REPLS |
CPU count - 1 | Maximum number of REPLs |
LEAN_SERVER_MAX_REPL_USES |
-1 |
Maximum number of uses per REPL (-1 is no limit) |
LEAN_SERVER_MAX_REPL_MEM |
8G |
Maximum memory limit for each REPL (Linux-only) |
LEAN_SERVER_MAX_WAIT |
3600 |
Maximum wait time for a REPL (in seconds) |
LEAN_SERVER_API_KEY |
None |
Optional API key for authentication |
LEAN_SERVER_DATABASE_URL |
None |
URL for the database (if using one) |
Workspace Auto-Discovery
The server automatically discovers the workspace in this order:
LEAN_SERVER_WORKSPACEenvironment variable- Current working directory (if it contains
mathlib4/orrepl/) - Common locations:
~/kimina-workspace,~/lean-workspace,~/workspace
Individual Path Overrides
If you have a non-standard layout, you can override individual paths:
LEAN_SERVER_REPL_PATH- Path to REPL binaryLEAN_SERVER_AST_EXPORT_BIN- Path to AST export binaryLEAN_SERVER_AST_EXPORT_PROJECT_DIR- Path to AST export project directoryLEAN_SERVER_PROJECT_DIR- Path to mathlib4 directory
Commands
kimina-ast-server
Start the FastAPI server. This is the default command.
kimina-ast-server
# or
kimina-ast-server run
kimina-ast-server setup
Set up the Lean workspace. This installs Elan, Lean, and builds the required repositories.
# Basic usage
kimina-ast-server setup
# Specify workspace location
kimina-ast-server setup --workspace ~/lean-workspace
# Save configuration to .env file
kimina-ast-server setup --workspace ~/lean-workspace --save-config
# Specify Lean version
kimina-ast-server setup --lean-version v4.21.0
Options:
--workspace PATH- Path to workspace directory (default: current directory orLEAN_SERVER_WORKSPACE)--save-config- Create.envfile withLEAN_SERVER_WORKSPACEsetting--lean-version VERSION- Lean version to install (default: v4.15.0)
API Endpoints
Once the server is running, you can access:
- API Documentation:
http://localhost:8000/docs(Swagger UI) - ReDoc:
http://localhost:8000/redoc - OpenAPI JSON:
http://localhost:8000/api/openapi.json
Main Endpoints
POST /api/check- Check Lean 4 code snippetsPOST /api/ast- Get AST for existing modulesPOST /api/ast_code- Get AST from raw codeGET /health- Health check endpoint
Manual Setup
If you prefer to set up the workspace manually:
- Install Elan and Lean 4
- Clone and build the required repositories:
git clone https://github.com/leanprover-community/repl.git cd repl && lake build git clone https://github.com/KellyJDavis/ast_export.git cd ast_export && lake build git clone https://github.com/leanprover-community/mathlib4.git cd mathlib4 && lake exe cache get && lake build
- Set
LEAN_SERVER_WORKSPACEto the directory containing these repositories
Prerequisites
- Python 3.9+
gitandcurl(for setup command)- Elan and Lean 4 (installed automatically by setup command)
- Sufficient disk space (~10GB+ for mathlib4)
Troubleshooting
"Missing required Lean workspace components"
The server couldn't find the required repositories. Solutions:
- Run
kimina-ast-server setupto set up the workspace - Set
LEAN_SERVER_WORKSPACE=/path/to/workspace - Set individual path environment variables (see Configuration section)
"setup.sh not found"
The setup script should be included with the package. If you see this error:
- Ensure you installed from PyPI:
pip install kimina-ast-server - If installing from source, ensure
setup.shis in the repository root
Server fails to start
Check that:
- All required paths exist and are accessible
lakecommand is in your PATH (should be after running setup)- You have sufficient disk space and memory
Development
For development setup, see the main README.md.
License
MIT License - see LICENSE file.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kimina_ast_server-2.1.2.tar.gz.
File metadata
- Download URL: kimina_ast_server-2.1.2.tar.gz
- Upload date:
- Size: 33.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed5e5c9acea449c8c605f088b5c49106a2027233c88572e76d2b2744f0ac6da6
|
|
| MD5 |
1657792be4fdeba64cc5e5ece335b342
|
|
| BLAKE2b-256 |
29e11f34df339f039d84e5e7afce6df5a47d4e73964a2e99d0df69f6ee196c5e
|
File details
Details for the file kimina_ast_server-2.1.2-py3-none-any.whl.
File metadata
- Download URL: kimina_ast_server-2.1.2-py3-none-any.whl
- Upload date:
- Size: 41.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
686e3773aa99a6ebcc526fbf0d84d47decd1c37d3504ddc31b656b4bbaefedaa
|
|
| MD5 |
92a89f62db217ccd2ed7fa4850789848
|
|
| BLAKE2b-256 |
bce64f26a34f1b77e7da6d56d74be82c6eb17fa626973767854457ce3202f0e5
|