Skip to content

Client API Reference

The Client module provides an interface for interacting with a LeanFlow Server.

It abstracts the HTTP communication, allowing you to treat a remote Lean instance almost exactly like a local REPL instance. It automatically handles connection pooling, request serialization, and error parsing.

The SyncClient class is a blocking wrapper around the asynchronous client.

leanflow.SyncClient

Synchronous wrapper around the Client class. Provides a blocking API for interacting with a LeanFlow server without needing to use async/await.

Example
from leanflow import SyncClient

with SyncClient(base_url="http://localhost:8000") as client:
    result = client.run("#eval 1 + 1")
    print(result)

__init__(base_url, timeout=300)

Initialize the SyncClient with the given configuration.

Parameters:

Name Type Description Default
base_url str

URL of the LeanFlow server.

required
timeout int

Request timeout in seconds.

300

run(command, env=None)

Run a Lean command synchronously via the server.

Parameters:

Name Type Description Default
command str

A single command string.

required
env Optional[int]

Optional environment ID to run in.

None

Returns:

Type Description
Union[Environment, LeanError]

Environment or LeanError.

run_list(commands, env=None)

Run Lean commands synchronously via the server.

Parameters:

Name Type Description Default
commands list[str]

A list of command strings.

required
env Optional[int]

Optional environment ID to run in.

None

Returns:

Type Description
list[Union[Environment, LeanError]]

List of results (Environment or LeanError).

status()

Check server status synchronously.

Returns:

Type Description
bool

True if the server is running and accessible, False otherwise.

close()

Close the client connection and clean up resources.

The Client class is the native asynchronous implementation, built on top of httpx.

leanflow.Client

An asynchronous client for interacting with a remote LeanFlow Server.

Example
import asyncio
from leanflow import Client

async def main():
    async with Client("http://localhost:8000") as client:
        result = await client.run("#eval 1 + 1")
        print(result)

asyncio.run(main())

__init__(base_url, timeout=None, max_connections=1000, max_keepalive_connections=100, log_dir=None, log_level=None)

Initializes the Client.

Parameters:

Name Type Description Default
base_url str

The base URL of the leanflow-server.

required
timeout Optional[int]

Request timeout in seconds.

None
max_connections int

Maximum number of connections.

1000
max_keepalive_connections int

Maximum number of keepalive connections.

100
log_dir Optional[Union[str, Path]]

Explicit directory to save log files.

None
log_level Optional[str]

The logging level (e.g., "INFO", "DEBUG").

None

run(command, env=None) async

Executes a single Lean command.

Parameters:

Name Type Description Default
command str

The Lean command to execute.

required
env Optional[Union[Environment, int]]

The environment ID to run in.

None

Returns:

Type Description
Union[Environment, LeanError]

The result of the command.

run_list(commands, env=None) async

Executes a list of commands sequentially, in the same environment and stopping on the first error.

Parameters:

Name Type Description Default
commands list[str]

A list of commands.

required
env Optional[Union[Environment, int]]

The environment to run the commands in.

None

Returns:

Type Description
list[Union[Environment, LeanError]]

List of results.

status() async

Checks if the remote server is running and accessible.

Returns:

Type Description
bool

True if the server returns status 'ok', False otherwise.

close() async

Closes the underlying HTTP client.