Skip to content

Direct interop between Python and .NET assemblies via Microsoft C++/CLR and Boost.Python.

License

Notifications You must be signed in to change notification settings

sadhbh-c0d3/pydotnet

Repository files navigation

Py.NET (pip install dotnet)

Direct interop between Python and .NET assemblies via Microsoft C++/CLR and Boost.Python.

This is regular module for native Python (CPython), and it uses .NET runtime library (mscoree.dll) to natively support .NET assemblies.

No annotations required! You can load .NET assemblies just like that!

  • Load into Python any .NET assembly
  • Build .NET assembly directly in Python - no additional tools required!
  • Experiment with .NET libraries
  • Automate testing of .NET projects
  • Build control panels using powerful .NET libraries, and flexibility of Python

Watch

Watch My Video! Watch My Video!

Watch on Loom

Compatibility

Windows

PyDotnet only works on Windows due to integration with Microsoft .NET Framework (.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

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

About

Direct interop between Python and .NET assemblies via Microsoft C++/CLR and Boost.Python.

Resources

License

Stars

Watchers

Forks

Packages

No packages published