Rich Output
Rich renders formatted text, tables, progress bars, and syntax highlighting in the terminal. It makes CLI output readable without sacrificing scriptability.
Search across all documentation pages
Rich renders formatted text, tables, progress bars, and syntax highlighting in the terminal. It makes CLI output readable without sacrificing scriptability.
uv add richfrom rich.console import Console
console = Console()
console.print("[bold green]Success![/bold green] Deployed v1.2.3")When to reach for this:
from rich.console import Console
from rich.table import Table
from rich.progress import track
from rich.syntax import Syntax
import time
console = Console()
def show_users(users: list[dict]):
table = Table(title="Active Users")
table.add_column("ID", style="cyan", justify="right")
table.add_column("Email")
table.add_column("Role", style="magenta")
for u in users:
table.add_row(str(u["id"]), u["email"], u["role"])
console.print(table)
def process_files(paths: list[str]):
for path in track(paths, description="Processing..."):
time.sleep(0.1) # simulate work
console.print("[green]Done![/green]")
def show_config(yaml_text: str):
syntax = Syntax(yaml_text, "yaml", theme="monokai", line_numbers=True)
console.print(syntax)What this demonstrates:
track() wraps iterables with a progress barSyntax highlights code and config files[green] for inline styling| Mode | Use |
|---|---|
| Rich table | Human inspection |
| JSON to stdout | Machine parsing (--json flag) |
| stderr for logs | Keep stdout pipeable |
Console(soft_wrap=True) | Narrow terminals |
Console(force_terminal=False) or --plain flag.--json flag for machine output; Rich for default human mode.rich.logging.RichHandler for structured logs.--limit flag.| Alternative | Use When | Don't Use When |
|---|---|---|
| Plain print | Scriptable output only | User-facing dashboard |
| tabulate | Simple tables, no colors | Progress bars needed |
| tqdm | Progress only | Full formatting suite |
Rich for interactive human use. Add --json or --plain for automation.
Yes. Windows Terminal supports ANSI colors. Legacy cmd may need colorama.
logging.basicConfig(handler=RichHandler(), level=logging.INFO).
from rich.markdown import Markdown; console.print(Markdown(text)).
Console(file=StringIO()) captures output for assertions.
from rich.live import Live for updating displays.
Compatible. Use click.echo for simple text; Rich Console for complex output.
Console(no_color=True) or NO_COLOR=1 env var.
from rich.tree import Tree for hierarchical display.
Stream or paginate. Do not build million-row tables.
Stack versions: This page was written for Python 3.14.0, FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.
Reviewed by Chris St. John·Last updated Jul 19, 2026