Rich Argparse
rich-argparse provides beautiful, Rich-powered help formatters for Python's argparse and optparse modules. It enhances the standard help output with syntax highlighting, improved layout, and the ability to include Rich renderables like Markdown and tables in descriptions and epilogs. The current version is 1.7.2, and it maintains an active release cadence with regular updates.
Warnings
- breaking In version 2.0, Rich markup will become opt-in instead of opt-out. Existing code relying on automatic markup parsing in descriptions and help messages will need to explicitly enable it.
- breaking Python 3.8 support will be dropped in version 2.0. The last release to officially support Python 3.8 is 1.7.0. Future versions will require Python 3.9 or newer.
- gotcha On Python 3.14.0a7+ (nightly builds), versions of rich-argparse prior to 1.7.1 could raise a `TypeError` due to changes in `HelpFormatter` arguments, specifically the `console` parameter becoming keyword-only.
- gotcha A regression in versions 1.5.1 and earlier could cause the formatter to crash when handling `%(default)s` style strings, especially if they appeared after markup text.
Install
-
pip install rich-argparse
Imports
- RichHelpFormatter
from rich_argparse import RichHelpFormatter
Quickstart
import argparse
from rich_argparse import RichHelpFormatter
parser = argparse.ArgumentParser(
description='A command-line tool with \n[bold blue]rich[/bold blue] help formatting.',
formatter_class=RichHelpFormatter
)
parser.add_argument('--name', '-n', help='Your name.')
parser.add_argument('--age', '-a', type=int, help='Your age.')
parser.add_argument(
'--verbose', '-v', action='store_true',
help='[dim]Enable verbose output.[/dim]'
)
# To display the rich help, you would typically run your script with --help
# or allow argparse to display it on invalid input.
# For demonstration, we can try parsing arguments that trigger help:
# try:
# parser.parse_args(['--help'])
# except SystemExit: # argparse raises SystemExit on --help
# pass
# To simply see the formatted output in a script context:
# This will print the help to the console
parser.print_help()