Over the last weeks, we've made significant strides to standardize and streamline our Python API to PEP8 for better conformance with modern standards. This change makes our Python API more intuitive for native Python users and improves the readability of algorithms.

The change was done by improving the technology that bridges LEAN and Python strategies, enabling backward-compatible use of the former CamelCase API and the new snake_case API versions of methods. The change had a negligible speed impact. 

To support client migration, we've ported the QuantConnect documentation to PEP8 so you can start writing your algorithm in the new API format immediately. The old API will continue to work as the underlying LEAN engine, and C# projects still use them. To migrate your strategy, use the following shortcuts for some examples:

# Before
# After

# Lowercase properties, underscore between words (snake case):
self.Portfolio[self.Securities[self.spy]].HoldingsValue 
self.portfolio[self.securities[self.spy]].holdings_value

# Snake case parameters:
self.AddEquity("SPY", extendedMarketHours=True)
self.add_equity("SPY", extended_market_hours=True)

# Capitalized constants, CamelCase classes:
if securityChanges == SecurityChanges.None:
if security_changes == SecurityChanges.NONE

# Snake case methods:
def OnData(self, data): 
def on_data(self, data):

# Lowercase methods, _prefix encouraged for private variables:
self.ema = self.EMA(symbol, 30, Resolution.Minute)
self._ema = self.ema(symbol, 20, Resolution.MINUTE)

# Snake case methods, and CamelCase classes:
self.AddUniverseSelection(ManualUniverseSelectionModel(symbols)) 
self.add_universe_selection(ManualUniverseSelectionModel(symbols))

Potential Name Conflicts

For some clients, there may be breaking changes to strategies that use the same variable names as the underlying C# API. For example, a lowercase "self.securities" was permitted before, but will now clash with the uppercase "self.Securities" collection. This may cause strange new errors in your project. 

Selecting Previous LEAN Build

To delay migration to PEP8, you can select the old version of the LEAN engine using the LEAN Version selector. This will be kept open for the next month to give you time to migrate your strategy. To select the old LEAN version, navigate to your project panel's "LEAN Engine" section and select the "master v16356". By default, all new projects are created on the master branch of LEAN and will use pep8 formatting (master v16357+).

Migration Script

We've written a Python research notebook that ports code to the new PEP8 standard and attached it to the discussion thread below. You can automatically rewrite the methods to the new APIs using this notebook.

In addition, we've invested heavily in standardizing our REST API across all its functions and updating the documentation to reflect the features we support. The new REST documentation will be published in the coming weeks as we finalize and ship the updates. If you depend on our REST API, reach out so we can give you advanced notice about the updates.

Thank you for your continued support; we're grateful to serve a truly excellent community. Happy coding!

Team @ QuantConnect