Rich Terminal Output
Style CLI output with rich.
Rich Terminal Output is a free Python Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is rich?
rich is a third-party library for beautiful terminal output: colors, styles, tables, progress bars, and more. Install it with pip install rich.
from rich import print
print('Hello, [bold magenta]world[/bold magenta]!')The Console Object
The central class is Console. Its print method understands style markup and handles wrapping and color detection.
from rich.console import Console
console = Console()
console.print('Styled output here')
Style Markup
rich uses bracket markup like [bold], [red], [italic] to style spans of text inline, closed with a matching tag.
from rich.console import Console
console = Console()
console.print('[bold red]Error:[/bold red] something failed')
console.print('[green]Success[/green]')
Style Argument
Instead of markup you can pass a style argument that applies to the whole line.
from rich.console import Console
console = Console()
console.print('Important notice', style='bold yellow on blue')
Tables
The Table class renders neat bordered tables. Add columns, then rows, then print the table.
from rich.console import Console
from rich.table import Table
table = Table(title='Users')
table.add_column('Name')
table.add_column('Age')
table.add_row('Ana', '30')
table.add_row('Bob', '25')
Console().print(table)
Panels
A Panel draws a box around content, useful for highlighting messages or grouping output.
from rich.console import Console
from rich.panel import Panel
Console().print(Panel('All systems go', title='Status'))
Progress Bars
rich can show live progress bars. track() wraps any iterable and renders progress as it is consumed.
from rich.progress import track
import time
for _ in track(range(5), description='Working'):
time.sleep(0.1)
Pretty Printing Data
console.print renders dicts and lists with syntax highlighting and indentation, far clearer than plain print.
from rich.console import Console
data = {'name': 'Ana', 'roles': ['admin', 'user'], 'active': True}
Console().print(data)
Logging and Tracebacks
rich offers prettier tracebacks via rich.traceback.install() and a logging handler, making error output far easier to read.
from rich.traceback import install
install()
# Now uncaught exceptions print with rich, colorized formatting
Rules and Layout
A console.rule() draws a horizontal divider with an optional title, handy for sectioning long output.
from rich.console import Console
console = Console()
console.rule('[bold]Report[/bold]')
console.print('section content')
Combining rich With Click
rich pairs nicely with Click: Click structures the commands while rich styles the output, giving polished, professional CLIs.
import click
from rich.console import Console
console = Console()
@click.command()
@click.argument('name')
def hello(name):
console.print('Hello [bold]' + name + '[/bold]!')
Quick Check
Test your understanding of rich.
Recap
You learned rich terminal output:
- The
Consoleprints with bracket style markup and astyleargument. Table,Panel, andrulestructure output;trackshows progress.- rich pretty-prints data and beautifies tracebacks.
- It is an external library that combines well with Click.
You have completed the CLI tools course!
Frequently asked questions
Is the “Rich Terminal Output” lesson free?
Yes — the full text of “Rich Terminal Output” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.
What will I learn in “Rich Terminal Output”?
Style CLI output with rich. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python Academy?
No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Rich Terminal Output” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python Academy lesson?
Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- argparse Basics
- Subcommands and Options
- The Click Library
- Rich Terminal Output