In the previous post, I explained how to create a package.
Everyone also wants to use their package with command line so here the steps you can follow. The package we built named shortpath. The structure of our package was
/shortpath
shortpath/
__init__.py
shortpath.py
MANIFEST.in
README.rst
__init__.py
setup.py
Now add new script to it for accessing your package with command line
/shortpath
bin/
shortpath
…
shortpath script will have some code like
#!/usr/bin/env python import shortpath print shortpath.some_method()
Now we have to declare our command script in setup.py
setup( ... scripts=['bin/funniest-joke'], ... )
When we will be done with our installation of the package, setup tools will copy the script to our PATH and make the command available for general use.
$Â shortpath