Video description
Build a robust Python CLI tool with argparseThe argparse
module is part of the Python standard library and meant to help you build robust command line tools. Once you need flags, switches, values, or positional arguments, it is very difficult to achieve that without using a framework.
In this case, argparse
can help build all you need to handle inputs in the terminal. We'll see how a single file named size.py
that calculates file sizes can make use of argparse
to handle the input in the terminal. Then, we will cover how error handling is done automatically when the expectations from argparse
aren't met. And finally, we'll go through some of the help menu options that construct the body of the help output.
Check the resources section for the GitHub repo with sample code
Why would you want to use argparseSince argparse
is part of the Python standard library, there is no need for you to define or install any external dependencies. You are ensuring that any Python installation in any system will work correctly out of the gate.
A very basic Python CLI tool without dependencies using the argparse module
Now that you know how to enhance a Python script into a more powerful one with argparse
, you can try out other frameworks like the Click framework or something much simpler by using the sys
module. I have examples and guides for the sys.argv module and for using the Click framework.
Table of contents
Product information
- Title: Robust Python CLI
- Author(s):
- Release date: February 2022
- Publisher(s): Pragmatic AI Solutions
- ISBN: 50129VIDEOPAIML
You might also like
video
Python command line one hour
Learn to build a Python CLI using Python Click from scratch as well as test it …
book
Python Command Line Tools
This book will teach you to master the ultimate UI, the command-line, using the powerful Click …
video
Python Command Line Tools Course
Python Command Line Tools Course This is a full Python CLI course that will take you …
video
Fast and Easy Python CLI
Build a very simple command line tool with Python without using external dependencies or frameworks. In …