Python Standard Library Options for CLIs
00:00 Now, implementing a command line interface in bare Python like I showed you how to do in the last section of this course is really hard, so you’ll be happy to know that there are many Python packages available that will help you build command line interfaces quickly and easily.
00:15 The first few that I’ll cover are the standard library options for command line interface building toolkits.
00:22
There are three standard library modules that are exposed in Python for command line interfaces. The first and the standard library’s recommended module is argparse
.
00:35
argparse
is great because it’s really robust and has a lot of configuration options. A lighter-weight option called getopt
, that you might be familiar with already if you use C, is also a good choice.
00:49
It just has a little bit more manual configuration. It’s a little bit less fully-featured, overall, than argparse
. There’s also a module called optparse
that was actually superseded by argparse
in Python 3.2, so it’s officially deprecated and no longer actually actively maintained, but it still is the basis for some other libraries—like click
, which I’ll talk about later—because it gives a little bit more leeway to the programmer in how they actually design the interface, whereas argparse
has some kind of opinionated positions on how the command line interface actually needs to be built. Next, I’ll give some demonstrations of argparse
and getopt
in Real Python code.
Become a Member to join the conversation.