The Click Library
Create CLIs with decorators.
What Is Click?
Click is a popular third-party library for building command-line interfaces using decorators. It handles parsing, help text, prompts, and colors with very little code. Install it with pip install click.
import click
@click.command()
def hello():
click.echo('Hello from Click')
# hello() would run when called as a scriptclick.echo
Use click.echo() instead of print. It handles encoding issues and works smoothly with Click's color and redirection features.
import click
@click.command()
def greet():
click.echo('Welcome!')
All lessons in this course
- argparse Basics
- Subcommands and Options
- The Click Library
- Rich Terminal Output