Puerts.Python
3.0.2
Prefix Reserved
dotnet add package Puerts.Python --version 3.0.2
NuGet\Install-Package Puerts.Python -Version 3.0.2
<PackageReference Include="Puerts.Python" Version="3.0.2" />
<PackageVersion Include="Puerts.Python" Version="3.0.2" />
<PackageReference Include="Puerts.Python" />
paket add Puerts.Python --version 3.0.2
#r "nuget: Puerts.Python, 3.0.2"
#:package Puerts.Python@3.0.2
#addin nuget:?package=Puerts.Python&version=3.0.2
#tool nuget:?package=Puerts.Python&version=3.0.2
PuerTS — Python for .NET
PuerTS is a scripting solution that brings Python (CPython) to your .NET applications. It provides seamless C# interop — using the same unified ScriptEnv API as the JavaScript and Lua backends. Great for AI/ML integration, tooling, and rapid prototyping.
Features
- 🐍 CPython Powered — Run real Python code with full CPython runtime.
- 🔗 Seamless C# Interop — Call any .NET type directly from Python, and invoke Python functions from C#.
- 🤖 AI/ML Ready — Ideal for integrating Python-based AI/ML libraries with .NET applications.
- 🔄 Unified API — Same
ScriptEnvarchitecture as JS and Lua backends — easy to switch or mix languages.
Installation
Install via NuGet. The Complete package includes core + native assets for all desktop platforms:
dotnet add package Puerts.Python.Complete
Or install components separately for finer control:
# Core library (required)
dotnet add package Puerts.Core
# Python backend
dotnet add package Puerts.Python
# Native assets per platform (choose what you need)
dotnet add package Puerts.Python.NativeAssets.Win32
dotnet add package Puerts.Python.NativeAssets.Linux
dotnet add package Puerts.Python.NativeAssets.macOS
Supported Platforms
.net8.0+, .netstandard2.1
| Windows (x64) | Linux (x64) | macOS (arm64) | |
|---|---|---|---|
| Python | ✔️ | ✔️ | ✔️ |
Note: The macOS native assets currently support
osx-arm64only.Note: AOT compilation is not currently supported.
Quick Start
using Puerts;
var env = new ScriptEnv(new BackendPython());
// Execute Python code
env.Eval("print('Hello from Python!')");
// Eval with return value
int result = env.Eval<int>("1 + 2");
Console.WriteLine($"Python result: {result}"); // output: 3
env.Dispose();
Multi-line Code
Python is indentation-sensitive. For multi-line code blocks, wrap with exec('''...'''):
var env = new ScriptEnv(new BackendPython());
env.Eval(@"
exec('''
def greet(name):
print('Hello, ' + name + '!')
greet('PuerTS')
''')
");
// output: Hello, PuerTS!
env.Dispose();
Calling Python from C#
using Puerts;
using System;
var env = new ScriptEnv(new BackendPython());
// Get a Python lambda as a C# delegate
var add = env.Eval<Func<int, int, int>>("lambda a, b: a + b");
Console.WriteLine(add(10, 20)); // output: 30
// Define a function via exec, then retrieve it
env.Eval(@"
exec('''
def greet(name):
print('Hello,' + name + '!')
''')
");
var greet = env.Eval<Action<string>>("greet");
greet("PuerTS"); // output: Hello,PuerTS!
env.Dispose();
Key Differences from JS/Lua
| Feature | JavaScript | Lua | Python |
|---|---|---|---|
| Environment creation | new ScriptEnv(new BackendV8()) |
new ScriptEnv(new BackendLua()) |
new ScriptEnv(new BackendPython()) |
| Console output | console.log(...) |
print(...) |
print(...) |
| Multi-line code | Write directly | Write directly | Wrap with exec('''...''') |
| Accessing C# types | CS.Namespace.Class |
require('csharp') |
import Namespace.Class |
| Instance method calls | obj.Method() |
obj:Method() |
obj.Method() |
| Null representation | null / undefined |
nil |
None |
Documentation
For full documentation, tutorials and API reference, visit: https://puerts.github.io/en
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Puerts.Core (>= 3.0.2)
-
net10.0
- Puerts.Core (>= 3.0.2)
-
net8.0
- Puerts.Core (>= 3.0.2)
-
net9.0
- Puerts.Core (>= 3.0.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Puerts.Python:
| Package | Downloads |
|---|---|
|
Puerts.Python.Complete
Puerts is a library that makes it easy to add scripting to your .NET applications. It currently supports JavaScript (via V8/Nodejs/Quickjs) and Lua. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.2 | 138 | 4/2/2026 |
| 3.0.1 | 132 | 3/4/2026 |
| 3.0.0-beta1 | 410 | 12/8/2025 |