rich
Display richly formatted text in terminal
TLDR
Display a file with syntax highlighting
Add line numbers, and indentation guides
Apply a theme
Display a file in an interactive pager
Display contents from a URL
Export a file as HTML
Display text with formatting tags, custom alignment, and line width
SYNOPSIS
python -m rich [SUBCOMMAND] [OPTIONS]
PARAMETERS
inspect OBJECT
Inspects a Python object, displaying its attributes, methods, and a pretty representation.
traceback
Renders a pretty traceback from a Python exception, improving readability for debugging.
syntax FILE
Renders a file with syntax highlighting for various programming languages.
markdown FILE
Renders a Markdown file directly in the terminal.
test
Runs a demonstration of various rich features, showcasing its capabilities.
--help
Displays the help message for the rich command or a specific subcommand.
DESCRIPTION
rich is a Python library that enables developers to add beautiful and powerful formatting to their terminal output. It provides a wide range of features including colors, styles, tables, progress bars, markdown rendering, syntax highlighting, and well-formatted tracebacks. While primarily a library used programmatically within Python applications to enhance their command-line interfaces (CLIs), it also ships with a command-line utility (typically invoked via python -m rich) that demonstrates and utilizes some of its core capabilities, such as inspecting Python objects, rendering syntax-highlighted code, or displaying rich tracebacks. Its ease of use and comprehensive feature set make it an invaluable tool for creating professional and user-friendly CLI applications and for improving developer productivity through better debugging and logging.
CAVEATS
The 'rich' command is not a native Linux utility but a command-line interface provided by the Python 'rich' library. It requires a Python installation (3.6+) and the 'rich' package to be installed (e.g., via pip install rich). Its primary use is as a programmatic library within Python applications, with the python -m rich utility serving mainly for demonstration and specific utility tasks rather than general system operation.
CORE LIBRARY USAGE
Beyond its command-line utility, the true power of rich lies in its Python API. Developers can import classes like Console, Table, Progress, Syntax, and Markdown to programmatically create sophisticated terminal output within their Python applications, offering dynamic and interactive experiences for users.
INTEGRATION WITH FRAMEWORKS
rich is often integrated with popular Python CLI frameworks such as Typer, Click, and Argparse to automatically provide rich formatting for help messages, error output, and general application feedback. It also enhances debugging in tools like pytest by providing pretty tracebacks.
HISTORY
The rich library was created by Will McGugan and first released in 2020. It quickly gained significant popularity within the Python community due to its modern approach to terminal output, its comprehensive feature set, and its ease of use. It represents a modern evolution in terminal UI/UX, moving beyond traditional basic text output to highly formatted and interactive console experiences. Its development has focused on providing a high-level API that abstracts away the complexities of ANSI escape codes, making it accessible to developers for enhancing their CLI tools.