# QuantConnect Lean: an event-driven trading engine you run from a CLI

> Lean is QuantConnect's open source algorithmic trading engine, written in C# with first-class Python support. It is aimed at quant developers who want the same backtest and live code path, and the CLI is the recommended way in.

**QuantConnect/Lean** — Lean Algorithmic Trading Engine by QuantConnect (Python, C#)

- Repository: https://github.com/QuantConnect/Lean
- Website: https://lean.io
- Stars: 21,819 · Forks: 5,268
- Language: C#
- License: Apache-2.0
- Published: 2026-09-21 · Updated: 2026-09-21 · Language: en
- Canonical page: https://hysenlabs.com/projects/quantconnect-lean

## What Lean solves for quant developers

Most strategy code starts as a notebook and ends as a pile of scripts that only run on one machine. Lean's answer is a single event-driven engine that handles the loop you would otherwise write yourself: pull data, update indicators, call your strategy, route orders, fill them, and record the result. The repository describes it as an event-driven algorithmic trading platform with out-of-the-box alternative data and live-trading support.

The audience is narrow and specific. You need to be comfortable in Python or C#, because the engine is written in C# and ships algorithm directories for both languages (Algorithm.CSharp and Algorithm.Python sit at the top level). You also need to accept the engine's opinions about portfolio construction, risk and execution, or be willing to replace them. Lean is modular by design: the README states that each component is pluggable and that the project ships with models for all major plug-in points. That is the real selling point. The default models are a starting point, not a fixed pipeline, so a strategy that needs a custom fill model or a different position-sizing rule can be expressed without forking the engine.

What Lean is not is a hosted service. The repository is the engine and its tooling. Data acquisition, cloud backtests and brokerage credentials are separate concerns that the README links out to rather than bundles.

## The event loop, the algorithm factory and the plug-in points

The top-level layout tells you most of the architecture. Engine/ holds the core loop, Common/ holds shared types such as securities and orders, Algorithm/ and Algorithm.Framework/ hold the base algorithm classes and the framework models, Indicators/ holds the technical indicator library, and Brokerages/ holds the brokerage implementations. AlgorithmFactory/ decides which algorithm class to instantiate for a run, which is how the same launcher can execute a C# or Python strategy without a separate binary.

Data arrives through a provider layer. DownloaderDataProvider/ is a top-level directory, and the Dockerfile copies its build output into the image alongside the launcher, so a container can fetch data as part of a run. The engine consumes that data as timestamped events and pushes them through the algorithm's event handlers. In the framework style, the same stream feeds portfolio construction and risk models before orders reach an execution model.

The launcher is the entry point. Launcher/ builds to QuantConnect.Lean.Launcher.dll, and the Dockerfile sets the working directory to /Lean/Launcher/bin/Debug with an entrypoint of dotnet QuantConnect.Lean.Launcher.dll. Optimizer/ and Optimizer.Launcher/ sit alongside it, which is why parameter sweeps are a first-class command rather than something you script around the backtester. Report/ produces the backtest output.

One consequence worth stating plainly: because the engine is a .NET application, Python algorithms run inside a .NET host rather than in a CPython process you control. The README's own note about Python updates in the 2017 release line and the presence of mypy.ini and run_syntax_check.py in the repository suggest the Python surface is checked separately from the C# build, but the runtime is still the .NET one.

## Installing the Lean CLI and running a first backtest

The README is direct about the recommended path: for most users it strongly recommends the LEAN CLI, which is prebuilt and runs on all platforms. The CLI is a Python package, so the install is a single pip command.

```bash
pip install lean
```

After that, the CLI exposes project and run commands. Creating a project gives you starter code, which is the fastest way to see the shape of an algorithm before you write your own.

```bash
lean project-create
```

Backtesting runs the project locally through Docker, so Docker must be available on the machine before this command is useful.

```bash
lean backtest
```

The same pattern covers the other workflows the README lists: lean research starts a local Jupyter Lab environment in Docker, lean optimize runs a parameter sweep, and lean live starts live trading. The README points to a CLI cheat sheet for the full command list, which is where the flags for a given command live.

If you would rather build the engine itself, the README gives the alternative: download the latest master zip, or clone the repository and build it. On macOS the documented requirements are Visual Studio Code with the C# Dev Kit extension and the dotnet 10 SDK. From the command line the build is:

```bash
dotnet build
```

Running the built launcher is a separate step. The README documents changing into Launcher/bin/Debug and invoking the DLL:

```bash
cd Launcher/bin/Debug
dotnet QuantConnect.Lean.Launcher.dll
```

Note the macOS caveat in the README: Visual Studio for Mac has been discontinued and the documentation directs you to Visual Studio Code instead. The repository also ships a .devcontainer directory and Dockerfile, DockerfileJupyter, DockerfileLeanFoundation and DockerfileLeanFoundationARM, so container-based workflows are clearly the maintained path rather than an afterthought.

## Where Lean gets in your way

The Docker dependency is the first real constraint. The README's own command list couples lean backtest, lean research, lean optimize and lean live to Docker. If you cannot run Docker in your environment, the CLI route is closed and you are back to building the solution and running the launcher directly, which the README frames as the path for people who want to use their local IDE rather than the default.

The second constraint is the release cadence visible in the repository metadata. The most recent listed release is v2.4.0.1 from 2017-08-08, with v2.4.0.0 and v2.3.0.3 before it. Those tags are old, and the release titles describe features such as Python library support and Visual Studio integration. Meanwhile the last push to master was on 2026-09-18, so the code is moving even though the tagged releases are not. Anyone who pins to a release tag is pinning to something from 2017. In practice you track master or you use the CLI, and neither gives you the kind of versioned stability that a tagged release implies.

Third, Lean is not a data vendor. The engine consumes data; it does not guarantee you have the history you need for a given symbol or resolution. The DownloaderDataProvider is a component, not a subscription. A strategy that depends on alternative data has to source that data itself.

Finally, the README is thin on operational details. It documents installation and the CLI command surface, and it links to a forum and a Discord for debugging, but it does not document rollback, upgrade procedures between engine versions, or what changes when you move a backtested algorithm to lean live. Treat live deployment as something to validate against the brokerage documentation, not against the README.

## Lean against backtrader and Zipline

The closest comparisons are backtrader and Zipline, and the difference is where the engine sits in the stack. Backtrader is a Python library you import into your own process. You control the loop, you install it with pip into whatever environment you like, and there is no separate launcher, no Docker requirement and no C# runtime. Zipline follows a similar shape, with a Python API and its own data bundle conventions.

Lean inverts that. It is an application, not a library. You write an algorithm against its API and the launcher runs it. That buys you the framework models (portfolio construction, risk, execution) as replaceable components, a built-in optimizer, and a Docker image that packages the engine with its dependencies. It also buys you the constraints: a .NET host, a Docker dependency for the CLI workflows, and a build step if you want to run the engine directly.

The language split matters too. Backtrader and Zipline are Python-first, so a Python developer never leaves the interpreter. Lean is C#-first with Python support, which means Python algorithms run inside the .NET engine. If your team is pure Python and values that boundary, Lean asks you to give it up. If your team already runs .NET services, Lean fits without a translation layer.

## Licence, upgrades and what maintenance costs you

Lean is Apache-2.0. That is a permissive licence: you can use it commercially, modify it and redistribute it, provided you keep the licence and notices intact and state significant changes. Apache-2.0 also includes an explicit patent grant, which matters for a trading engine you might embed in a product. This is a description of the licence text, not legal advice; if you are redistributing Lean inside a commercial offering, have counsel read the LICENSE file at the repository root.

The maintenance picture is unusual. The repository is not archived and the last push to master was on 2026-09-18, so the codebase is being worked on. But the release history stops at 2017. That means the practical upgrade unit is a commit on master or a CLI package version, not a semantic release. There is no documented migration path between engine versions in the README, so an upgrade is a rebuild and a re-run of your regression tests rather than a changelog review. Budget for that: if you fork the engine to customize a model, you own the rebase.

The CLI package is versioned separately from the engine, which is worth knowing before you file a bug. A broken lean backtest may be a CLI issue, a Docker image issue or an engine issue, and the README routes debugging to the LEAN Forum and Discord rather than to a triage guide.

## Conclusion

Adopt Lean if you already write Python or C# strategies and want one engine for backtests and live deployment, with brokerage models you can replace. Do not adopt it if you expect a GUI or a managed data feed out of the box; the README points at the CLI and the cloud platform instead. Before committing, check the .vscode and .vs readme files for your IDE, confirm the dotnet 10 SDK requirement, and decide whether Docker is acceptable for research and live runs.

## FAQ

### What is QuantConnect Lean used for?

It is an event-driven algorithmic trading engine for backtesting and live trading algorithms across multiple financial markets. The repository ships algorithm projects in both C# and Python, along with an optimizer, a report generator and brokerage implementations.

### What is the Lean engine?

Lean is the engine itself: a modular, event-driven trading platform where each component is pluggable and the project ships with models for the major plug-in points. It handles the data, indicator, order and reporting loop that a strategy runs inside.

### Is QuantConnect Lean free?

The engine in this repository is open source under Apache-2.0, so you can build, modify and redistribute it under that licence. The README also links to a hosted cloud platform, and it does not describe what that service costs.

### What are the alternatives to QuantConnect Lean?

The README does not name alternatives. The meaningful distinction for a reader choosing between engines is architectural: Lean is an application with a launcher and a Docker-based CLI, whereas a Python library such as backtrader or Zipline is imported into your own process and leaves the loop under your control.

## Sources

- [License: Apache-2.0](https://github.com/QuantConnect/Lean/blob/master/LICENSE)
- [Project website](https://lean.io)
- [QuantConnect/Lean on GitHub](https://github.com/QuantConnect/Lean)
- [README](https://github.com/QuantConnect/Lean/blob/master/README.md)
- [Releases](https://github.com/QuantConnect/Lean/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/quantconnect-lean
