I do not like the idea of ββa single file, because it becomes a load on the service. I would consider an approach similar to the one below.
I became a big fan of Python virtual environments because it allows you to synchronize your application dependencies from OS installation. Imagine a scenario in which the application you are about to distribute now uses the Python requests v1.0 package. After a while, you will create another application that you want to distribute using requests v2.3 . You may encounter version conflicts on a system where you want to install both applications side by side. Virtual environments solve this problem, as each application will have its own package location.
Creating a virtual environment is very simple. Once you have installed virtualenv , it is just a matter of startup, for example virtualenv /opt/application/env . You now have a python sandbox for your application. In addition, virtual environments are very easy to clean up, just delete the env directory and you're done.
To install the application in the environment you need the setup.py . Say your application uses requests v2.3.0 , your own code is in a package named acme , and your script is called phone_home . The structure of your catalog is as follows:
acme/ __init__.py models.py actions.py scripts/ phone_home setup.py
setup.py will look something like this:
from distutils.core import setup install_requires = [ 'requests==2.3.0', ] setup(name='phone_home', version='0.0.1', description='Sample application to phone home', author='John Doe', author_email=' john@doe.com ', packages=['acme'], scripts=['scripts/phone_home'], url='http://acme.com/phone_home', install_requires=install_requires, )
Now you can make a tarball from your project and place it however you want (your own web server, S3, etc.):
tar cvzf phone_home-0.0.1.tar.gz .
Finally, you can use pip to install your package into the created virtual environment:
/opt/application/env/bin/pip install http://acme.com/phone_home-0.0.1.tar.gz
Then you can run phone_home with:
/opt/application/env/bin/phone_home
Or create a symlink in / usr / local / bin to just call the script using phone_home :
ln -s /opt/application/env/bin/phone_home /usr/local/bin/phone_home
All the steps described above can be placed in a shell script that will make the process install one command.
And with minor changes, this approach works very well for development environments; for example, using pip to install / link to your development directory: pip install -e . where . refers to the current directory, and you should be in the project directory next to setup.py .
Hope this helps!