ApplePieIsGood
ApplePieIsGood

Reputation: 3731

Is there a way to build a C-like DLL from a Python module?

I have a Python module with nothing but regular global functions. I need to call it from another business-domain scripting environment that can only call out to C DLLs. Is there anyway to build my Python modules so that to other code it can be called like a standard C function that's exported from a DLL? This is for a Windows environment. I'm aware of IronPython, but as far as I know it can only build .NET Assemblies, which are not callable as C DLL functions.

Upvotes: 7

Views: 368

Answers (3)

S.Lott
S.Lott

Reputation: 391952

The standard solution is to embed the Python interpreter (which is already a C DLL) in your application.

https://docs.python.org/extending/windows.html#using-dlls-in-practice

http://docs.python.org/extending/embedding.html

Upvotes: 3

dirkgently
dirkgently

Reputation: 111200

Take a look at this Codeproject article. One way would be wrap your python functions in a C dll and expose this to the callee.

COM is a binary protocol to solve this issue. But you will have to wrap this python dll in a COM wrapper. And add some code on the calling side as well.

Upvotes: 6

Macke
Macke

Reputation: 25690

Py2exe can generate COM dlls from python code, by compiling and embedding python code + interpreter. It does not, AFAIK, support regular DLLs yet. For that, see dirkgently's answer about embedding python yourself.

Upvotes: 2

Related Questions