Building Command Line Tools in Python

04:00 PM - 04:25 PM on July 16, 2016, Room CR5

Erik Taubeneck

Audience level:


Do you often catch yourself opening a Python script, changing a couple variables at the top, and then running python Turn that script into a Command Line Tool! Learn how to use docopt to easily build a Command Line Tool, how to use pip to make your tool directly callable, and how this strategy can improve your code.


Python is often described as a wonderful scripting language, but these scripts often end up containing both the logic of a program and the input variables to the program. This can lead to a number of undesirable patterns: difficulty sharing tools with others, inconsistent version control tracking, and confusion over how to use the tool. Writing a Python script as a Command Line Tool forces the separation of the program logic from the input variables, and simplifies or eliminates most of these issues. Simple enough, except that writing Command Line Tools in Python is quite verbose and a bit cumbersome. docopt is an open source tool that simplifies the process of building a Command Line Tool from your Python script. This talk presents how to use docopt and best practices for building Command Line Tools in Python, how to use pip to share your tool and make it directly callable (myscript instead of python path/to/, and how to capitalize on the advantages of writing Command Line Tools.