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 shim 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 customisation required.

Features

  • 🌈 Rich command-line formatting of click help and error messages
  • 💫 Nice styles be default, usage is simply import rich_click as click
  • 💻 CLI tool to run on other people's tools (prefix the command with rich-click)
  • 📦 Export help text as HTML or SVG
  • 🎁 Group commands and options into named panels
  • ❌ Well formatted error messages
  • 🔢 Easily give custom sort order for options and commands
  • 🎨 Extensive customisation of styling and behaviour possible

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

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 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.

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


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.8.0.dev3.tar.gz (36.4 kB view details)

Uploaded Source

Built Distribution

rich_click-1.8.0.dev3-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file rich-click-1.8.0.dev3.tar.gz.

File metadata

  • Download URL: rich-click-1.8.0.dev3.tar.gz
  • Upload date:
  • Size: 36.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for rich-click-1.8.0.dev3.tar.gz
Algorithm Hash digest
SHA256 331678bd662b77be55dc0a7476b7e6911adb803a5d5e771ba25dcd51854e8fcc
MD5 d05ec3c271341818ec7bfc52bb410880
BLAKE2b-256 104b84bbb6c69eca2115d1e20625aa0bc46a4fc2b6cb6de2103f11b9b6d64757

See more details on using hashes here.

File details

Details for the file rich_click-1.8.0.dev3-py3-none-any.whl.

File metadata

File hashes

Hashes for rich_click-1.8.0.dev3-py3-none-any.whl
Algorithm Hash digest
SHA256 6efd93f4a86abc888f6859caee02b4cdda924e61a09e79208251bb8fb39f6d24
MD5 f46a3a46ec0de12693c6b48b02f6f69e
BLAKE2b-256 2f6b6843b53f854e20c41041e62bdf69042f38b0b2092c7f00a81972ea8d35a2

See more details on using hashes here.

Supported by

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