Rich-Click
rich-click is a wrapper around Click that renders help output nicely using Rich. It provides attractive, color-formatted help text with minimal customization required, serving as a drop-in replacement for Click. The library is currently at version 1.9.7 and has an active development cycle with frequent releases.
Warnings
- breaking Rich-Click 1.9+ dropped support for Python 3.7, Click 7, and Rich versions 10/11. Ensure your environment uses Python 3.8+, Click 8+, and Rich 12+ for full compatibility and features.
- gotcha Rich formatting markup (e.g., '[red]') in help texts is disabled by default to maintain broad compatibility. It will render as plain text unless explicitly enabled.
- gotcha Minor Typer incompatibilities, such as default panel placements, have been addressed in recent versions. For optimal integration with Typer CLIs, ensure `rich-click[typer]` is installed.
- gotcha Subcommand discovery in help text had inconsistent behavior between versions 1.8 and 1.9.3. If using an affected version, subcommands might not display correctly.
- gotcha Early versions (prior to v1.9.5) experienced strange encoding issues on Windows environments, potentially leading to malformed help output.
- deprecated The 'groups' feature for organizing commands and options was superseded by the more intuitive 'Panels' API in rich-click 1.9. While old code might still function, 'Panels' offer more powerful customization.
Install
-
pip install rich-click -
pip install "rich-click[typer]"
Imports
- click
import rich_click as click
- RichCommand, RichGroup
from rich_click import RichCommand, RichGroup
Quickstart
import rich_click as click
import os
@click.command()
@click.option("--count", default=1, help="Number of greetings.")
@click.option("--name", prompt="Your name", help="The person to greet.")
@click.option(
"--api-key",
envvar="MY_APP_API_KEY",
help="API key for external service.",
default=os.environ.get('MY_APP_API_KEY', '')
)
def hello(count, name, api_key):
"""
A simple program that greets NAME for a total of COUNT times.
It also demonstrates an optional API key from an environment variable.
"""
if not api_key:
click.echo("[red]Warning:[/] No API key provided (set MY_APP_API_KEY environment variable).")
for _ in range(count):
click.echo(f"Hello, {name}!")
if __name__ == '__main__':
hello()