or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

classes.mdcli.mdclick-api.mdconfiguration.mddecorators.mdindex.mdutilities.md
tile.json

tessl/pypi-rich-click

Format click help output nicely with rich

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/rich-click@1.8.x

To install, run

npx @tessl/cli install tessl/pypi-rich-click@1.8.0

index.mddocs/

Rich-Click

Rich-Click is a Python library that provides attractive help output from Click, formatted with Rich, with minimal customization required. It serves as a drop-in replacement for Click while enhancing command-line interfaces with rich text formatting, colors, and visual enhancements.

Package Information

  • Package Name: rich-click
  • Language: Python
  • Installation: pip install rich-click

Core Imports

import rich_click as click

Or use specific imports:

from rich_click import command, group, option, argument
from rich_click import RichCommand, RichGroup, RichContext
from rich_click import __version__

Version Information

__version__: str = "1.8.9"

Basic Usage

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()

Architecture

Rich-Click extends Click's architecture with Rich formatting capabilities:

  • Drop-in Replacement: Complete Click API compatibility via re-exports
  • Rich Enhancement: Enhanced classes (RichCommand, RichGroup, RichContext) with Rich formatting
  • Configuration System: Comprehensive styling through RichHelpConfiguration
  • Patching Capability: Monkey-patch existing Click applications
  • CLI Tool: Command-line utility to enhance external Click tools

Capabilities

Core Decorators

Essential decorators for creating rich-formatted Click commands and groups with enhanced help output and styling capabilities.

def command(name=None, cls=None, **attrs):
    """Create a rich-formatted command."""

def group(name=None, cls=None, **attrs):
    """Create a rich-formatted command group."""

def pass_context(f):
    """Pass RichContext to the decorated function."""

def rich_config(help_config=None, *, console=None):
    """Configure Rich settings for commands."""

Core Decorators

Rich Classes

Enhanced Click classes with rich formatting capabilities including command classes, context management, and configuration systems.

class RichCommand(click.Command):
    """Enhanced Click command with rich formatting."""

class RichGroup(click.Group):
    """Enhanced Click group with rich formatting."""

class RichContext(click.Context):
    """Enhanced Click context with Rich capabilities."""

class RichHelpConfiguration:
    """Comprehensive configuration for Rich help formatting."""

Rich Classes

Configuration and Styling

Comprehensive configuration system for customizing Rich-Click appearance, behavior, and styling with extensive options for colors, panels, tables, and text formatting.

class RichHelpConfiguration:
    # Style configuration
    style_option: str = "bold cyan"
    style_argument: str = "bold cyan"
    style_command: str = "bold cyan"
    # ... many more styling options
    
    # Behavior configuration
    show_arguments: bool = False
    show_metavars_column: bool = True
    text_markup: str = "ansi"
    # ... many more behavior options

Configuration

Click API Re-exports

Complete Click API re-exported for drop-in compatibility including all core classes, decorators, exceptions, types, and utility functions.

# Core classes
class Command: ...
class Group: ...
class Context: ...
class Option: ...
class Argument: ...

# Decorators
def option(*param_decls, **attrs): ...
def argument(*param_decls, **attrs): ...

# Exception classes
class ClickException(Exception): ...
class UsageError(ClickException): ...
class BadParameter(UsageError): ...

Click API

Utilities and Patching

Utility functions for patching existing Click applications and various helper functions for working with Rich-Click components.

def patch(rich_config=None):
    """Patch Click internals to use rich-click types."""

def truthy(o):
    """Check if string or other obj is truthy."""

class CommandGroupDict(TypedDict):
    """Specification for command groups."""

class OptionGroupDict(TypedDict):
    """Specification for option groups."""

Utilities

Command Line Interface

Rich-Click CLI tool for enhancing external Click applications with rich formatting without modifying their source code.

def main(ctx, script_and_args, output, errors_in_output_format, 
         suppress_warnings, rich_config, show_help):
    """Rich-click CLI command entry point."""

CLI Tool