Command line scripts inside python packages are common. You can organise your package in such a way that when a user installs the package, the script will be available on their path.
If you had the greetings
package which had the command line script hello_world.py
.
greetings/
greetings/
__init__.py
hello_world.py
You could run that script by running:
python greetings/greetings/hello_world.py
However if you would like to run it like so:
hello_world.py
You can achieve this by adding scripts
to your setup()
in setup.py
like this:
from setuptools import setup
setup(
name='greetings',
scripts=['hello_world.py']
)
When you install the greetings package now, hello_world.py
will be added to your path.
Another possibility would be to add an entry point:
entry_points={'console_scripts': ['greetings=greetings.hello_world:main']}
This way you just have to run it like:
greetings