📝 LLM & AI

rich: Beautiful Terminal Output

0
Author
04e5cc8b-58ac-4bdc-bdee-661bbb
📅
Published
04.06.2026
⏱️
Reading time
1 min
👁️
Views
15
🌱
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\n\nParagraph with **bold** text.\n\n```python\nprint('hello')\n```"
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

📝

Anthropic SDK: Getting Started with the Claude API

Anthropic Python SDK is the official library for working with Claude. It hides the complexity...

📅 04.06.2026 👁️ 16
📝

Streaming LLM Responses: Getting the Answer Piece…

By default, messages.create() waits until the model has fully generated its response before returning anything....

📅 04.06.2026 👁️ 18
📝

uv: The Modern Python Package Manager

uv is a next-generation tool for managing Python dependencies. Written in Rust by Astral, it...

📅 04.06.2026 👁️ 16

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!