QuantConnect.pythonnet 2.0.16 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved

.NET 6.0
Install-Package QuantConnect.pythonnet -Version 2.0.16
dotnet add package QuantConnect.pythonnet --version 2.0.16
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.16" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add QuantConnect.pythonnet --version 2.0.16
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: QuantConnect.pythonnet, 2.0.16"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install QuantConnect.pythonnet as a Cake Addin
#addin nuget:?package=QuantConnect.pythonnet&version=2.0.16

// Install QuantConnect.pythonnet as a Cake Tool
#tool nuget:?package=QuantConnect.pythonnet&version=2.0.16
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

pythonnet is a package that gives .NET programmers ability to integrate Python engine and use Python libraries.

Embedding Python in .NET

  • You must set Runtime.PythonDLL property or PYTHONNET_PYDLL environment variable, otherwise you will receive BadPythonDllException (internal, derived from MissingMethodException) upon calling Initialize. Typical values are python38.dll (Windows), libpython3.8.dylib (Mac), libpython3.8.so (most other *nix). Full path may be required.
  • All calls to Python should be inside a using (Py.GIL()) {/* Your code here */} block.
  • Import python modules using dynamic mod = Py.Import("mod"), then you can call functions as normal, eg mod.func(args). You can also access Python objects via PyObject and dervied types instead of using dynamic.
  • Use mod.func(args, Py.kw("keywordargname", keywordargvalue)) or mod.func(args, keywordargname: keywordargvalue) to apply keyword arguments.
  • Mathematical operations involving python and literal/managed types must have the python object first, eg. np.pi * 2 works, 2 * np.pi doesn't.

Example

using var _ = Py.GIL();

dynamic np = Py.Import("numpy");
Console.WriteLine(np.cos(np.pi * 2));

dynamic sin = np.sin;
Console.WriteLine(sin(5));

double c = (double)(np.cos(5) + sin(5));
Console.WriteLine(c);

dynamic a = np.array(new List<float> { 1, 2, 3 });
Console.WriteLine(a.dtype);

dynamic b = np.array(new List<float> { 6, 5, 4 }, dtype: np.int32);
Console.WriteLine(b.dtype);

Console.WriteLine(a * b);
Console.ReadKey();

Output:

1.0
-0.958924274663
-0.6752620892
float64
int32
[  6.  10.  12.]

Resources

Information on installation, FAQ, troubleshooting, debugging, and projects using pythonnet can be found in the Wiki:

https://github.com/pythonnet/pythonnet/wiki

Mailing list https://mail.python.org/mailman/listinfo/pythondotnet Chat https://gitter.im/pythonnet/pythonnet

.NET Foundation

This project is supported by the .NET Foundation.

Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (26)

Showing the top 5 NuGet packages that depend on QuantConnect.pythonnet:

Package Downloads
QuantConnect.Common The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

QuantConnect LEAN Engine: Common Project - A collection of common definitions and utils

QuantConnect.Indicators The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

QuantConnect LEAN Engine: Indicators Project - A collection of financial indicators

QuantConnect.Algorithm.Framework The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

QuantConnect LEAN Engine: Algorithm.Framework Project - The core QCAlgorithm framework implementation

QuantConnect.Algorithm The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

QuantConnect LEAN Engine: Algorithm Project - Core QCAlgorithm implementation

QuantConnect.Algorithm.CSharp The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

QuantConnect LEAN Engine: Algorithm.CSharp Project - A collection of C# algorithm demonstrations for how to use the API

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on QuantConnect.pythonnet:

Repository Stars
QuantConnect/Lean
Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
Version Downloads Last updated
2.0.16 4,177 6/27/2022
2.0.15 4,466 5/17/2022
2.0.14 1,200 5/6/2022
2.0.13 665 5/2/2022
2.0.12 563 4/28/2022
2.0.11 14,485 12/27/2021
2.0.10 9,144 10/22/2021
2.0.9 235 10/21/2021
2.0.8 1,928 10/13/2021
2.0.7 495 10/8/2021
2.0.6 7,396 8/26/2021
2.0.5 8,590 7/14/2021
2.0.4 13,750 6/11/2021
2.0.3 726 6/8/2021
2.0.2 4,148 5/28/2021
2.0.1 10,972 3/13/2021
2.0.0 655 3/9/2021
1.0.5.30 110,661 3/31/2020
1.0.5.29 22,597 11/13/2019
1.0.5.28 432 11/12/2019
1.0.5.27 376 11/12/2019
1.0.5.26 4,123 10/15/2019
1.0.5.25 2,617 9/23/2019
1.0.5.24 3,253 9/10/2019
1.0.5.23 505 9/5/2019
1.0.5.22 415 9/5/2019
1.0.5.21 624 6/24/2019
1.0.5.20 19,656 4/23/2019
1.0.5.19 2,431 4/2/2019
1.0.5.18 633 3/27/2019
1.0.5.17 5,433 2/21/2019
1.0.5.16 497 2/20/2019
1.0.5.15 4,535 1/22/2019
1.0.5.14 626 1/18/2019
1.0.5.13 609 1/15/2019
1.0.5.12 5,206 8/27/2018
1.0.5.11 624 8/27/2018
1.0.5.10 655 8/24/2018
1.0.5.9 832 7/23/2018
1.0.5.8 19,184 7/16/2018
1.0.5.7 140,767 4/2/2018
1.0.5.6 850 4/2/2018
1.0.5.5 2,410 2/2/2018
1.0.5.4 2,130 12/29/2017
1.0.5.3 838 12/29/2017
1.0.5.2 1,225 11/29/2017
1.0.5.1 2,759 10/9/2017
1.0.5 943 9/29/2017
1.0.4.8 1,101 9/12/2017
1.0.4.7 731 9/8/2017
1.0.4.6 739 9/4/2017
1.0.4.5 752 8/21/2017
1.0.4.4 2,284 6/23/2017
1.0.4.3 808 6/23/2017
1.0.4.2 769 6/22/2017
1.0.4.1 759 6/22/2017
1.0.4 834 6/15/2017
1.0.3.5 1,221 6/1/2017
1.0.3.4 750 6/1/2017
1.0.3.3 746 6/1/2017
1.0.3.2 744 5/31/2017
1.0.3.1 776 5/31/2017
1.0.3 743 5/31/2017
1.0.2.1 872 5/25/2017
1.0.2 809 5/23/2017
1.0.1.1 1,345 4/11/2017
1.0.0 840 1/12/2017