DotNetPip 1.0.0
See the version list below for details.
dotnet add package DotNetPip --version 1.0.0
NuGet\Install-Package DotNetPip -Version 1.0.0
<PackageReference Include="DotNetPip" Version="1.0.0" />
<PackageVersion Include="DotNetPip" Version="1.0.0" />
<PackageReference Include="DotNetPip" />
paket add DotNetPip --version 1.0.0
#r "nuget: DotNetPip, 1.0.0"
#:package DotNetPip@1.0.0
#addin nuget:?package=DotNetPip&version=1.0.0
#tool nuget:?package=DotNetPip&version=1.0.0
DotNetPip
Run Python AI & Machine Learning models natively inside .NET 10 — zero microservices, zero HTTP overhead, zero configuration friction.
DotNetPip is an ultra-lightweight, in-process interoperability engine that embeds Python directly inside your C# applications. It lets you declare Python packages directly in your .csproj file just like standard NuGet packages, restoring and isolating them automatically during build time.
Installation
dotnet add package DotNetPip --version 1.0.0
Published on nuget.org.
Key Features
- In-Process Performance: Runs CPython embedded directly inside your .NET process via low-level native bindings. Eliminates gRPC/HTTP latency and extra server deployments.
- Declarative Package Management: Manage Python dependencies inside your C#
.csprojusing<PythonPackageReference>. MSBuild automatically fetches and isolates wheels duringdotnet build. - Zero-Copy Memory Access: Share large matrices, vectors, and PyTorch/NumPy tensors between C# and Python without copying bytes, using
Span<T>and the Python Buffer Protocol. - Natural C# Dynamic Syntax: Access any Python module, function, or class fluidly using C#
dynamictypes—no static wrappers or generated glue code required.
Quick Start
1. Declare Python packages in your .csproj
Add DotNetPip and your required Python packages directly to your project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetPip" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<PythonPackageReference Include="transformers" Version="4.35.0" />
<PythonPackageReference Include="torch" Version="2.1.0" />
</ItemGroup>
</Project>
2. Run Python models from C#
using DotNetPip;
// 1. Initialize the embedded Python engine
using var py = PythonEngine.CreateMinimalist();
// 2. Import Python AI libraries directly
dynamic transformers = py.Import("transformers");
dynamic pipeline = transformers.pipeline("sentiment-analysis");
// 3. Execute inference in-process
dynamic result = pipeline("Evaluating embedded AI performance in .NET 10");
Console.WriteLine(result);
How It Works
┌───────────────────────────────────────────────────────────┐
│ BUILD TIME │
│ .csproj (<PythonPackageReference>) │
│ └─► MSBuild Task downloads wheels & provisions env │
└─────────────────────────────┬─────────────────────────────┘
│
┌─────────────────────────────▼─────────────────────────────┐
│ RUNTIME │
│ C# (.NET 10) Process │
│ └─► Embedded CPython Engine (In-Memory) │
│ └─► Zero-Copy Data Sharing (Span<T>) │
└───────────────────────────────────────────────────────────┘
- Build Phase: When you run
dotnet build, theDotNetPipMSBuild task inspects your<PythonPackageReference>items, fetches the wheels, and prepares a isolated local environment in your output directory. - Runtime Phase: At application startup,
PythonEngineinitializes an embedded CPython instance inside the same process memory space, giving you direct, high-speed access to Python libraries.
TODO: Potential Practical Challenges
While the architectural vision is highly innovative, executing it comes with real-world engineering hurdles that we will need to navigate:
The Python Global Interpreter Lock (GIL): Standard CPython is single-threaded for CPU-bound Python bytecode due to the GIL. (Though modern Python versions support free-threaded builds, managing thread safety across .NET multi-threading and CPython state requires careful synchronization).
Native Binary Distribution: Bundling native Python dynamic libraries (python311.dll / .so) and ensuring they resolve correctly across Windows, Linux, and macOS deployment targets requires robust publishing scripts.
ABI Stability: CPython's C-API is stable across minor versions, but major version changes or third-party C-extensions (like PyTorch compiled with specific CUDA toolkits) can occasionally introduce binary compatibility edge cases.
Building the NuGet package
The package version comes from <Version> in DotNetPip/DotNetPip.csproj.
./scripts/pack.sh # macOS / Linux
./scripts/pack.ps1 # Windows / PowerShell
Packages are written to artifacts/. Publish to nuget.org as jaime_olivares:
export NUGET_API_KEY=<your-key>
./scripts/push.sh
Tag a release (for example v1.0.0) to pack and push from GitHub Actions (secret name: NUGET_API_KEY). The nupkg version is still the one in DotNetPip.csproj.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.