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.1

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.1
File Size Uploaded Provenance Actions
pythonnet-2.5.1.tar.gz 1.9 MB Without provenance Details for pythonnet-2.5.1.tar.gz

Built distributions (wheels)

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

Total release size: 2.7 MB

Release files / pythonnet-2.5.1.tar.gz

Download URL pythonnet-2.5.1.tar.gz
Size 1.9 MB
Tags Source
SHA-256 checksum
How to use checksums
b4e876e0ddb52c7ce187c1abf529ef1e419743af283fde9d5769c798cf4b078f
BLAKE2b-256 checksum
How to use checksums
193a058cee38730776bcecc2d3dd54fe50ac3f8c77077ba9dc10bb59e70549e2
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.1-cp38-cp38-win_amd64.whl

Download URL pythonnet-2.5.1-cp38-cp38-win_amd64.whl
Size 82.0 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
c1db9edf41489c1227746cf6382bd087e08b494632010a6bead92984f000a4bf
BLAKE2b-256 checksum
How to use checksums
45c3df81e58af5b1e327ee89bd6a6b2f07e349d604f8c67ff06aa2aad98aadbd
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.1-cp38-cp38-win32.whl

Download URL pythonnet-2.5.1-cp38-cp38-win32.whl
Size 82.0 kB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
71d5af9205a6f872e654b21a4f77fb2385aa9feff8760057c0518dc470f19d6f
BLAKE2b-256 checksum
How to use checksums
11e2e4ef3beab530e3c1dabf321b42f7b62da6b1f7a4722704b0a0727367c67a
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.1-cp37-cp37m-win_amd64.whl

Download URL pythonnet-2.5.1-cp37-cp37m-win_amd64.whl
Size 82.0 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
6bbf050084224d54da7aeb6a90f068e90ae4d3750248700aa0acab7d657df8cd
BLAKE2b-256 checksum
How to use checksums
66cc92687c78c6c2ff15d312282bb2eead32a98e3a721d429e10f12d7d5573ad
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.1-cp37-cp37m-win32.whl

Download URL pythonnet-2.5.1-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
93065007501edbe9a97dff1dbb041eeb8f3c1551d469070761b7a75c24308fa2
BLAKE2b-256 checksum
How to use checksums
01b60b4b949a872afbfcc9b1cec15920a41a061c5889d2d1343d5b9a5b83f0c7
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.1-cp36-cp36m-win_amd64.whl

Download URL pythonnet-2.5.1-cp36-cp36m-win_amd64.whl
Size 82.0 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
6b808b3278395f2a2b166844d6b23032f28cda22e5296d2e57a8ecd38cb0d554
BLAKE2b-256 checksum
How to use checksums
792107fe32571a63f9752a643883a795ab2b9ee8bcac1c0142b051c679c74e5c
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.1-cp36-cp36m-win32.whl

Download URL pythonnet-2.5.1-cp36-cp36m-win32.whl
Size 82.0 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
f0cd76232072b15bba4459cbf9475d81348065ac120e20c301d2593621dd0a76
BLAKE2b-256 checksum
How to use checksums
9b588f0f8874407fdcfb56eb5ca02d6b4e5f13f494869ac08d23361534ae6282
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.1-cp35-cp35m-win_amd64.whl

Download URL pythonnet-2.5.1-cp35-cp35m-win_amd64.whl
Size 82.0 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
faa3c2a90aadce92bfb28570830b498954243eb5c6907d41e9dcbd936ec9ca52
BLAKE2b-256 checksum
How to use checksums
65ade80fd5fc22aa7e6578fadee6f18bb9f92a4efcfda264bc556b42e4b358bb
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.1-cp35-cp35m-win32.whl

Download URL pythonnet-2.5.1-cp35-cp35m-win32.whl
Size 82.0 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
3555c3a1ed5e7359d156043e1b4a4db2c6ae90fad0e8c70547af01e76c86f374
BLAKE2b-256 checksum
How to use checksums
6d7d8127aa7facea268df4fddeab779fb3b36479eca3578375a4d416a7163c83
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.1-cp27-cp27m-win_amd64.whl

Download URL pythonnet-2.5.1-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
6fb41f0b9f3cd9a7ad581e6c817ad44e8ba7cd9ee4b91bbb7718fd85284b0c65
BLAKE2b-256 checksum
How to use checksums
531c1db3d9dfe3e6336d4132e1b123118baeb0124e64d0653f24bef2f7377b65
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.1-cp27-cp27m-win32.whl

Download URL pythonnet-2.5.1-cp27-cp27m-win32.whl
Size 81.5 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
5d1ec84c7d1ec9d31350383bb4832ef51a916e43cae11d7f7fc127985f62ab6c
BLAKE2b-256 checksum
How to use checksums
1ed74fe0d9bf7d6b74fb03607901877b34ae51c461a3883c5228426236ab75a4
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

Security for pythonnet 2.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.5.1 This release

11 release files No provenance

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