Skip to main content

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 repl repository
  • Clone and build the ast_export repository
  • 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:

  1. LEAN_SERVER_WORKSPACE environment variable
  2. Current working directory (if it contains mathlib4/ or repl/)
  3. 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 binary
  • LEAN_SERVER_AST_EXPORT_BIN - Path to AST export binary
  • LEAN_SERVER_AST_EXPORT_PROJECT_DIR - Path to AST export project directory
  • LEAN_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 or LEAN_SERVER_WORKSPACE)
  • --save-config - Create .env file with LEAN_SERVER_WORKSPACE setting
  • --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 snippets
  • POST /api/ast - Get AST for existing modules
  • POST /api/ast_code - Get AST from raw code
  • GET /health - Health check endpoint

Manual Setup

If you prefer to set up the workspace manually:

  1. Install Elan and Lean 4
  2. 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
    
  3. Set LEAN_SERVER_WORKSPACE to the directory containing these repositories

Prerequisites

  • Python 3.9+
  • git and curl (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:

  1. Run kimina-ast-server setup to set up the workspace
  2. Set LEAN_SERVER_WORKSPACE=/path/to/workspace
  3. 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:

  1. Ensure you installed from PyPI: pip install kimina-ast-server
  2. If installing from source, ensure setup.sh is in the repository root

Server fails to start

Check that:

  • All required paths exist and are accessible
  • lake command 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

Metadata

Release files for kimina-ast-server 2.1.3

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

Source distribution (sdist)

Source distribution for kimina-ast-server 2.1.3
File Size Uploaded Provenance
kimina_ast_server-2.1.3.tar.gz 33.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kimina-ast-server 2.1.3
File Interpreter ABI Platform
kimina_ast_server-2.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 75.7 kB

Release files / kimina_ast_server-2.1.3.tar.gz

Download URL kimina_ast_server-2.1.3.tar.gz
Size 33.8 kB
Tags Source
SHA-256 checksum
How to use checksums
edabbe0882478dde6fab9662b7b8b3b97efbe404b6b5228e2835d3f26a7c5c9d
BLAKE2b-256 checksum
How to use checksums
2c594020531a575964a9bb0fe9df3d9c631758d6e2b080ac765c3f927f981e78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / kimina_ast_server-2.1.3-py3-none-any.whl

Download URL kimina_ast_server-2.1.3-py3-none-any.whl
Size 41.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f962d5fd0e67350f51e6b70d974e0dd158cab3cec63a21498b071df93790735
BLAKE2b-256 checksum
How to use checksums
b7529ce8f774050c515a3e45667c704ba4629bf9637271db8c72a371d9701372
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for kimina-ast-server 2.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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