Skip to main content

.Net and Mono integration for Python

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pythonnet-2.5.1.tar.gz (1.9 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pythonnet-2.5.1-cp38-cp38-win_amd64.whl (82.0 kB view details)

Uploaded CPython 3.8Windows x86-64

pythonnet-2.5.1-cp38-cp38-win32.whl (82.0 kB view details)

Uploaded CPython 3.8Windows x86

pythonnet-2.5.1-cp37-cp37m-win_amd64.whl (82.0 kB view details)

Uploaded CPython 3.7mWindows x86-64

pythonnet-2.5.1-cp37-cp37m-win32.whl (81.9 kB view details)

Uploaded CPython 3.7mWindows x86

pythonnet-2.5.1-cp36-cp36m-win_amd64.whl (82.0 kB view details)

Uploaded CPython 3.6mWindows x86-64

pythonnet-2.5.1-cp36-cp36m-win32.whl (82.0 kB view details)

Uploaded CPython 3.6mWindows x86

pythonnet-2.5.1-cp35-cp35m-win_amd64.whl (82.0 kB view details)

Uploaded CPython 3.5mWindows x86-64

pythonnet-2.5.1-cp35-cp35m-win32.whl (82.0 kB view details)

Uploaded CPython 3.5mWindows x86

pythonnet-2.5.1-cp27-cp27m-win_amd64.whl (81.5 kB view details)

Uploaded CPython 2.7mWindows x86-64

pythonnet-2.5.1-cp27-cp27m-win32.whl (81.5 kB view details)

Uploaded CPython 2.7mWindows x86

File details

Details for the file pythonnet-2.5.1.tar.gz.

File metadata

  • Download URL: pythonnet-2.5.1.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pythonnet-2.5.1.tar.gz
Algorithm Hash digest
SHA256 b4e876e0ddb52c7ce187c1abf529ef1e419743af283fde9d5769c798cf4b078f
MD5 4bd4bc10240e4447722243167045c55b
BLAKE2b-256 193a058cee38730776bcecc2d3dd54fe50ac3f8c77077ba9dc10bb59e70549e2

See more details on using hashes here.

File details

Details for the file pythonnet-2.5.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pythonnet-2.5.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 82.0 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for pythonnet-2.5.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c1db9edf41489c1227746cf6382bd087e08b494632010a6bead92984f000a4bf
MD5 fc274e099ecbbb421be0214a6f36048c
BLAKE2b-256 45c3df81e58af5b1e327ee89bd6a6b2f07e349d604f8c67ff06aa2aad98aadbd

See more details on using hashes here.

File details

Details for the file pythonnet-2.5.1-cp38-cp38-win32.whl.

File metadata

  • Download URL: pythonnet-2.5.1-cp38-cp38-win32.whl
  • Upload date:
  • Size: 82.0 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using 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

File hashes

Hashes for pythonnet-2.5.1-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 71d5af9205a6f872e654b21a4f77fb2385aa9feff8760057c0518dc470f19d6f
MD5 729d510557978db2f8aed3af3e662b58
BLAKE2b-256 11e2e4ef3beab530e3c1dabf321b42f7b62da6b1f7a4722704b0a0727367c67a

See more details on using hashes here.

File details

Details for the file pythonnet-2.5.1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pythonnet-2.5.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 82.0 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for pythonnet-2.5.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 6bbf050084224d54da7aeb6a90f068e90ae4d3750248700aa0acab7d657df8cd
MD5 3fd23fc2f6ce852957f59342f14909ce
BLAKE2b-256 66cc92687c78c6c2ff15d312282bb2eead32a98e3a721d429e10f12d7d5573ad

See more details on using hashes here.

File details

Details for the file pythonnet-2.5.1-cp37-cp37m-win32.whl.

File metadata

  • Download URL: pythonnet-2.5.1-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 81.9 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using 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

File hashes

Hashes for pythonnet-2.5.1-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 93065007501edbe9a97dff1dbb041eeb8f3c1551d469070761b7a75c24308fa2
MD5 d88d881ac40062c71ef653759c5e7a19
BLAKE2b-256 01b60b4b949a872afbfcc9b1cec15920a41a061c5889d2d1343d5b9a5b83f0c7

See more details on using hashes here.

File details

Details for the file pythonnet-2.5.1-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: pythonnet-2.5.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 82.0 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for pythonnet-2.5.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 6b808b3278395f2a2b166844d6b23032f28cda22e5296d2e57a8ecd38cb0d554
MD5 089fa4343f691967b710a02fa8baa3ff
BLAKE2b-256 792107fe32571a63f9752a643883a795ab2b9ee8bcac1c0142b051c679c74e5c

See more details on using hashes here.

File details

Details for the file pythonnet-2.5.1-cp36-cp36m-win32.whl.

File metadata

  • Download URL: pythonnet-2.5.1-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 82.0 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using 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

File hashes

Hashes for pythonnet-2.5.1-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 f0cd76232072b15bba4459cbf9475d81348065ac120e20c301d2593621dd0a76
MD5 f6c1aa61b4e3bbc3733c508b6bac7f72
BLAKE2b-256 9b588f0f8874407fdcfb56eb5ca02d6b4e5f13f494869ac08d23361534ae6282

See more details on using hashes here.

File details

Details for the file pythonnet-2.5.1-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: pythonnet-2.5.1-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 82.0 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for pythonnet-2.5.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 faa3c2a90aadce92bfb28570830b498954243eb5c6907d41e9dcbd936ec9ca52
MD5 40566a5715c3dc355c5ba5a26861606d
BLAKE2b-256 65ade80fd5fc22aa7e6578fadee6f18bb9f92a4efcfda264bc556b42e4b358bb

See more details on using hashes here.

File details

Details for the file pythonnet-2.5.1-cp35-cp35m-win32.whl.

File metadata

  • Download URL: pythonnet-2.5.1-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 82.0 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using 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

File hashes

Hashes for pythonnet-2.5.1-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 3555c3a1ed5e7359d156043e1b4a4db2c6ae90fad0e8c70547af01e76c86f374
MD5 df768db32af213e6a821044ca1576a53
BLAKE2b-256 6d7d8127aa7facea268df4fddeab779fb3b36479eca3578375a4d416a7163c83

See more details on using hashes here.

File details

Details for the file pythonnet-2.5.1-cp27-cp27m-win_amd64.whl.

File metadata

  • Download URL: pythonnet-2.5.1-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 81.5 kB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for pythonnet-2.5.1-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 6fb41f0b9f3cd9a7ad581e6c817ad44e8ba7cd9ee4b91bbb7718fd85284b0c65
MD5 a5d0bf50588156bc822e4ca64fa92cad
BLAKE2b-256 531c1db3d9dfe3e6336d4132e1b123118baeb0124e64d0653f24bef2f7377b65

See more details on using hashes here.

File details

Details for the file pythonnet-2.5.1-cp27-cp27m-win32.whl.

File metadata

  • Download URL: pythonnet-2.5.1-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 81.5 kB
  • Tags: CPython 2.7m, Windows x86
  • Uploaded using 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

File hashes

Hashes for pythonnet-2.5.1-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 5d1ec84c7d1ec9d31350383bb4832ef51a916e43cae11d7f7fc127985f62ab6c
MD5 10730e3bd0a08da4024faa7b30aecaca
BLAKE2b-256 1ed74fe0d9bf7d6b74fb03607901877b34ae51c461a3883c5228426236ab75a4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page