Call Python from .NET

Viewed 29771

I have some code written in Python which can not be transferred to a .NET language. I need to call one of these functions from my .NET WinForms application.

Now, I do it by starting the Python script as a separate process and pass parameters to it as command line arguments. It works, but I don't really like this solution. I'd like to improve it to a better one.

Is there any better way to call a function of a .py script from a .NET application? What is the best way to do it?

Note: IronPython is NOT an option for this Python script

6 Answers

PythonNet should help with this one. It enables you to call python code from C#.

A cleaner way is to expose the python script via a Flask REST API and consume that from your .NET Application. Don't forget to put proper authentication in place.

Related