.Net and Mono integration for Python
Project description
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
Release history Release notifications | RSS feed
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 hashes)
Built Distributions
Close
Hashes for pythonnet-2.2.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f712361625d0634e6fc75576e2dd0d3801ff99788901cc84742d2265c18a740 |
|
MD5 | 81cf6d990317cce0b2b1d8804515d996 |
|
BLAKE2-256 | 8bf0218609355ebea8848f666796bb8f886d5bf6205834c86a9e2118f6089d44 |
Close
Hashes for pythonnet-2.2.2-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46c1c4210e812e9c09bf9a4ca10fe9e9e4801054030eb17b40082c86c72c2fea |
|
MD5 | 90272f04a60f01a21eed749b341324bf |
|
BLAKE2-256 | f4063ff886bf7dc9ef45751ccf224e95e686f4534b1792abce9143769f11e1cb |
Close
Hashes for pythonnet-2.2.2-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47f9047d55c43ee5a39d18ea6daeedbeebe28add74ac90b08b7b6c66b05d1f38 |
|
MD5 | 1d7aff6fa079d9da78c6ffe319700dca |
|
BLAKE2-256 | c21b616ba08a2856537f511e052020dc2317213af031d88c8db361f26cc89f6a |
Close
Hashes for pythonnet-2.2.2-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59f6cfe980ab112dc512632d4271d1a7d86758809ab3e19d6ed5b81613fa67ca |
|
MD5 | d6c90a051474b5a18aa255da76cee646 |
|
BLAKE2-256 | efb30694741489285bafdcd8dcf105e26c3701c59cb9f0fbc274d007895d8bb9 |
Close
Hashes for pythonnet-2.2.2-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b75585bcdd478b3366735ad43035b2ae9a12a499dd02e4c9a9b575c071a40509 |
|
MD5 | 084bee95ee4d3ed80143d68ef77596d1 |
|
BLAKE2-256 | fecf91c27d239c07a3acc5ce4c483efc3e08c0608f9fd2b184dfc624e851ed33 |
Close
Hashes for pythonnet-2.2.2-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 340bb436bb7f65c6b014556dde14d2485cbe21e6b6b76182ea99664bc57cf218 |
|
MD5 | c2ea559359d0c124b2ae0fea718aa44a |
|
BLAKE2-256 | 19e099b424867423ef2df3ce6f93345eff94fab7a05fee8c8f568c7fbf6b6599 |
Close
Hashes for pythonnet-2.2.2-cp33-cp33m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d11819876b4d7db7232b4080f655ee1d446a96fb2d30e53e92d302c9589c3380 |
|
MD5 | 16e6caf7f43e75ffb9eab9d9e1bb0a6c |
|
BLAKE2-256 | 464fb34d4f318b604bb54fab34ff7d22edb67057ca14bc79aa9defe6e5a9c497 |
Close
Hashes for pythonnet-2.2.2-cp33-cp33m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31e162ff1c6ba153924b5d59077bc1430c795a8bb5198695f2a31cc5d3a42363 |
|
MD5 | 021202c49239454d7e37a1ca2d634828 |
|
BLAKE2-256 | 48356386e840d73222fe434f9c7231661c323f676bc0302546c07daf426c87f3 |
Close
Hashes for pythonnet-2.2.2-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82460185b3c7a77bfc7f7102646f626e1eea9c6060284f62751074cac02a49be |
|
MD5 | 945ebe7fefb3af1ca4f838bfe7fde106 |
|
BLAKE2-256 | 67ba3a092b33bec769763595b7a7ddab6a810d20714760f2a2bd7b4a4aaeafe3 |
Close
Hashes for pythonnet-2.2.2-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2de76d9a1071797eccc2316e43828a2dbd6406239037c0d868ea9f2f1201ba0f |
|
MD5 | 6b1f14d04cb6feca8184454dafd11e04 |
|
BLAKE2-256 | 170b0acd22b71f846ef7ae7b790ece43c1690c21e018256f38f7b257dab096f5 |