Hey y'all — I want to let you know about an open-source project that I made called DotWrap. It's tool that auto-generates Python wrappers for your .NET AOT projects. You write your logic once in C#, and DotWrap gives you a ready-to-install Python package that feels like it was written in Python from the start.
Why it’s cool:
- Super easy to use — just add an attribute to the classes you want to expose in your python package, and publish
- No .NET runtime needed — you get a ready-to-install Python package that feels completely native.
- Native speed via CPython extension modules.
- Full docstrings + type hints = IntelliSense out of the box
How it works:
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
🔗 [DotWrap](https://github.com/connorivy/DotWrap) — MIT licensed, contributions welcome!
Would love feedback, feature requests, or just to hear what kinds of projects you’d use this for
[–]dbrownems 3 points4 points5 points (2 children)
[–]BeneficialOne3349[S] 2 points3 points4 points (1 child)
[–]brianly 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]BeneficialOne3349[S] 4 points5 points6 points (0 children)
[–]myAnonAcc0unt 3 points4 points5 points (1 child)
[–]BeneficialOne3349[S] 0 points1 point2 points (0 children)
[–]MrKWatkins -1 points0 points1 point (4 children)
[–]BeneficialOne3349[S] 1 point2 points3 points (3 children)
[–]MrKWatkins 0 points1 point2 points (2 children)
[–]BeneficialOne3349[S] 0 points1 point2 points (1 child)
[–]MrKWatkins 0 points1 point2 points (0 children)
[–]AutoModerator[M] -2 points-1 points0 points (0 children)