Skip to main content

pythonnet - Python.NET

Join the chat at https://gitter.im/pythonnet/pythonnet

appveyor shield travis shield codecov shield

license shield pypi package version conda-forge version python supported shield stackexchange shield

Python.NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers. It allows Python code to interact with the CLR, and may also be used to embed Python into a .NET application.

Calling .NET code from Python

Python.NET allows CLR namespaces to be treated essentially as Python packages.

import clr
from System import String
from System.Collections import *

To load an assembly, use the AddReference function in the clr module:

import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Form

Embedding Python in .NET

  • All calls to python should be inside a using (Py.GIL()) {/* Your code here */} block.

  • Import python modules using dynamic mod = Py.Import("mod"), then you can call functions as normal, eg mod.func(args).

  • Use mod.func(args, Py.kw("keywordargname", keywordargvalue)) or mod.func(args, keywordargname: keywordargvalue) to apply keyword arguments.

  • All python objects should be declared as dynamic type.

  • Mathematical operations involving python and literal/managed types must have the python object first, eg. np.pi * 2 works, 2 * np.pi doesn’t.

Example

static void Main(string[] args)
{
    using (Py.GIL())
    {
        dynamic np = Py.Import("numpy");
        Console.WriteLine(np.cos(np.pi * 2));

        dynamic sin = np.sin;
        Console.WriteLine(sin(5));

        double c = np.cos(5) + sin(5);
        Console.WriteLine(c);

        dynamic a = np.array(new List<float> { 1, 2, 3 });
        Console.WriteLine(a.dtype);

        dynamic b = np.array(new List<float> { 6, 5, 4 }, dtype: np.int32);
        Console.WriteLine(b.dtype);

        Console.WriteLine(a * b);
        Console.ReadKey();
    }
}

Output:

1.0
-0.958924274663
-0.6752620892
float64
int32
[  6.  10.  12.]

Resources

Information on installation, FAQ, troubleshooting, debugging, and projects using pythonnet can be found in the Wiki:

https://github.com/pythonnet/pythonnet/wiki

Mailing list

https://mail.python.org/mailman/listinfo/pythondotnet

Chat

https://gitter.im/pythonnet/pythonnet

.NET Foundation

This project is supported by the .NET Foundation.

Metadata

Release files for pythonnet 2.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pythonnet 2.5.0
File Size Uploaded
pythonnet-2.5.0.tar.gz 1.9 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for pythonnet 2.5.0
File
pythonnet-2.5.0-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
pythonnet-2.5.0-cp38-cp38-win32.whl CPython 3.8 CPython 3.8 Windows x86-32 Details
pythonnet-2.5.0-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
pythonnet-2.5.0-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details
pythonnet-2.5.0-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
pythonnet-2.5.0-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
pythonnet-2.5.0-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details
pythonnet-2.5.0-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details
pythonnet-2.5.0-cp27-cp27m-win_amd64.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-64 Details
pythonnet-2.5.0-cp27-cp27m-win32.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-32 Details

Total release size: 2.7 MB

Release files / pythonnet-2.5.0.tar.gz

Download URL pythonnet-2.5.0.tar.gz
Size 1.9 MB
Tags Source
SHA-256 checksum
How to use checksums
73279c283804b9c72906fc512522d87d4c2ae1654ff3572cc8a3fc980de2891a
BLAKE2b-256 checksum
How to use checksums
98805a44c553d8fc87e142c80ca96f9fff5ee61710965fe26708fec9c716042d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release files / pythonnet-2.5.0-cp38-cp38-win_amd64.whl

Download URL pythonnet-2.5.0-cp38-cp38-win_amd64.whl
Size 82.0 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
796bd77a21c50414e8b15816b05bb66c90ea636786d7cf96ea77c534f274e898
BLAKE2b-256 checksum
How to use checksums
3c5de44966ffb174bc8a7fe21d1e4d488997cc4bf4e81f55d442ba9c1f37cf8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release files / pythonnet-2.5.0-cp38-cp38-win32.whl

