Python CLI Scripts and Applications: Reference + Examples

Last updated:

WIP Alert This is a work in progress. Current information is correct but more content will probably be added in the future.

This short guide is aimed mainly at simple CLI applications in Python. For anything more complex than this, I recommend you use click.

Click is very nice and easy. See an example project here: Jekyll Utils


You can call any python as a regular executable script if you add this line to the top of the file:

#!/usr/bin/env python

Read command-line arguments

#!/usr/bin/env python

import sys

print 'This script was passed', len(sys.argv), 'arguments.'
print 'Arguments:', str(sys.argv)

See also

Dialogue & Discussion