What Is Rich? Terminal Formatting Explained

How Rich turns plain terminal output into formatted tables, progress bars, and syntax-highlighted text with just a few lines of Python

Rich turns plain terminal output into formatted tables, progress bars, and syntax-highlighted text, handling all the underlying ANSI escape-code complexity so you write ordinary Python instead. Checked against Rich 15.0.0 (12 April 2026), which requires Python 3.9 or later; the version 15 bump only dropped Python 3.8 support.

What it actually replaces

Building a formatted table, a live-updating progress bar, or colored/styled text in a terminal normally means working with raw ANSI escape codes — easy to get wrong, inconsistent across terminals, and tedious to write by hand. Rich wraps all of that in a plain Python API: a Table object you add rows to, a Progress context manager that updates itself, a drop-in print() replacement that understands basic markup for color and style.

import io

from rich.console import Console
from rich.table import Table


def show(console):
    table = Table(title="Results")
    table.add_column("Name")
    table.add_column("Score")
    table.add_row("Ada", "92")
    console.print(table)


# Written to a file-like object, as when output is redirected: no colour codes
plain = io.StringIO()
show(Console(file=plain, force_terminal=False))
print(plain.getvalue())
print("ANSI codes in redirected output:", "\x1b[" in plain.getvalue())

# The same table forced to behave like a colour terminal
coloured = io.StringIO()
show(Console(file=coloured, force_terminal=True, color_system="truecolor"))
print("ANSI codes in terminal output:", "\x1b[" in coloured.getvalue())

Run as a script with console = Console() and show(console) in a terminal, the table is drawn with box lines and styled headers. The block above writes to in-memory buffers so you can see the second point, that the codes are only present when the output is a terminal.

Where it shows up

CLI tools that need to show progress on a long-running task, structured output (tables, trees, JSON) that’s actually readable rather than a wall of plain text, and better error messages. Rich’s traceback formatting adds syntax-highlighted source context, and it can also show each frame’s local variables, but only when you ask for them (show_locals=True); in a test they appeared only with that option on. A large share of modern Python CLI tools use Rich for exactly this, often alongside Click or Typer for the argument-parsing side.

Graceful degradation

Rich detects what the current terminal actually supports and adjusts automatically: full color and styling in a capable terminal, clean text when output is redirected to a file or piped somewhere that doesn’t support ANSI codes. A redirected table contained no escape codes in a test (the box-drawing characters remain, since they are ordinary Unicode text). The NO_COLOR environment variable is also respected: with it set, [bold red]hi[/] kept the bold code and dropped the colour.

Should you add it to a project

If your project prints anything more structured than occasional status messages — progress on a batch job, tabular results, readable error output — Rich is a low-effort addition that meaningfully improves what users see, without requiring you to learn terminal formatting internals yourself.

Frequently Asked Questions

What is Rich used for?

Formatting terminal output — tables, progress bars, syntax-highlighted code, markdown rendering, tracebacks — that would otherwise take significant manual work with raw ANSI escape codes or plain print() statements.

Do you need to learn ANSI escape codes to use Rich?

No — that’s the entire point. Rich handles color, styling, and layout internally, exposing a simple Python API (a Table object, a Progress context manager) instead of requiring you to write or understand raw terminal escape sequences.

Does Rich work in every terminal?

Rich detects terminal capabilities automatically and degrades gracefully — full color and styling in a modern terminal, plain text in one that doesn’t support it (like output redirected to a file), rather than producing garbled escape codes.

What’s the difference between Rich and just using print()?

print() outputs plain text with no formatting. Rich’s own print() replacement and its Console object add color, styling, word-wrapping, and structured layouts (tables, panels, trees) while remaining just as simple to call for basic cases.