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.
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.
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
getopt in Real Python code.
Become a Member to join the conversation.