Useful Python libraries 2 - Docopt

docopt is a command-line interface tool.

You know what's awesome? It's when the option parser is generated based on the beautiful help message that you write yourself! This way you don't need to write this stupid repeatable parser-code, and insavtead can write only the help message--the way you want it.

-source: readme

For me, that means attractive, sensible, and easy command-line interfaces that follow common syntax that anyone using Linux would be familiar with.

Installation

Like most Python packages, you can install with pip:

1
$ pip install docopt

However, docopt is also a self-contained module, which means you can just place it in the same folder as files requiring it and import directly:

1
$ wget https://github.com/docopt/docopt/blob/master/docopt.py

Usage

I'd normally put examples here, but the project's GitHub repo contains an examples directory with many useful examples. Restating those here would, besides being lazy copy-pasting, not nearly as useful as simply linking you there.