https://github.com/quantconnect/quantconnect-stubs-generator
Automatically generate Python type stubs for QuantConnect's Lean
https://github.com/quantconnect/quantconnect-stubs-generator
Last synced: 10 months ago
JSON representation
Automatically generate Python type stubs for QuantConnect's Lean
- Host: GitHub
- URL: https://github.com/quantconnect/quantconnect-stubs-generator
- Owner: QuantConnect
- License: apache-2.0
- Created: 2020-06-14T09:19:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-05T22:45:39.000Z (about 1 year ago)
- Last Synced: 2025-02-18T06:03:50.157Z (about 1 year ago)
- Language: C#
- Homepage:
- Size: 360 KB
- Stars: 13
- Watchers: 4
- Forks: 9
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# QuantConnect Stubs Generator
[](https://github.com/QuantConnect/quantconnect-stubs-generator/actions?query=workflow%3ABuild)
[](https://pypi.org/project/quantconnect-stubs/)
[](https://pypi.org/project/quantconnect-stubs/)
QuantConnect Stubs Generator is a program which generates Python stubs based on the C# files in [QuantConnect/Lean](https://github.com/QuantConnect/Lean) and [dotnet/runtime](https://github.com/dotnet/runtime). These stubs can be used by editors to provide type-aware features like autocomplete and auto-imports in QuantConnect strategies written in Python.
## Installation
The latest version of the stubs can be installed by running `pip install --upgrade quantconnect-stubs`. Every time Lean is updated, a new version of the package is released containing the latest stubs (the same command can be used to update).
The stubs are tested to work well with PyCharm and VS Code in combination with the [Pylance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance) extension. They should also work with any other editor capable of indexing Python type stubs.
If type-aware features like autocomplete are not working after installing the package, make sure your editor supports indexing Python type stubs and is set up to index packages in the environment you installed the package into. Sometimes it may also help to restart your editor to make sure newly installed/updated packages are correctly indexed.
After installing the stubs, you can copy the following line to the top of every Python file to have the same imports as the ones that are added by default in the cloud:
```py
from AlgorithmImports import *
```
This line imports [all common QuantConnect members](https://github.com/QuantConnect/Lean/blob/master/Common/AlgorithmImports.py) and provides autocomplete for them.
## Development
To run the generator locally, clone the repository, `cd` into the QuantConnectStubsGenerator project and run `dotnet run `. Make sure `` points to a directory containing the [QuantConnect/Lean](https://github.com/QuantConnect/Lean) repository and `` points to a directory containing the [dotnet/runtime](https://github.com/dotnet/runtime) repository.
To run the unit tests, run `dotnet test` in the root of the project. To run the integration tests read the [`integration/README.md`](./integration/README.md) file.
### Using Dev Container
- Open VSCode, click "Reopen in Container Prompt"; Or use command pallete "Reopen in Container"
- After build and initial creation script completes, run VSCode launch option "Run Stubs Generator"
There is also a launch option for integration tests which works right out of the box in this dev container. Try option "Python Integration Tests"