SmartPythonRunner 1.0.1
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Framework 4.8
This package targets .NET Framework 4.8. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SmartPythonRunner --version 1.0.1
NuGet\Install-Package SmartPythonRunner -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SmartPythonRunner" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SmartPythonRunner" Version="1.0.1" />
<PackageReference Include="SmartPythonRunner" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SmartPythonRunner --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SmartPythonRunner, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SmartPythonRunner@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SmartPythonRunner&version=1.0.1
#tool nuget:?package=SmartPythonRunner&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SmartPythonRunner is a cross-platform .NET library that allows you to run Python scripts from any .NET project (Console, Web API, WinForms, WPF, Windows Services) even if Python is not installed on the system.
It supports automatic Python installation for Windows using the embeddable Python zip, and on Linux/macOS it uses the system-installed Python (python3).
Features
- Execute Python scripts from .NET projects.
- Run inline Python code without creating files manually.
- Automatically downloads and sets up Python on Windows if missing.
- Cross-platform support (Windows, Linux, macOS).
- Compatible with .NET Framework 4.8, .NET 6, .NET 7, .NET 8.
- Works in any project type: API, Console, WinForms, WPF, Services.
Installation
Using NuGet Package Manager
Install-Package SmartPythonRunner
```Using .NET CLI
dotnet add package SmartPythonRunner
```Run Inline Python Code
(`
using System;
using System.Threading.Tasks;
using SmartPythonRunner;
class Program
{
static async Task Main()
{
string code = @"print('Hello from Python!')
for i in range(3):
print(i)
";
int exitCode = await PythonRunner.RunScriptAsync(code);
Console.WriteLine($""Python exited with code {exitCode}"");
}
}
`)
```Run Python Script File
(`
using System.IO;
string scriptPath = @"C:\Scripts\myscript.py";
int exitCode = await PythonRunner.RunScriptAsync(File.ReadAllText(scriptPath));
`)
```Using in ASP.NET Web API
(`[ApiController]
[Route("api/[controller]")]
public class PythonController : ControllerBase
{
[HttpGet("run")]
public async Task<IActionResult> RunPythonScript()
{
string code = "print('Hello from API!')";
int exitCode = await SmartPythonRunner.PythonRunner.RunScriptAsync(code);
return Ok(new { ExitCode = exitCode });
}
}`)
##Notes
On Windows, if Python is not installed, the library automatically downloads a portable embeddable Python zip and runs it.
On Linux/macOS, ensure python3 is installed (e.g. sudo apt install python3 or brew install python3).
Fully asynchronous on .NET 6+; synchronous fallback on .NET Framework 4.8.
How It Works
Detects the platform (Windows/Linux/macOS).
Checks if Python is available (python or python3).
If Python is missing on Windows, downloads the embeddable zip from python.org.
Runs the script in a separate process using ProcessStartInfo.
Returns the exit code to indicate success/failure.
###Supported Frameworks
- .NET Framework 4.8
- .NET 6.0
- .NET 7.0
- .NET 8.0
###Works in:
- Console apps
- ASP.NET Web API / MVC
- WinForms / WPF
- Windows Services
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. 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 is compatible. 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 was computed. 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 was computed. 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 Framework | net48 is compatible. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.8
- System.IO.Compression.ZipFile (>= 4.3.0)
-
net6.0
- System.IO.Compression.ZipFile (>= 4.3.0)
-
net7.0
- System.IO.Compression.ZipFile (>= 4.3.0)
-
net8.0
- System.IO.Compression.ZipFile (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.