bt.lean

bt.lean

Typed local Lean CLI orchestration.

The adapter launches the standalone lean command without changing the caller’s working directory. LEAN remains responsible for execution and native artifacts; QRT adds lifecycle handling and report integration.

Classes

Name Description
LeanArtifactError Raised when a successful backtest did not produce a result artifact.
LeanBacktestResult Completed Lean backtest with preserved native artifact paths.
LeanBacktestRun A running Lean backtest with deterministic artifact ownership.
LeanCommandError Raised when a Lean CLI command exits unsuccessfully.
LeanCommandResult Terminal result of a general Lean CLI command.
LeanDependencyError Raised when the Lean CLI executable cannot be located.
LeanError Base class for Lean adapter failures.
LeanRun A running Lean CLI process.
LeanRunSpecification Immutable, JSON-serializable Lean command specification.
LeanRunState Lifecycle state for a Lean CLI process.
LeanTimeoutError Raised after a command exceeds its wait timeout and is terminated.
LeanValidationError Raised when a workspace or command input is invalid.

LeanArtifactError

bt.lean.LeanArtifactError()

Raised when a successful backtest did not produce a result artifact.

LeanBacktestResult

bt.lean.LeanBacktestResult(
    specification,
    state,
    returncode,
    stdout,
    stderr,
    started_at,
    ended_at,
    algorithm,
    output_directory,
    result_path,
    artifacts,
    parameters,
)

Completed Lean backtest with preserved native artifact paths.

Methods

Name Description
report Create a native QRT report from this run’s exact result JSON.
report
bt.lean.LeanBacktestResult.report(
    destination,
    *,
    asset_returns=None,
    asset_weights=None,
    title=None,
    description='',
)

Create a native QRT report from this run’s exact result JSON.

LeanBacktestRun

bt.lean.LeanBacktestRun(
    specification,
    *,
    algorithm,
    output_directory,
    parameters,
)

A running Lean backtest with deterministic artifact ownership.

Methods

Name Description
cancel Terminate this backtest and retain any artifacts already written.
wait Wait for LEAN and resolve this run’s exact native artifacts.
cancel
bt.lean.LeanBacktestRun.cancel(grace_period=5.0)

Terminate this backtest and retain any artifacts already written.

wait
bt.lean.LeanBacktestRun.wait(timeout=None, *, check=True)

Wait for LEAN and resolve this run’s exact native artifacts.

LeanCommandError

bt.lean.LeanCommandError(result)

Raised when a Lean CLI command exits unsuccessfully.

LeanCommandResult

bt.lean.LeanCommandResult(
    specification,
    state,
    returncode,
    stdout,
    stderr,
    started_at,
    ended_at,
)

Terminal result of a general Lean CLI command.

LeanDependencyError

bt.lean.LeanDependencyError()

Raised when the Lean CLI executable cannot be located.

LeanError

bt.lean.LeanError()

Base class for Lean adapter failures.

LeanRun

bt.lean.LeanRun(specification)

A running Lean CLI process.

Attributes

Name Description
state Return the current lifecycle state.
stderr Return stderr captured so far.
stdout Return stdout captured so far.

Methods

Name Description
cancel Terminate this command and return its cancelled result.
wait Wait for completion, optionally terminating after timeout seconds.
cancel
bt.lean.LeanRun.cancel(grace_period=5.0)

Terminate this command and return its cancelled result.

wait
bt.lean.LeanRun.wait(timeout=None, *, check=True)

Wait for completion, optionally terminating after timeout seconds.

LeanRunSpecification

bt.lean.LeanRunSpecification(workspace, executable, arguments)

Immutable, JSON-serializable Lean command specification.

Attributes

Name Description
command Return the complete argv passed to the operating system.

Methods

Name Description
to_dict Return a JSON-compatible representation.
to_json Serialize this specification to JSON.
to_dict
bt.lean.LeanRunSpecification.to_dict()

Return a JSON-compatible representation.

to_json
bt.lean.LeanRunSpecification.to_json(indent=2)

Serialize this specification to JSON.

LeanRunState

bt.lean.LeanRunState()

Lifecycle state for a Lean CLI process.

LeanTimeoutError

bt.lean.LeanTimeoutError(result)

Raised after a command exceeds its wait timeout and is terminated.

LeanValidationError

bt.lean.LeanValidationError()

Raised when a workspace or command input is invalid.

Functions

Name Description
backtest Launch a local LEAN backtest and return its asynchronous run handle.
init Create a workspace and run lean init in it synchronously.
run Launch whatever follows the lean command inside workspace.

backtest

bt.lean.backtest(
    workspace,
    algorithm,
    parameters=None,
    update_image=False,
    image=None,
    executable=None,
    output_root=None,
)

Launch a local LEAN backtest and return its asynchronous run handle.

init

bt.lean.init(
    workspace,
    organization=None,
    language=None,
    executable=None,
    timeout=None,
)

Create a workspace and run lean init in it synchronously.

run

bt.lean.run(command, *, workspace='.', executable=None)

Launch whatever follows the lean command inside workspace.

Examples

q.bt.lean.run("config get engine-image", workspace="lean/project")

Back to top