Server API Reference
The Server module provides the backend infrastructure for running LeanFlow as a service. It wraps the Lean REPL in a HTTP server (FastAPI), managing a pool of worker processes to handle concurrent requests.
Server Class
The Server class is the main entry point. It initializes the worker pool, handles the request queue, and manages the lifecycle of persistent Lean environments.
leanflow.Server
Server that owns and configures the StateManager.
Example
__init__(state_manager)
Initialize the server with a StateManager instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_manager
|
StateManager
|
The initialized state manager. |
required |
create_from_yaml(yaml_path)
async
classmethod
Asynchronously creates the Server by loading configuration from a YAML file.
This method waits for the StateManager to be fully initialized before returning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaml_path
|
Union[str, Path]
|
Path to the YAML configuration file. |
required |
Returns:
| Type | Description |
|---|---|
Server
|
The initialized Server instance. |
run(command, env=None)
async
Run command using the StateManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The Lean command to execute. |
required |
env
|
Optional[int]
|
The environment ID to run in. |
None
|
Returns:
| Type | Description |
|---|---|
Union[Environment, LeanError]
|
The result of the command. |
delete_environment(env_id)
async
Delete environment using the StateManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_id
|
int
|
The environment ID to delete. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if deleted, False if not found. |
shutdown()
async
Shutdown the server by shutting down the StateManager.
Starting the Server
Command Line
Configuration File (server.yaml)
The configuration file is split into two sections:
-
server: Controls HTTP server and worker settings. -
repl: Passed directly to the underlying Lean REPL instances.
server:
host: 0.0.0.0
port: 8000
workers: 10
stateless: false
repl:
lean_version: "4.24.0"
require_mathlib: true
timeout: 300
# Optional: Shared header to run on startup for every worker
header: |
import Mathlib
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
server.host |
string | localhost |
Host address to bind to |
server.port |
int | 8000 |
Port number |
server.workers |
int | 10 |
Number of REPL workers |
server.stateless |
bool | false |
Stateless mode |
repl.lean_version |
string | required | Lean version to use |
repl.require_mathlib |
bool | true |
Whether to include Mathlib |
repl.timeout |
int | 300 |
Command timeout in seconds |
repl.header |
string | null |
Commands to run at startup |
REST API Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET |
/status |
Check server status |
POST |
/run |
Execute a Lean command |
POST /run
Request:
Response: