Python.NET lets Python code call .NET libraries and allows embedding Python inside .NET applications via the CLR. It supports Mono, .NET Framework, and .NET Core runtimes.
Overview
Python.NET is a package that links Python with the .NET Common Language Runtime. Python callers can import CLR namespaces like Python packages, load assemblies with clr.AddReference, and embed Python in .NET hosts.
On Linux and macOS the default runtime is Mono; on Windows it defaults to .NET Framework. When .NET Core is installed in a default location or the dotnet CLI is on PATH, loading CoreCLR uses PYTHONNETRUNTIME=coreclr or pythonnet.load("coreclr").
Embedding Python in .NET requires setting Runtime.PythonDLL or PYTHONNETPYDLL from version 3.0 onward, then PythonEngine.Initialize() and Py.GIL() guards around Python calls. Multi-threaded hosts can call PythonEngine.BeginAllowThreads().
The project ships on PyPI, conda-forge, and NuGet for Python and .NET consumers.
Key features
- Import CLR namespaces from Python
- Load .NET assemblies dynamically
- Embed Python in .NET apps
- Mono and .NET Framework defaults
- Optional .NET Core loading
- GIL-scoped Python calls
- PyPI, conda-forge, NuGet packages
- Cross-language scripting bridge
Use cases
- Calling .NET APIs from Python
- Scripting .NET apps with Python
- Using System libraries in Python code
- Hosting Python inside .NET services