Python Interoperability with the Microsoft .NET Framework


License
MIT
Install
pip install dotnet==1.5.1

Documentation

PyDotNET (pip: dotnet)

(CPython) <==> (.NET) direct interop via embedded CLR (.pyd) through Boost.Python

Windows

PyDotnet only works on Windows due to integration with Microsoft .NET environment (.NetCore C++/CLI for Linux and MacOS - Is not supported)

Works natively on Windows 64-Bit (x86), and also on Windows on ARM64 in AMD64 emulation mode.

Mac

Works well on Windows on ARM64 on Apple Silicon: Parallels® Desktop 18 for Mac

Linux

Haven't tested, but this might work: Windows-Docker-Machine

Videos

Stay tuned! More to come...

Usage

Example

import dotnet.seamless
import System

from System.Collections.Generic import List

lst = List[Int32]()

lst.Add(1)
lst.Add(2)
lst.Add(3)

lst.AddRange([4,5,6])

lst.FindIndex(lambda x: x > 3)

Explanation

Import .NET seamless integration for CPython shell

import dotnet.seamless

Import .NET namespace

import System

Import type from .NET namespace

from System.Collections.Generic import List

Create an instance of .NET type. This shows also how to specialize .NET generic type

lst = List[Int32]()

Call instance method of .NET type. This also converts Python int into .NET Int32

lst.Add(1)
lst.Add(2)
lst.Add(3)

Call instance method of .NET type. This also converts Python list into .NET IEnumerable

lst.AddRange([4,5,6])

Call instance method of .NET type. Here Python lambda gets converted into .NET Predicate. The invocation jumps from Python into .NET CLR and calls back to Python lambda

lst.FindIndex(lambda x: x > 3)

Installation

pip install dotnet

Documentation

See https://github.com/sadhbh-c0d3/pydotnet/blob/main/SLIDES.md

Building

See https://github.com/sadhbh-c0d3/pydotnet/blob/main/BUILD.md