Skip to main content

.Net and Mono integration for Python

Project description

appveyor shield travis shield license shield pypi package version python supported shield

Python for .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 for .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)) 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");
        dynamic sin = np.sin;
        Console.WriteLine(np.cos(np.pi*2));
        Console.WriteLine(sin(5));
        double c = np.cos(5) + sin(5);
        Console.WriteLine(c);
        /* this block is temporarily disabled due to regression
        dynamic a = np.array(new List<float> { 1, 2, 3 });
        dynamic b = np.array(new List<float> { 6, 5, 4 }, Py.kw("dtype", np.int32));
        Console.WriteLine(a.dtype);
        Console.WriteLine(b.dtype);
        Console.WriteLine(a * b); */
        Console.ReadKey();
    }
}

Output:

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

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.2.2.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

pythonnet-2.2.2-cp36-cp36m-win_amd64.whl (57.3 kB view details)

Uploaded CPython 3.6mWindows x86-64

pythonnet-2.2.2-cp36-cp36m-win32.whl (57.4 kB view details)

Uploaded CPython 3.6mWindows x86

pythonnet-2.2.2-cp35-cp35m-win_amd64.whl (57.3 kB view details)

Uploaded CPython 3.5mWindows x86-64

pythonnet-2.2.2-cp35-cp35m-win32.whl (57.4 kB view details)

Uploaded CPython 3.5mWindows x86

pythonnet-2.2.2-cp34-cp34m-win_amd64.whl (57.3 kB view details)

Uploaded CPython 3.4mWindows x86-64

pythonnet-2.2.2-cp34-cp34m-win32.whl (57.4 kB view details)

Uploaded CPython 3.4mWindows x86

pythonnet-2.2.2-cp33-cp33m-win_amd64.whl (57.3 kB view details)

Uploaded CPython 3.3mWindows x86-64

pythonnet-2.2.2-cp33-cp33m-win32.whl (57.4 kB view details)

Uploaded CPython 3.3mWindows x86

pythonnet-2.2.2-cp27-cp27m-win_amd64.whl (56.4 kB view details)

Uploaded CPython 2.7mWindows x86-64

pythonnet-2.2.2-cp27-cp27m-win32.whl (56.5 kB view details)

Uploaded CPython 2.7mWindows x86

File details

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

File metadata

  • Download URL: pythonnet-2.2.2.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pythonnet-2.2.2.tar.gz
Algorithm Hash digest
SHA256 1ea51b14a286eb54d5a71c7e2a408c59ba028418585e393732617518caf1a0d8
MD5 9b26f8600b03088a02d398eb728aca0f
BLAKE2b-256 82852db5319e610c8f2568bbd81c0e46fc39a0bfb44c2990e6b9b4dfc9b8e6b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pythonnet-2.2.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 5f712361625d0634e6fc75576e2dd0d3801ff99788901cc84742d2265c18a740
MD5 81cf6d990317cce0b2b1d8804515d996
BLAKE2b-256 8bf0218609355ebea8848f666796bb8f886d5bf6205834c86a9e2118f6089d44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pythonnet-2.2.2-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 46c1c4210e812e9c09bf9a4ca10fe9e9e4801054030eb17b40082c86c72c2fea
MD5 90272f04a60f01a21eed749b341324bf
BLAKE2b-256 f4063ff886bf7dc9ef45751ccf224e95e686f4534b1792abce9143769f11e1cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pythonnet-2.2.2-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 47f9047d55c43ee5a39d18ea6daeedbeebe28add74ac90b08b7b6c66b05d1f38
MD5 1d7aff6fa079d9da78c6ffe319700dca
BLAKE2b-256 c21b616ba08a2856537f511e052020dc2317213af031d88c8db361f26cc89f6a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pythonnet-2.2.2-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 59f6cfe980ab112dc512632d4271d1a7d86758809ab3e19d6ed5b81613fa67ca
MD5 d6c90a051474b5a18aa255da76cee646
BLAKE2b-256 efb30694741489285bafdcd8dcf105e26c3701c59cb9f0fbc274d007895d8bb9

See more details on using hashes here.

File details

Details for the file pythonnet-2.2.2-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for pythonnet-2.2.2-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 b75585bcdd478b3366735ad43035b2ae9a12a499dd02e4c9a9b575c071a40509
MD5 084bee95ee4d3ed80143d68ef77596d1
BLAKE2b-256 fecf91c27d239c07a3acc5ce4c483efc3e08c0608f9fd2b184dfc624e851ed33

See more details on using hashes here.

File details

Details for the file pythonnet-2.2.2-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for pythonnet-2.2.2-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 340bb436bb7f65c6b014556dde14d2485cbe21e6b6b76182ea99664bc57cf218
MD5 c2ea559359d0c124b2ae0fea718aa44a
BLAKE2b-256 19e099b424867423ef2df3ce6f93345eff94fab7a05fee8c8f568c7fbf6b6599

See more details on using hashes here.

File details

Details for the file pythonnet-2.2.2-cp33-cp33m-win_amd64.whl.

File metadata

File hashes

Hashes for pythonnet-2.2.2-cp33-cp33m-win_amd64.whl
Algorithm Hash digest
SHA256 d11819876b4d7db7232b4080f655ee1d446a96fb2d30e53e92d302c9589c3380
MD5 16e6caf7f43e75ffb9eab9d9e1bb0a6c
BLAKE2b-256 464fb34d4f318b604bb54fab34ff7d22edb67057ca14bc79aa9defe6e5a9c497

See more details on using hashes here.

File details

Details for the file pythonnet-2.2.2-cp33-cp33m-win32.whl.

File metadata

File hashes

Hashes for pythonnet-2.2.2-cp33-cp33m-win32.whl
Algorithm Hash digest
SHA256 31e162ff1c6ba153924b5d59077bc1430c795a8bb5198695f2a31cc5d3a42363
MD5 021202c49239454d7e37a1ca2d634828
BLAKE2b-256 48356386e840d73222fe434f9c7231661c323f676bc0302546c07daf426c87f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pythonnet-2.2.2-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 82460185b3c7a77bfc7f7102646f626e1eea9c6060284f62751074cac02a49be
MD5 945ebe7fefb3af1ca4f838bfe7fde106
BLAKE2b-256 67ba3a092b33bec769763595b7a7ddab6a810d20714760f2a2bd7b4a4aaeafe3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pythonnet-2.2.2-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 2de76d9a1071797eccc2316e43828a2dbd6406239037c0d868ea9f2f1201ba0f
MD5 6b1f14d04cb6feca8184454dafd11e04
BLAKE2b-256 170b0acd22b71f846ef7ae7b790ece43c1690c21e018256f38f7b257dab096f5

See more details on using hashes here.

Supported by

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