🎨 Rich Cheatsheet

Colourful text, tables and more with Rich. Copy any example into the Editor and press ▶ Run.

🚀 Getting started

Rich makes your output colourful and tidy. Import its print and use [tags] for styles. The first Rich program takes a moment while the library loads — after that it is quick. The same code also shows colours in a real terminal.

from rich import print

print("[bold red]Hello[/] [green]world[/] 🌈")
💡 A style tag like [green] turns on a style and [/] turns it back off. You can combine styles, e.g. [bold underline blue].

🌈 Colourful text & styles

Wrap words in tags to colour and style them.

from rich import print

print("[red]red[/], [green]green[/], [blue]blue[/]")
print("[bold]bold[/], [italic]italic[/], [underline]underline[/], [dim]dim[/]")
print("[white on blue] white on blue [/]")
print("[#ff8800]any hex colour you like[/]")

For more control, use a Console and its print with a style=.

from rich.console import Console

console = Console()
console.print("Styled with a Console", style="bold magenta")

📊 Tables

Tables draw neat borders automatically. Add columns (with a style and alignment), then add rows.

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

table = Table(title="🍓 Fruit basket")
table.add_column("Fruit", style="cyan")
table.add_column("Count", justify="right", style="magenta")
table.add_column("Yummy?", justify="center")

table.add_row("Apples", "12", "✅")
table.add_row("Bananas", "7", "✅")
table.add_row("Lemons", "3", "😐")

Console().print(table)
💡 Try a different border look with Table(box=None) or import a box style, e.g. from rich import box then Table(box=box.ROUNDED).

🖼️ Panels

A panel draws a box around some text — handy for titles or messages.

from rich.console import Console
from rich.panel import Panel

Console().print(Panel("Hello in a box! 🎁", title="Message"))

➖ Rules

A rule is a titled divider line, handy for separating sections of output.

from rich.console import Console

console = Console()
console.rule("[bold]Part One[/]")
console.print("Some text under the heading.")

🌳 Trees

A tree shows items that branch, like folders or a family of pets.

from rich.console import Console
from rich.tree import Tree

tree = Tree("🌳 My pets")
tree.add("🐶 Dog")
cats = tree.add("🐱 Cats")
cats.add("Tom")
cats.add("Felix")

Console().print(tree)

📚 Want to go further?

Rich can do much more — progress bars, syntax highlighting, markdown, live displays and more. Explore the official documentation:

https://rich.readthedocs.io/

💡 Some Rich features that animate (live progress bars and spinners) need a full terminal, so they may not animate here — but colours, tables, panels, rules and trees all work.