Skip to main content

Format click help output nicely with rich

Project description

rich-click logo

Richly rendered command line interfaces in click.

PyPI Test Coverage badge Lint code badge


Documentation  ·  Source Code  ·  Changelog


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

  • Click is a "Python package for creating beautiful command line interfaces".
  • Rich is a "Python library for rich text and beautiful formatting in the terminal".

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

Features

  • 🌈 Rich command-line formatting of click help and error messages
  • 😌 Same API as Click: usage is simply import rich_click as click
  • 🎨 Over 100 themes that can be set by developers and end-users (export RICH_CLICK_THEME=...)
  • 💻 CLI tool to run on other people's Click and Typer CLIs (prefix the command with rich-click)
  • 📦 Export help text as HTML or SVG
  • 🎁 Group commands and options into named panels
  • ❌ Well formatted error messages
  • 💫 Extensive customization
  • 🤖 IDE autocomplete of Click decorators for smooth developer experience

Installation

pip install rich-click

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

rich-click has a ton of customization options that let you compose help text however you'd like.

Below is a more complex example of what rich-click is capable of, utilizing themes and panels:

python examples/03_groups_sorting.py --help

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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rich_click-1.9.8.tar.gz (75.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rich_click-1.9.8-py3-none-any.whl (72.2 kB view details)

Uploaded Python 3

File details

Details for the file rich_click-1.9.8.tar.gz.

File metadata

  • Download URL: rich_click-1.9.8.tar.gz
  • Upload date:
  • Size: 75.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rich_click-1.9.8.tar.gz
Algorithm Hash digest
SHA256 4008f921da88b5d91646c134ec881c1500e5a6b3f093e90e8f29400e09608371
MD5 88d62d543fe64411b0fb6699fecc4971
BLAKE2b-256 f7ea21e4867ea0ef881ffd4c0550fc21a061435e50d6324bcd034396633cbc18

See more details on using hashes here.

File details

Details for the file rich_click-1.9.8-py3-none-any.whl.

File metadata

  • Download URL: rich_click-1.9.8-py3-none-any.whl
  • Upload date:
  • Size: 72.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rich_click-1.9.8-py3-none-any.whl
Algorithm Hash digest
SHA256 12873865396e6927835d4eabb1cc3996edcd65b7ac9b2391a29eca4f335a2f93
MD5 5ee07f205505fb6902c9392be08d5af5
BLAKE2b-256 6d97a87901aef6b7e7e4a34c6dd6cc17dca8594a592ef9d9dd765fca2b7facf7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page