
Explore the click library, a Python package for building beautiful command line interfaces with a composable design and minimal code, from basic programs to seo-like automation tasks.
Adam Mcquiston, instructor for Building Python CLI apps with Click, brings a polyglot software engineering background across full stack, devops, and cloud, with seven AWS certifications and tech writing.
learn to build Python CLI apps with the click framework, from setup and installation to creating commands, options, prompts, colors, and subcommands, including file handling, progress bars, and download tasks.
Create a click-based Python CLI by setting up a virtual environment, packaging with setup.py, and exposing a greetings command that runs the greet function.
Enable click in your python cli by annotating the greet function with a Click Command and replacing print with Click Echo. Access a help page that lists usage and options.
Add a mandatory name argument to the greetings command with click annotations, map it to the function parameter, and greet using an f-string.
Explore advanced argument usage in a Python Click CLI by adding add and subtract commands with explicit types, argument validation, and variable argument lists, including help and testing steps.
Learn how to use options with Click to pass information to commands, including optional options with defaults. Implement a language option (English or Spanish) with help text and input validation.
Use click's choice type to validate language options, reducing custom code and relying on built-in error messages. Define a predefined language list and set the default to English.
Explore typed options in click, including floats, integers, booleans, and file paths, with defaults and verbose flags, and learn how dash arguments map to underscores in Python function parameters.
Explore how to pass data to click commands using prompt options, including username and password prompts with hidden input and confirmation, demonstrated in an authentication command.
Learn to collect user input on demand with the click prompt function, including username prompts and secure password prompts with confirmation, then explore non-text inputs in future lectures.
Explore how to capture non-string input using click prompts and confirmations, including boolean confirmations and integer prompts, to enforce type checks in Python CLI apps.
Learn to build a click command note that accepts a file argument in append mode, prompts for lines, writes them to the file, and confirms when done.
Extend click file arguments with a canned cat command that accepts a variable number of input files, reads and concatenates their contents, and writes to an output file.
Explore grouped commands in click by building a notes command line interface with show, add, update, and delete using a group decorator, storing and displaying notes from a text database.
Learn to implement grouped click subcommands with shared context, hoisting setup logic to the parent entry point, and passing a context dictionary with notes data to subcommands.
Build a download command in a Python click app that uses a progress bar to fetch multiple URLs with requests and save content to local files from comma-separated pairs.
Explore advanced progress bar usage in click by specifying length, disabling ETA, and using an item show callback to display each downloading file name during web requests.
Style click-based Python command-line interface output with colored text using Click style and echo. Show foreground and background colors using color names and a color index modulo across greetings.
Test Python CLI apps built with Click using Seelye runner to validate an add command across normal, verbose, and very verbose modes, with correct exit codes and output.
Explore testing Python-based applications with click by using an isolated filesystem to create temporary directories and files, then validate a can cat command outputs combined contents.
Test click apps that prompt for user input by mocking prompts in the authenticate program, covering username, password, admin and non-admin paths, and logging in with a click testing runner.
This is a practical, example heavy, course on building Python based Command Line Interface (CLI) applications and utility programs. Such CLI programs are powerful tools used to automate a wide range of simple to complex tasks which frees users from repetitive mundane activities ultimately increasing productivity along with quality of work. The Click library featured in this course empowers Python software developers with the ability to build rich CLI tools while requiring significantly less code than what’s possible with the regular Python standard library or other programming languages.
After participating in this course viewers should have a strong grasp of building CLI programs that work with all common argument and parameter options types like string, numbers, flags and I/O sources. Students will also learn to collect user input in the form of plain text and hidden (aka masked) input prompts, compose nested programs with sub commands. To facilitate high quality software development practices emphasis is also placed on how to write automated tests with your CLI applications harnessing some very useful features of the Click library that simplify writing tests.
Below is a list of the topics that are covered in this course.
Setup and Install of Click CLI Applications
Single and Multiple Argument Programs
Using Options to Control CLI Program Behavior
Collecting User Input in the form of Prompts
Composing Nested Programs with Subcommands
Passing Shared Context Between Nested Commands
Implementing Progress Bars to Convey Work Completed
Styling CLI Program Output with Colored Text
Testing CLI Programs to Ensure Quality