Rich-Click

1.9.7 · active · verified Sat Mar 28

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

Install

Imports

Quickstart

This example demonstrates a basic rich-click CLI with options, a prompt, and an environment variable for an API key. Save it as `cli.py` and run `python cli.py --help` for rich-formatted output or `python cli.py --name World`.

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()

view raw JSON →