0

Recently, the company I work for has been modernizing their codebases to mostly Python. Last week, I was tasked with looking into converting a utility program we rely on to manage some USB devices. I was quick to discover this program is highly specialized and is likely impossible to covert to Python (nor do I want to attempt it if I'm being honest). I have access to the source code for this program.

This program runs on Linux and currently compiles to an executable, not a shared object (.so).

Is binding Python to this program something that can be reasonably done? If so, I've already looked into ctypes, cffi, cython, pybind11, and writing raw C bindings, but I am lost as to what the best approach would be. If not, there is no major loss--I'll just have to call the program via subprocess and parse its output.

Thank you for your time.

Julian_Orteil
  • 45
  • 1
  • 9
  • All the methods you mention allow you to make this kind of bindings. They are all reasonable choices, There is no best solution, each has its pros and cons. Ctypes is great if you handle simple types. Cython is great for C++ (handles classes, exceptions, etc.) and for numpy interactions. – Demi-Lune Mar 21 '22 at 15:10
  • @Demi-Lune Do you happen to have any resources I could study on binding executables then? Or would I have to compile the utility into a .so? – Julian_Orteil Mar 21 '22 at 16:01
  • I'd recommend to build a .so – Demi-Lune Mar 23 '22 at 08:26
  • If you really want to keep the exe (e.g. if it's relevant for the exe to continue living on its own), you'd need to decide on a way for python to communicate with the executable (Linux pipes if all interesting data is already printed out via stdout, otherwise [sockets](https://realpython.com/python-sockets/), but [there are many other interprocess communication modules](https://stackoverflow.com/questions/6920858/interprocess-communication-in-python). – Demi-Lune Mar 23 '22 at 08:32

0 Answers0