Tutorials

Custom libraries

Introduction

By default, only the libraries in the official LEAN Docker images can be referenced in your algorithms. However, the CLI also supports using custom libraries. This makes it possible to use a library that is not available in the official LEAN Docker images or to use a newer version of an existing library.

Custom C# libraries

Follow these steps to add custom libraries to your C# project:

  1. Find the name of the package that you want to add on NuGet.
  2. Open a terminal in the directory you ran lean init in.
  3. Run lean library add "My Project" Microsoft.ML to add the Microsoft.ML NuGet package to the project in ./My Project. Replace Microsoft.ML with the name of the package found in step 1.
    $ lean library add "My Project" Microsoft.ML
    Retrieving latest available version from NuGet
    Adding Microsoft.ML 1.5.5 to 'My Project/My Project.csproj'
    Restoring packages in 'My Project' to provide local autocomplete
    This command installs the latest version of the Microsoft.ML package. If you want to use a different version you can use the --version <value> option. Additionally, you can pass the --no-local flag to skip restoring the packages locally.

Follow these steps to remove custom libraries from your C# project:

  1. Open a terminal in the directory you ran lean init in.
  2. Run lean library remove "My Project" Microsoft.ML to remove the Microsoft.ML NuGet package from the project in ./My Project. Replace Microsoft.ML with the name of the library that you want to remove.
    $ lean library remove "My Project" Microsoft.ML
    Removing Microsoft.ML from 'My Project/My Project.csproj'
    Restoring packages in 'My Project'
    You can pass the --no-local flag to skip restoring the packages locally.

Additionally, you can also add or remove custom C# libraries by modifying the C# project file (the file ending with .csproj). This can be done manually or through your editor's built-in NuGet tooling if your editor has such a feature.

Custom Python libraries

Follow these steps to add custom libraries to your Python project:

  1. Find the name of the package that you want to add on PyPI.
  2. Open a terminal in the directory you ran lean init in.
  3. Run lean library add "My Project" altair to add the altair PyPI package to the project in ./My Project. Replace altair with the name of the package found in step 1.
    $ lean library add "My Project" altair
    Retrieving latest compatible version from PyPI
    Adding altair 4.1.0 to 'My Project/requirements.txt'
    Installing altair 4.1.0 in local Python environment to provide local autocomplete
    This command installs the latest version of the altair package that is compatible with Python 3.6 (which is what the official LEAN Docker images use). If you want to use a different version you can use the --version <value> option. Additionally, you can pass the --no-local flag to skip installing the package in your local Python environment.
  4. If you are using VS Code, restart your editor for autocomplete to start working on the new library.

Follow these steps to remove custom libraries from your Python project:

  1. Open a terminal in the directory you ran lean init in.
  2. Run lean library remove "My Project" altair to remove the altair PyPI package from the project in ./My Project. Replace altair with the name of the library that you want to remove.
    $ lean library remove "My Project" altair
    Removing altair from 'My Project/requirements.txt'

Additionally, you can also add or remove custom Python libraries by modifying the project's requirements.txt file. If you choose to do this, make sure that the library versions that you add to this file are compatible with Python 3.6, because that's what the official LEAN Docker images use.

You can also see our Videos. You can also get in touch with us via Chat.

Did you find this page helpful?

Contribute to the documentation: