pythonnet

pythonnet: Connect Python with the .NET Runtime

Python.NET lets Python programs use .NET libraries and lets .NET applications embed Python. It suits developers integrating the two ecosystems, with runtime setup and Python’s thread and object-handling rules to account for.

View on GitHub Compare
Stars
5.5k
Forks
780
Stars, last 30 days
+13

Our take

Health score

62/100

How it is scored
Activity
54
Community
85
Issues
45
Pull requests
64

+13 stars in the last 30 days

  • More contributors than 77% of the projects we track
  • Slower to close issues than 80% of the projects we track

Project history

Daily GitHub snapshots since Oct 7, 2026. History covers stars and forks; health signals are not tracked historically.

Selected snapshot

Stars

5,539

Forks

779

Change since Nov 14, 2026: +1 stars·0 forks

Overview

Python.NET bridges Python and the .NET Common Language Runtime (CLR). Python code can load .NET assemblies and work with their namespaces and types, while .NET applications can initialize and call Python.

Use it when an application needs to combine existing Python packages or scripts with .NET code. It is an integration library rather than a standalone application, so developers need to manage runtime selection and, when embedding Python, initialization and the Global Interpreter Lock (GIL).

Key Features

  • Import CLR namespaces from Python as though they were Python packages.
  • Load .NET assemblies through clr.AddReference.
  • Select CoreCLR explicitly with pythonnet.load("coreclr") or PYTHONNET_RUNTIME=coreclr.
  • Embed Python in .NET applications through PythonEngine and Py.GIL().
  • Call Python modules, functions, and keyword arguments from C# using the provided Python object APIs.
  • Integrate Python libraries such as NumPy into .NET code.

Use Cases

  • .NET developers can embed Python scripts to add scripting or use Python libraries within an existing application.
  • Python developers can call CLR APIs or .NET libraries without moving their workflows out of Python.
  • Teams maintaining software across both ecosystems can build an integration layer between Python and .NET components.

Getting Started

Install the package with pip install pythonnet. See the README and Wiki for runtime setup, embedding instructions, installation details, and troubleshooting.

Considerations

  • Python.NET needs a compatible Python runtime and a CLR runtime. The README describes Mono and .NET Framework defaults, and how to select CoreCLR.
  • When embedding Python, configure the Python shared library using Runtime.PythonDLL or PYTHONNET_PYDLL before initialization.
  • Embedded Python calls must be made while holding the GIL. Multithreaded use may also require PythonEngine.BeginAllowThreads().
  • Some operations involving Python objects and managed or literal values are order-sensitive, as described in the README.

Found this useful?

Share it with someone who would like pythonnet.

Comparisons