📝 LLM & AI

rich: Beautiful Terminal Output

P
Author
PyLand Team
📅
Published
04.06.2026
⏱️
Reading time
1 min
👁️
Views
400
🌱
Level
Beginner

rich is a Python library for formatted terminal output. Colors, tables, panels, markdown, progress bars, spinners — all through one simple API. Created by Will McGugan and actively maintained.

Installation

uv add rich

Console — the Foundation of Everything

from rich.console import Console

console = Console()

console.print("Plain text")
console.print("[bold red]Error![/bold red]")
console.print("[green]Success[/green]")
console.print("[bold blue]Heading[/bold blue]")
console.print("[dim]Secondary text[/dim]")

Styles are wrapped in [style]text[/style].

Markdown

from rich.markdown import Markdown

text = """# Heading

Paragraph with **bold** text.

```python
print('hello')
```
"""
console.print(Markdown(text))

Perfect for rendering Claude responses — the model frequently replies in markdown format.

Panel

from rich.panel import Panel

console.print(Panel(
    "Message text",
    title="Title",
    border_style="blue"
))

console.print(Panel(
    "[bold]Important message[/bold]",
    title="[red]Error[/red]",
    border_style="red",
    padding=(1, 2),
))

Status (Spinner)

import time

with console.status("[bold green]Thinking...[/]", spinner="dots"):
    time.sleep(2)  # long operation
# spinner stops automatically when exiting the with block

Built-in spinners: dots, dots2, line, arc, bouncingBall, clock.

Input with a Prompt

user_input = console.input("[bold blue]You:[/] ")

Supports the same color tags as console.print().

Table

from rich.table import Table

table = Table(title="Token Stats")
table.add_column("Type", style="cyan", no_wrap=True)
table.add_column("Count", justify="right", style="green")
table.add_column("Cost", justify="right", style="yellow")

table.add_row("Input", "1,234", "$0.0037")
table.add_row("Output", "567", "$0.0085")

console.print(table)

Style Cheat Sheet

Style Use Case
[bold] important parts
[italic] terms, emphasis
[dim] secondary information
[red] / [green] errors / success
[blue] / [cyan] user labels / code
[yellow] warnings, costs
[bold green]Claude[/bold green] combined styles

Important: highlight=False When Streaming

When printing text chunk by chunk, always disable auto-highlighting:

# When streaming:
console.print(chunk, end="", highlight=False)

# For regular output, the flag is not needed:
console.print(response_text)

Without highlight=False, rich tries to apply syntax highlighting to each chunk individually — this breaks formatting during streaming output.

Rule (Divider)

from rich.rule import Rule

console.print(Rule("[dim]new conversation[/dim]"))

Prints a horizontal line spanning the full terminal width — handy for separating output blocks.

Your reaction to the article

💬 Comments (0)

🔐 Sign in to leave a comment
🚪 Login
💭

No comments yet

Be the first to share your opinion about this article!

🔗 Similar

Similar articles

Continue learning with these materials

📝

httpx: A Modern HTTP Client for Python

httpx is a next-generation HTTP client. Its interface is similar to requests, but it supports...

📅 30.06.2026 👁️ 330
📝

AI Agents: ReAct Loop and Autonomous Actions

A chatbot answers questions. An agent takes action: it calls tools, retrieves real data, and...

📅 30.06.2026 👁️ 336
📝

Typer: CLI Applications Without the Boilerplate

Typer builds CLIs from Python type annotations. No argparse, no manual parsing — just decorators...

📅 30.06.2026 👁️ 368
🎓 Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

Neural Networks in Code: 5 AI Projects in Python with Claude Open course curriculum