Rich
Terminal output that does not look like 1985 — tables, progress bars, syntax highlighting, markdown.
What it is
Rich is a Python library for rich text and beautiful formatting in the terminal. It allows you to create colorful and styled console output, including tables, progress bars, markdown, syntax highlighting, and more.
Rich allows developers to print styled text, tables, progress bars, and render markdown in the terminal. It supports colors, gradients, emojis, and live updates for interactive command-line applications.
- Licence
- MIT
- Best known for
- Making `print` of a dictionary genuinely readable
When to use it
The question documentation cannot answer for you — because it cannot recommend something else.
Reach for it when
- Any CLI tool where readable output improves the experience
- Progress reporting for long-running scripts
- Pretty-printing nested data structures while debugging
Look elsewhere when
- Output is piped into another program that expects plain text — check `is_terminal` first
Installation
pip install richGetting started
The smallest useful thing you can do with it, and what each part means.
from rich import print
print('[bold red]Hello[/bold red] [green]World[/green]!')from rich.console import Console
from rich.table import Table
console = Console()
table = Table(title='Fruits')
table.add_column('Name', style='cyan')
table.add_column('Quantity', justify='right')
table.add_row('Apple', '10')
table.add_row('Banana', '5')
console.print(table)Advanced usage
Where the library earns its place over a simpler alternative.
from rich.progress import track
import time
for i in track(range(100), description='Processing...'):
time.sleep(0.05)from rich.console import Console
from rich.syntax import Syntax
code = 'print("Hello, World!")'
syntax = Syntax(code, 'python', theme='monokai', line_numbers=True)
console = Console()
console.print(syntax)from rich.live import Live
from rich.panel import Panel
import time
with Live(Panel('Starting...'), refresh_per_second=4) as live:
for i in range(5):
live.update(Panel(f'Progress {i+1}/5'))
time.sleep(1)Errors and fixes
The failures you are most likely to hit, and what actually resolves them.
- ModuleNotFoundError: No module named 'rich'
- Install Rich using pip or conda in your current Python environment.
- Console does not support features
- Ensure your terminal supports ANSI colors and UTF-8 encoding for full Rich functionality.
Best practices
- Use Rich for logging, progress bars, and tables to make CLI apps more user-friendly.
- Use markup syntax for styling text rather than manual ANSI codes.
- Combine Rich with Python’s logging module for structured logs.
- Use `Live` and `Progress` for interactive real-time updates.
- Leverage Rich themes and styles to maintain consistent CLI design.
Alternatives
Comparable options, and the reason you would pick one over the other.
Background
Why it exists, and what it was reacting to.
Rich was created by Will McGugan in 2019 to bring modern, visually appealing formatting to Python command-line applications. Its goal is to make terminal output more informative, interactive, and beautiful without sacrificing performance or simplicity.
