Presenting commandr: an easy to use and automatic CLI builder for Python
Scripts are a big part of any code base, and if you’re like us, you have lots of them. Also, if you’re like us, you’re not too fond of writing Python optparse specifications. That’s why we created commandr, a tool for automatically converting a function’s signature into a command line interface, using just a decorator. We’ve found commandr so useful, we decided to open-source it!
commandr has a number of useful features:
It infers and casts types automatically from default values.
Documentation is automatically generated from each function’s signature and docstring.
Boolean parameters are automatically converted to flags, (e.g. –caps or –no_caps).
Commands can be grouped, making long lists of commands easy to read.
Here’s an example usage:
example.py
From the command line:
commandr_example.txt
Internally, we’ve combined commandr with fabric to allow functions to be invoked from our local command lines and executed on remote servers – just by adding a decorator. (Unfortunately, that part was too tightly integrated with the rest of the TellApart stack to release it here).
You can get commandr right from PyPI:
install_commandr.txt
Hopefully, you’ll find this tool as useful as we do!
Kevin Ballard is a Software Engineer at TellApart.
The Classifier