DotWrap 0.3.0

dotnet add package DotWrap --version 0.3.0
                    
NuGet\Install-Package DotWrap -Version 0.3.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="DotWrap" Version="0.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotWrap" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="DotWrap" />
                    
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 DotWrap --version 0.3.0
                    
#r "nuget: DotWrap, 0.3.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 DotWrap@0.3.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=DotWrap&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=DotWrap&version=0.3.0
                    
Install as a Cake Tool

DotWrap

✨ What is DotWrap?

DotWrap is a tool that automatically generates Python wrappers for your .NET AOT projects.
Write your logic once in C#, publish with DotWrap, and you’ll get a ready-to-install Python package that feels completely native.

The generated Python package includes docstrings, type hints, and IntelliSense support, so you can consume your C# code in Python as if it were written there.


🛠 Basic Usage

Suppose you have a C# class you want to expose to Python:

using DotWrap;

namespace CoolCalc;

/// <summary>
/// Custom summary for cool calc calculator.
/// </summary>
[DotWrapExpose] // <-- mark with attribute for source generator discoverability
public class Calculator
{
    /// <summary>
    /// Adds two integers together.
    /// </summary>
    /// <param name="a">The first integer to add.</param>
    /// <param name="b">The second integer to add.</param>
    /// <returns>The sum of the two integers.</returns>
    public int Add(int a, int b) => a + b;
}

After you mark the classes you want to expose with the DotWrapExpose attribute, build and publish your project with:

dotnet publish -r linux-x64 # or win-x64, osx-arm64, etc.

DotWrap will automatically generate a Python package inside python-package-root, complete with docstrings and type hints:


# main.py (auto-generated by DotWrap)

class Calculator:
"""
Custom summary for cool calc calculator.
"""
def add(self, a: int, b: int) -> int:
    """
    Adds two integers together.

    :param a: The first integer to add.
    :param b: The second integer to add.
    :return: The sum of the two integers.
    """
    # implementation skipped for brevity

You can install and test it locally:

cd ./python-package-root
pip install .

Now use your C# code seamlessly from Python:

import cool_calc

calc = cool_calc.Calculator()
print(calc.add(2, 3)) # Output: 5

Read the Wiki for more examples and documentation

📦 Features of the Generated Python Package

When you wrap your .NET project with DotWrap, the resulting Python package has some important advantages:

  • No .NET runtime required – the wrapper is based on your AOT-compiled library, so end users only need Python.
  • Native speed – the wrapper is implemented as a CPython extension module for extremely low overhead.
  • Full type hints and docstrings – IntelliSense and autocomplete work out of the box.
  • Microsecond overhead – only ~0.3µs per call across the Python ↔ C# boundary.

<div align="center"> <h2>⭐️ If you like DotWrap, please give the project a star on GitHub! ⭐️</h2> <a href="https://github.com/connorivy/DotWrap/stargazers"> <img src="https://img.shields.io/github/stars/connorivy/DotWrap?style=social" alt="GitHub stars" /> </a> </div>

⚡ Performance

While DotWrap is primarily about portability and usability, it also adds almost no overhead when bridging Python and C#.

Our benchmarks show that just calling into C# and returning takes about 0.000000344 seconds (0.344 µs)—fast enough that you won’t notice the boundary between Python and C#.

And when you offload real work to C#, the performance gains can be dramatic. For example, these are the results of the sum primes benchmarks which sums all primes numbers below 500,000:

<table> <tr> <th>Implementation</th> <th>Result</th> <th>Time</th> </tr> <tr> <td><strong>Python 3.13</strong></td> <td>9914236195</td> <td>0.786 s</td> </tr> <tr> <td><strong>C# with .NET 10 (via DotWrap)</strong></td> <td>9914236195</td> <td>0.036 s</td> </tr> </table>

<p align="center"> <b>C# was <span style="color:#27ae60;">22x faster</span> than Python in this benchmark.</b> </p>


📦 Summary

  • Wrap your .NET AOT projects – DotWrap turns them into Python packages.
  • No runtime dependency – Generated packages are AOT-compiled, no .NET runtime needed.
  • Ease of use – Auto-generated packages with docstrings and type hints.
  • Native integration – CPython extension modules for low-overhead calls.
  • Performance – Just 0.3µs overhead per call, plus C# speed where it matters.

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.3.0 411 9/29/2025
0.2.3 113 9/26/2025
0.2.2 163 9/24/2025
0.2.1 109 8/23/2025
0.2.0 161 8/20/2025
0.1.2 160 8/19/2025
0.1.1 157 8/18/2025
0.1.0 129 8/17/2025
0.0.2 172 8/14/2025
0.0.1 166 8/12/2025