DotWrap 0.1.0
See the version list below for details.
dotnet add package DotWrap --version 0.1.0
NuGet\Install-Package DotWrap -Version 0.1.0
<PackageReference Include="DotWrap" Version="0.1.0" />
<PackageVersion Include="DotWrap" Version="0.1.0" />
<PackageReference Include="DotWrap" />
paket add DotWrap --version 0.1.0
#r "nuget: DotWrap, 0.1.0"
#:package DotWrap@0.1.0
#addin nuget:?package=DotWrap&version=0.1.0
#tool nuget:?package=DotWrap&version=0.1.0
DotWrap
Basic Usage
Suppose you have a c# class you want to call from Python:
using DotWrap;
namespace CoolCalc;
/// <summary>
/// A simple calculator class.
/// </summary>
[DotWrapExpose] // <-- mark with attr for source generator discoverablity
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;
}
Next publish you package with
dotnet publish -r linux-x64 (or win-x64)
That is all! A complete python package will be created in a new directory called python-package-root. The package is fully annotated with the comments and type hints taken from the original c# methods to enable intellisense for package users
# main.py (auto generated by DotWrap)
class Calculator:
"""
A simple calculator class.
"""
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 omitted for brevity
Use the following commands to test it locally
cd ./python-package-root
pip install .
From there you should be able to import your project and any exposed types.
import cool-calc
calc = cool-calc.Calculator()
result = calc.add(2, 3)
print(result) # Output: 5
🚀 Performance
Why use DotWrap? One word: performance.
In a real-world benchmark summing all primes below 500,000:
<table> <tr> <th>Implementation</th> <th>Result</th> <th>Time</th> </tr> <tr> <td><strong>Python</strong></td> <td>9914236195</td> <td>0.98 s</td> </tr> <tr> <td><strong>C# (via DotWrap)</strong></td> <td>9914236195</td> <td>0.04 s</td> </tr> </table>
<p align="center"> <b>C# was <span style="color:#27ae60;">24x faster</span> than Python!</b> </p>
<details> <summary>See benchmark output</summary>
Benchmarking Python sum_of_primes...
Python sum_of_primes: 9914236195 (Time: 0.982828s)
Benchmarking c# sum_of_primes...
c# sum_of_primes: 9914236195 (Time: 0.040921s)
C# implementation is 24.02 times faster than Python.
</details>
If you need to accelerate performance-critical code, DotWrap makes it easy to harness the speed of C# from Python.
DotWrap is a package that automatically generates Python packages by wrapping AOT-compiled .NET libraries.
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.1.0)
-
net8.0
- DotWrap.Shared (>= 0.1.0)
-
net9.0
- DotWrap.Shared (>= 0.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.