Home

Awesome

<p align="center"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ewels/rich-click/main/docs/images/rich-click-logo-darkmode.png"> <img alt="rich-click logo" src="https://raw.githubusercontent.com/ewels/rich-click/main/docs/images/rich-click-logo.png"> </picture> </p> <p align="center"> <em>Richly rendered command line interfaces in click.</em> </p> <p align="center"> <img src="https://img.shields.io/pypi/v/rich-click?logo=pypi" alt="PyPI"/> <img src="https://github.com/ewels/rich-click/workflows/Test%20Coverage/badge.svg" alt="Test Coverage badge"> <img src="https://github.com/ewels/rich-click/workflows/Lint%20code/badge.svg" alt="Lint code badge"> </p>
<p align="center"> <a href="https://ewels.github.io/rich-click">Documentation</a>&nbsp&nbspยท&nbsp&nbsp<a href="https://github.com/ewels/rich-click">Source Code</a>&nbsp&nbspยท&nbsp&nbsp<a href="https://github.com/ewels/rich-click">Changelog</a> </p>

rich-click is a shim around Click that renders help output nicely using Rich.

The intention of rich-click is to provide attractive help output from Click, formatted with Rich, with minimal customisation required.

Features

Installation

pip install rich-click

Read the docs for all supported installation methods.

Examples

Simple Example

To use rich-click in your code, replace import click with import rich_click as click in your existing click CLI:

import rich_click as click

@click.command()
@click.option("--count", default=1, help="Number of greetings.")
@click.option("--name", prompt="Your name", help="The person to greet.")
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for _ in range(count):
        click.echo(f"Hello, {name}!")

if __name__ == '__main__':
    hello()

python examples/11_hello.py --help

Screenshot from examples/11_hello.py

More complex example

python examples/03_groups_sorting.py

Screenshot from examples/03_groups_sorting.py

Usage

This is a quick overview of how to use rich-click. Read the docs for more information.

There are a couple of ways to begin using rich-click:

Import rich_click as click

Switch out your normal click import with rich_click, using the same namespace:

import rich_click as click

That's it! โœจ Then continue to use Click as you would normally.

See examples/01_simple.py for an example.

Declarative

If you prefer, you can use RichGroup or RichCommand with the cls argument in your click usage instead. This means that you can continue to use the unmodified click package in parallel.

import click
from rich_click import RichCommand

@click.command(cls=RichCommand)
def main():
    """My amazing tool does all the things."""

See examples/02_declarative.py for an example.

rich-click CLI tool

rich-click comes with a CLI tool that allows you to format the Click help output from any package that uses Click.

To use, prefix rich-click to your normal command. For example, to get richified Click help text from a package called awesometool, you could run:

$ rich-click awesometool --help

Usage: awesometool [OPTIONS]
..more richified output below..

License

This project is licensed under the MIT license.