Format click help output nicely with rich
Project description
Richly rendered command line interfaces in click.
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
- 😌 Same API as Click: usage is simply
import rich_click as click
- 💫 Nice styles by default
- 💻 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()
Screenshot from examples/11_hello.py
More complex example
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
Built Distribution
File details
Details for the file rich_click-1.8.0.dev7.tar.gz
.
File metadata
- Download URL: rich_click-1.8.0.dev7.tar.gz
- Upload date:
- Size: 37.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29c418be25da0fec88a663b6298eb40de290f15a825799dd6c5715242b40d722 |
|
MD5 | 0ac87ddb86577d31c5d32ae869d29c30 |
|
BLAKE2b-256 | 96b196b7da48f2c4effc7c540e5937f66f70684d1ae8a03105a713393804038b |
File details
Details for the file rich_click-1.8.0.dev7-py3-none-any.whl
.
File metadata
- Download URL: rich_click-1.8.0.dev7-py3-none-any.whl
- Upload date:
- Size: 34.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30e2fc642b4b5b7abf89dfab8c00deb958c0ab3039bbd9d8cd16fd769cd1a9ca |
|
MD5 | de7aff4f11c68954623099f8bf5c9630 |
|
BLAKE2b-256 | f1d05f806019af45dadc5bc6ac07324be2d4c567a348615a1525c6298e6cd363 |