Backtrader is an open-source Python backtesting library. You install it once with pip install backtrader, then every script starts with import backtrader as bt.
The conductor is called Cerebro: you create cerebro = bt.Cerebro(), give it data with adddata(), a strategy with addstrategy(), then launch cerebro.run().
During run(), Cerebro replays history bar after bar: at each bar your strategy only sees the past, just like in real conditions.
run() returns a list of the strategies that ran: strat = cerebro.run()[0] gives you your strategy after the test, for example to read its analyzers.
Examples
CERE-X (fictional market) : The vertical line shows where Cerebro is: on the left, the bars already replayed; on the right, those your strategy does not know yet. run() moves forward like this up to the last bar.
Backtrader, an open-source project : Backtrader was created by developer Daniel Rodriguez and published as open source on GitHub under the GPL v3 licence. Anyone can read its code and check how the engine actually executes orders.
Key terms
Cerebro
Backtrader’s engine that brings together data, strategy and broker