Skip to main content

rich-click

Format click help output nicely with 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.

Screenshots

Native click help With rich-click

Installation

You can install rich-click from the Python Package Index (PyPI) with pip or equivalent.

python -m pip install rich-click

Usage

There are two main ways to set up rich-click formatting for your tool: monkey patching or declarative. Which you choose will depend on your use-case and your personal disposition!

Note that the intention is to maintain most / all of the normal click functionality and arguments. If you spot something that is missing once you start using the plugin, please create an issue about it.

The path of least typing

Monkey patching is probably bad and you should only use this method if you are a Responsible Developer. It's also good if you're lazy, as it requires very little typing.

Assuming that you're already using click, you only need to add three lines:

import rich_click
click.Command.format_help = rich_click.rich_format_help
click.Group.format_help = rich_click.rich_format_help

(if you're not click groups, only 2 lines!)

This overwrites the default click methods with those from the rich-click package. As such, no other changes are needed - just continue to use click as you would normally and it will use these custom methods to print your help output.

The good and proper way

If using monkey-patching in your project makes your palms sweaty and your pulse race, then you'll be pleased to know that you can also use rich-click in a nicely declarative and verbose manner:

import click
import rich_click

class RichClickGroup(click.Group):
    def format_help(self, ctx, formatter):
        rich_click.rich_format_help(self, ctx, formatter)
class RichClickCommand(click.Command):
    def format_help(self, ctx, formatter):
        rich_click.rich_format_help(self, ctx, formatter)

@click.group(cls=RichClickGroup)
@click.option('--debug/--no-debug', default=False)
def cli(debug):
    click.echo(f"Debug mode is {'on' if debug else 'off'}")

@cli.command(cls=RichClickCommand)
def sync():
    click.echo('Syncing')

(example based on the click docs)

Here we are making new Group and Command child classes that are based on click. We define our custom format_help() functions and then tell click to to use these classes with the cls argument.

Customisation

You can customise most things that are related to formatting. For example, to print the option flags in a different colour, use:

rich_click.core.STYLE_OPTION = "magenta"
Full list of config options
# Default colours
STYLE_OPTION = "bold cyan"
STYLE_SWITCH = "bold green"
STYLE_METAVAR = "bold yellow"
STYLE_USAGE = "yellow"
STYLE_USAGE_COMMAND = "bold"
STYLE_DEPRECATED = "red"
STYLE_HELPTEXT_FIRST_LINE = ""
STYLE_HELPTEXT = "dim"
STYLE_METAVAR = "bold yellow"
STYLE_OPTION_HELP = ""
STYLE_OPTION_DEFAULT = "dim"
STYLE_REQUIRED_SHORT = "red"
STYLE_REQUIRED_LONG = "dim red"
STYLE_OPTIONS_PANEL_BORDER = "dim"
ALIGN_OPTIONS_PANEL = "left"
STYLE_COMMANDS_PANEL_BORDER = "dim"
ALIGN_COMMANDS_PANEL = "left"
MAX_WIDTH = 100

# Fixed strings
DEPRECATED_STRING = "(Deprecated) "
DEFAULT_STRING = " [default: {}]"
REQUIRED_SHORT_STRING = "*"
REQUIRED_LONG_STRING = " [required]"
OPTIONS_PANEL_TITLE = "Options"
COMMANDS_PANEL_TITLE = "Commands"

# Behaviours
SKIP_ARGUMENTS = True

Contributing

Contributions and suggestions for new features are welcome, as are bug reports! Please create a new issue or better still, dive right in with a pull-request.

Credits

This package was put together hastily by Phil Ewels (@ewels), but the hard work was really done by Will McGugan (@willmcgugan) who not only is the author of Rich but also wrote the original code that this package is based on.

Metadata

Release files for rich-click 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rich-click 0.2.0
File Size Uploaded
rich-click-0.2.0.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rich-click 0.2.0
File Interpreter ABI Platform
rich_click-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.9 kB

Release files / rich-click-0.2.0.tar.gz

Download URL rich-click-0.2.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
08565fb374ab2b0189cb79fdbbdfcccddd74f4d4bacbef62a48d23ef24589eff
BLAKE2b-256 checksum
How to use checksums
345160667011f7c763a3243e97b7bff80082d59cd7648bdc2800b1531452fe92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release files / rich_click-0.2.0-py3-none-any.whl

Download URL rich_click-0.2.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62f131e2e22c2dffaf17d4f93c5e58dec408316e80bb27e9ba0153e5cbb8ffb1
BLAKE2b-256 checksum
How to use checksums
40a95da4db9b668c023202b8236603da98df4c507ed8ca9a489dc10f7d266375
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release history Release notifications | RSS feed

1.9.9

2 release files

1.9.8

2 release files

1.9.7

2 release files

1.9.6

2 release files

1.9.5

2 release files

1.9.4

2 release files

1.9.3

2 release files

1.9.2

2 release files

1.9.1

2 release files

1.9.0

2 release files

1.8.9

2 release files

1.8.8

2 release files

1.8.7

2 release files

1.8.6

2 release files

1.8.5

2 release files

1.8.4

2 release files

1.8.3

2 release files

1.8.2

2 release files

1.8.1

2 release files

1.8.0

2 release files

1.7.4

2 release files

1.7.3

2 release files

1.7.2

2 release files

1.7.1

2 release files

1.7.0

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5

2 release files

1.4

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.3.0

2 release files

This release

0.2.0 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page