DotWrap 0.3.0
dotnet add package DotWrap --version 0.3.0
NuGet\Install-Package DotWrap -Version 0.3.0
<PackageReference Include="DotWrap" Version="0.3.0" />
<PackageVersion Include="DotWrap" Version="0.3.0" />
<PackageReference Include="DotWrap" />
paket add DotWrap --version 0.3.0
#r "nuget: DotWrap, 0.3.0"
#:package DotWrap@0.3.0
#addin nuget:?package=DotWrap&version=0.3.0
#tool nuget:?package=DotWrap&version=0.3.0
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 | Versions 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. |
-
net10.0
- DotWrap.Shared (>= 0.3.0)
-
net8.0
- DotWrap.Shared (>= 0.3.0)
-
net9.0
- DotWrap.Shared (>= 0.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.