0

I am currently interning at a place where they've asked me to make a standalone python program to do something (say X).
Now, that program is to be run by some commands sent by their proprietary software which is written in their proprietary language. Now the reason I'm saying proprietary so many times is because they aren't ready to take me anywhere near their code. I am just supposed to make a Python code that does X based on the input given by their software.

So is there a way I can make an API and wrap it around my code so as to let the software control it? Also I need to make the whole thing standalone (maybe an installer of some kind) so that they don't have to install Python and the accompanying modules (like opencv) just to run my script?

All I could get out of them was "there are dll files that will be calling your app and we want an executable"

  • 2
    Why do you need an API? Are command-line arguments not sufficient? – SiHa Jul 05 '16 at 09:01
  • https://en.wikipedia.org/wiki/Inter-process_communication – Sebastian Hoffmann Jul 05 '16 at 09:03
  • The answer to both of your questions (possible to define an interface, possible to make an executable/installer) is yes, you should go and do more research on both of them. – jonrsharpe Jul 05 '16 at 09:08
  • Command line arguments aren't good enough for them, they want an executable file. To clarify, I know that it can be done, but I don't know how to do it when I'm blind about the thing that's using my program. – Shileen Upadhyay Jul 05 '16 at 09:19
  • command line arguments can be given to an executable file. – syntonym Jul 05 '16 at 09:21
  • There are tools for this: [freeze](https://wiki.python.org/moin/Freeze) (from the stdlib) also pyinstaller and py2exe and probably many others. – Bakuriu Jul 05 '16 at 09:31

1 Answers1

0

Any programm can execute any other program (if it has the appropriate rights) so there is no real distinction between "python file" and "python executable" (that is because python is an interpreted language. The python source files and the "final python program" are "identical" (asuming cpython), in contrast to e.g. a C program where the source files and the executable are vastly different).

If you are on windows there is the additional problem that the user must have installed python to execute .py files. There are some ways to mitigate that problem - there are python libraries that "freeze" the python interpreter and your code into a single .exe file (from the comment by Bakuriu see e.g. freeze) . You could bundle the python interpreter with your code. You can just say your users to install python (if the amount of users is low that might be the good way).

"API" is just a fancy way of saying "this is how you communicate with my programm". This might be how you call a library (e.g. what functions a python module exports) or this might be an HTTP API or which command line arguments are passed or which protocoll over an TCP socket is spoken. Without knowing which API you are supposed to implement you cannot fulfill your job.

Without knowing further specifications (what inputdoes the other program give to yours, how does it call your programm?) it's very hard to say anything more helpful.

syntonym
  • 7,134
  • 2
  • 32
  • 45
  • Okay, this clears a lot of things. The system they're using is running Windows and a proprietary software. The software is supposed to send some arguments (like name, number etc) to my program and my program is supposed to return either text or image to the software. I'm using opencv library too and that would also have to be bundled along with my Python code. Does pyinstaller (or other such distutils) do that? – Shileen Upadhyay Jul 05 '16 at 09:37
  • How are the arguments sent? Are you supposed to program a library or an executable? How should the text/image be returned (encoding, or maybe a path to a image file?)? – syntonym Jul 05 '16 at 09:39
  • Bundling C libraries with a python application is alwayse a bit of a hassle, [this question](http://stackoverflow.com/questions/11477643/packaging-opencv-with-a-python-app) mentions cxfreeze. I couldn't quickly find information on pyinstaller and opencv but I guess if you dig a bit deeper you should find some information. – syntonym Jul 05 '16 at 09:42
  • I have no control over how the argument are sent to my code, I can just decide what arguments my code receives and tell them about it. The images will be stored locally and path will be returned. – Shileen Upadhyay Jul 05 '16 at 10:37
  • So you decide wether they are passed as commandline arguments or otherwise? In that case you can just decide what is easiest for you, so essentially you can "make up" an API, document it and give the documentation to them. – syntonym Jul 05 '16 at 10:40