Download URL pythonnet-2.5.0-cp38-cp38-win32.whl
Size 82.0 kB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
df7819c23deed9b2541e5f4fd91dd69d6f286d174f284080498ede31f9aea4a5
BLAKE2b-256 checksum
How to use checksums
c08bacebd9b13a23f3d3b432f6922f009f6317a3c093a4b6b521e932f6e73018
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release files / pythonnet-2.5.0-cp37-cp37m-win_amd64.whl

Download URL pythonnet-2.5.0-cp37-cp37m-win_amd64.whl
Size 81.9 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
e8bb08c0058c5d42ecd47dc532b23d66089420ffe68ab4e75cea7820822b71f5
BLAKE2b-256 checksum
How to use checksums
192c65404ef224a1bbec67beefcd659f694fcc06aa159efd72f50f59e2f677e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release files / pythonnet-2.5.0-cp37-cp37m-win32.whl

Download URL pythonnet-2.5.0-cp37-cp37m-win32.whl
Size 81.9 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
0fff3addacaa82a26b1cebce8c8049dfebf7356e06cf4532074897f96a203495
BLAKE2b-256 checksum
How to use checksums
5db9302a18255b6b55d7f252bbe0bf29a9b2788e9ec860b3e7f779b3b03b9fb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release files / pythonnet-2.5.0-cp36-cp36m-win_amd64.whl

Download URL pythonnet-2.5.0-cp36-cp36m-win_amd64.whl
Size 81.9 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
585a170e8580528a3533944514895e462173067a5dfbb0784e5f49c45748ed83
BLAKE2b-256 checksum
How to use checksums
6a5da9bb0007337affddb7cd662d4ebde7b07e119a39f8a7010a55401efa77c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release files / pythonnet-2.5.0-cp36-cp36m-win32.whl

Download URL pythonnet-2.5.0-cp36-cp36m-win32.whl
Size 81.9 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
5501b6016dec7b12918d79d6fb75fedd13eec54c90447e1a063727a0379b1204
BLAKE2b-256 checksum
How to use checksums
f7fc4240299cb33acab0a6730919d2c2204bf98a0a5d945b6c72f410ca69d707
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release files / pythonnet-2.5.0-cp35-cp35m-win_amd64.whl

Download URL pythonnet-2.5.0-cp35-cp35m-win_amd64.whl
Size 81.9 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
0976a2a42a78c18e620d0626349e941e950d09e4591c13b3e00fd4effe4a9446
BLAKE2b-256 checksum
How to use checksums
ddbb3e0393c09907e9e25a55229d9f6dacc10d5335d1e41412cb6c253ab67e8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release files / pythonnet-2.5.0-cp35-cp35m-win32.whl

Download URL pythonnet-2.5.0-cp35-cp35m-win32.whl
Size 81.9 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
628fb08d948856a5ed238750e7a02d32f999a94c28cfae0cf83afb5b2db02812
BLAKE2b-256 checksum
How to use checksums
ae037176dca0b7b3260129769f3f0ca4936e194539a6d8557fe02c7fe0cceba5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release files / pythonnet-2.5.0-cp27-cp27m-win_amd64.whl

Download URL pythonnet-2.5.0-cp27-cp27m-win_amd64.whl
Size 81.5 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
fcf0ee24d3a2a41ca1f5a74dfed8581c992c1bd3f0d36ac0a9ec9f4c0abba31f
BLAKE2b-256 checksum
How to use checksums
e5a370e7b75d1f953a1faa48a5e48d0a48f0ebf58b2a45d4d4e14dded233c9c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release files / pythonnet-2.5.0-cp27-cp27m-win32.whl

Download URL pythonnet-2.5.0-cp27-cp27m-win32.whl
Size 81.4 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
c25605d2768c58de589fbe34a69f3dd91783d9e60d66bd543fd60effa224f3c1
BLAKE2b-256 checksum
How to use checksums
5914d9df8fed68df22e93d68ea6e946e6a6414a1ae28a992c86ec2c4c64033c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release history Release notifications | RSS feed

3.2.0

2 release files

3.1.0

3 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.5.1

11 release files

This release

2.5.0 This release

11 release files

2.4.0

9 release files

2.3.0

11 release files

2.2.2

11 release files

2.2.1

11 release files

2.1.0

9 release files

2.0.0

5 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page