PyCon UK 2012: Create *beautiful* command-line interfaces with Python

Vladimir Keleshev · 175K views · 2012 · 24:15

Open on YouTube

Python, Ruby & scripting languagesTesting, debugging & developer toolstalk

Why Stack Overflow recommends it

Stack Overflow users link it when someone asks for a nicer alternative to argparse, optparse or Ruby's thor for Python command-line tools.

Recommended by 3 people across 3 different months, 2013 to 2014.

What it is

Vladimir Keleshev presents docopt at PyCon UK 2012, a library that builds a command-line parser from the help message you write by hand. The 24-minute talk covers why argparse and optparse feel clumsy and walks through docopt's approach to making CLIs clean and self-documenting.

What people said

Recommends Paolo · 2013-08 · Stack Overflow · on “What is python alternative to thor (ruby) for command line applications?”

Python offers natively (via standard library) two packages to create auto-documenting interfaces for command line tools: optparse [LINK] and argparse [LINK] . The docs says that optparse is deprecated and argparse replaces it, maintaining some backward compatibility where possible. Though, argparse is not so easy to use and 3rd-party libraries have been created. Have a look at docopt [LINK] and the video [this video] about it. cliff [LINK] is another possibility. To write line-oriented command interpreters you can find useful the Python cmd [LINK] module. I finally want to point out that docopt and cliff are not the Python alternative/s as you asked, but just the couple I found.

Recommends William Denman · 2013-11 · Stack Overflow · on “argparse: store_true and int at same time”

I haven't used argparse before. But recently I saw a presentation on docopt [this video] [LINK] that blew me away. Maybe give that a try?

Recommends Pablo Marin-Garcia · 2014-02 · Stack Overflow · on “perl add options in pod documentation from hash in GetOptions”

I ralize that your point of view is code first and document later the things that become stable. That is fair when you need to write twice docs and code. But nowadays that is not true. My recomendation for prototyping is write the manpage and use a module that create the code of the options for you. My favorite in perl and python is docopt [LINK] (and has implementations for many other languages). Here you can find the Perl Docopt [LINK] I asked about perl implementatios for docopt [LINK] long time ago in stackoverflow and I was pointed to the docopt [LINK] module and other options like Getopt::Euclid [LINK] , Getopt::Auto [LINK] and Getopt::AsDocumented [LINK] Related with your concern abou