DotNetPip 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DotNetPip --version 1.2.0
                    
NuGet\Install-Package DotNetPip -Version 1.2.0
                    
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="DotNetPip" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotNetPip" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="DotNetPip" />
                    
Project file
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 DotNetPip --version 1.2.0
                    
#r "nuget: DotNetPip, 1.2.0"
                    
#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 DotNetPip@1.2.0
                    
#: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=DotNetPip&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=DotNetPip&version=1.2.0
                    
Install as a Cake Tool

DotNetPip

NuGet downloads github

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# .csproj using <PythonPackageReference>. MSBuild automatically fetches and isolates wheels during dotnet 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# dynamic types—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>

  
  <PropertyGroup>
    <PythonRuntimeVersion>3.11.5</PythonRuntimeVersion>  
  </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>)          │
└────────────────────────────────────────────────────────┘

  1. Build Phase: When you run dotnet build, the DotNetPip MSBuild task inspects your <PythonPackageReference> items, fetches the wheels, and prepares a isolated local environment in your output directory.
  2. Runtime Phase: At application startup, PythonEngine initializes an embedded CPython instance inside the same process memory space, giving you direct, high-speed access to Python libraries.

TODO: Potential Practical Challenges

While this architectural proposal 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 full C-API/ABI changes between 3.x minor versions, so native extensions (PyTorch, NumPy) must match the embedded interpreter (e.g. a cp311 wheel with Python 3.11). The Stable ABI (abi3) is the opt-in subset that stays compatible across 3.x. CUDA builds add another axis: a wheel must also match the installed CUDA toolkit.

How to contribute

Contributions are welcome! Here are a few ways you can help support and grow the project:

  • Star the repository: Giving the project a star helps increase visibility and attract more contributors.
  • Share real-world samples: Code snippets, configuration examples, or real-life usage scenarios are highly appreciated and will be added to the sample library.
  • Submit Issues & Pull Requests: Bug reports, feature suggestions, and code updates are always welcome.
  • Spread the word: Sharing the project on social media or technical networks helps expand our reach.
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
1.3.0 121 10/25/2026
1.2.0 102 10/25/2026
1.1.0 102 10/25/2026
1.0.0 108 10/24/2026