Imports
import rich
from rich import print, print_json, inspect
from rich.console import Console, Group
from rich.prompt import Prompt, IntPrompt, FloatPrompt, Confirm
from rich.table import Table
from rich.progress import track
from rich.markdown import Markdown
from rich.syntax import Syntax
from rich import traceback, pretty
Core Patterns
Styled printing with rich.print ✅ Current
from rich import print
def main() -> None:
print("Hello, [bold magenta]World[/]!")
print("[green]OK[/] [dim](dim text)[/]")
print("A whole line styled via markup, plus an emoji: [bold]Done[/] ✅")
if __name__ == "__main__":
main()
- Use
from rich import print as a drop-in replacement for built-in print.
- Inline styling uses Rich markup tags (BBCode-like), e.g.
[bold magenta]...[/].
Use a shared Console for app-wide output ✅ Current
from __future__ import annotations
from rich.console import Console
from rich.table import Table
def build_table() -> Table:
table = Table(title="Build Summary")
table.add_column("Step", style="bold")
table.add_column("Status", justify="right")
table.add_row("Lint", "[green]pass[/]")
table.add_row("Tests", "[green]pass[/]")
table.add_row("Package", "[yellow]skipped[/]")
return table
def main() -> None:
console = Console()
console.print("Starting build...", style="bold cyan")
console.print(build_table())
console.log("Build finished", log_locals=False)
if __name__ == "__main__":
main()
- Prefer a single
rich.console.Console instance for consistent width/color/logging configuration.
- Use
console.print(..., style="...") to style an entire renderable/line (and markup for parts).
JSON pretty printing with print_json ✅ Current
from __future__ import annotations
from rich import print_json
def main() -> None:
payload: dict[str, object] = {
"name": "example",
"ok": True,
"count": 3,
"items": ["a", "b", "c"],
"meta": {"source": "unit-test"},
}
print_json(data=payload, indent=2, highlight=True, sort_keys=True)
if __name__ == "__main__":
main()
print_json(json=...) prints a JSON string; print_json(data=...) encodes Python data then prints.
- Useful for debugging structured output with syntax highlighting.
Progress over an iterable with track ✅ Current
from __future__ import annotations
import time
from rich.progress import track
def main() -> None:
for _ in track(range(50), description="Working..."):
time.sleep(0.01)
if __name__ == "__main__":
main()
rich.progress.track(sequence, description=...) is the quick pattern for a single progress bar.
Prompts with validation (Prompt.ask, Confirm.ask) ✅ Current
from __future__ import annotations
from rich.prompt import Prompt, IntPrompt, Confirm
def main() -> None:
name: str = Prompt.ask("Name", default="Ada")
color: str = Prompt.ask(
"Favorite color",
choices=["red", "green", "blue"],
default="green",
case_sensitive=False,
)
age: int = IntPrompt.ask("Age", default=30)
proceed: bool = Confirm.ask("Proceed?", default=True)
from rich import print
print(f"Hello [bold]{name}[/], age={age}, color={color}, proceed={proceed}")
if __name__ == "__main__":
main()
Prompt.ask(..., choices=[...]) loops until valid input; set case_sensitive=False if desired.
Confirm.ask(...) is for yes/no prompts; IntPrompt / FloatPrompt parse numeric input.
Pretty printing with pretty.pprint ✅ Current
from __future__ import annotations
from rich.pretty import pprint
def main() -> None:
data = {
"name": "example",
"items": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"nested": {"foo": "bar", "baz": [True, False]},
}
# Basic pretty print
pprint(data)
# With max_length to truncate sequences/dicts
pprint(data, max_length=3)
# With max_string to truncate long strings
pprint({"long": "Hello" * 50}, max_string=20)
if __name__ == "__main__":
main()
pprint(obj, ...) pretty prints objects with automatic layout and syntax highlighting.
- Use
max_length=N to limit items shown in sequences/dicts; use max_string=N to truncate strings.
- Use
expand_all=True to force multi-line layout even for small objects.
Trees for hierarchical data ✅ Current
from __future__ import annotations
from rich.tree import Tree
from rich.console import Console
def main() -> None:
console = Console()
tree = Tree("Project Root")
tree.add("README.md")
src = tree.add("src/", style="bold blue")
src.add("main.py")
src.add("utils.py")
tree.add("tests/", style="bold green")
console.print(tree)
if __name__ == "__main__":
main()
Tree(label) creates a tree structure for hierarchical data visualization.
- Use
.add(item, style=..., guide_style=...) to add branches; returns a Tree for nesting.
Columns for multi-column layout ✅ Current
from __future__ import annotations
from rich.columns import Columns
from rich.console import Console
from rich.panel import Panel
def main() -> None:
console = Console()
panels = [Panel(f"Item {i}", expand=True) for i in range(6)]
columns = Columns(panels, equal=True, expand=True)
console.print(columns)
if __name__ == "__main__":
main()
Columns(renderables, ...) arranges items in columns.
- Use
equal=True for equal-width columns; expand=True to fill available width.
- Use
align="left", "center", or "right" to control alignment.
Configuration
- Console configuration
- Prefer constructing a
Console() and passing it through your app.
- If you rely on Rich's global console, you can access it via:
rich.get_console() -> Console
rich.reconfigure(*args, **kwargs) -> None (reconfigures the global console)
- Environment variables (behavior change in 14.0.0)
NO_COLOR: if set to a non-empty value, disables color output; empty is treated as disabled (i.e., does not disable colors).
FORCE_COLOR: if set to a non-empty value, forces color output; empty is treated as disabled.
UNICODE_VERSION: control Unicode version used for cell width calculations (added in 14.3.0).
TTY_COMPATIBLE: override auto-detection of TTY support (added in 14.0.0).
- Unicode width handling
- Rich has internal support for Unicode cell width tables; avoid relying on internal loaders.
- If using
rich.cells.cell_len, prefer keyword args (not positional), especially after signature changes in 14.3.0.
- Pretty printing in REPL / IPython
rich.pretty.install() enables pretty-printing in the Python REPL.
- On 14.3.0+, IPython respects a
Console passed to pretty.install(console=...).
Pitfalls
Wrong: Using built-in print and expecting Rich markup to render
def main() -> None:
# Built-in print will output markup tags literally.
print("Hello, [bold magenta]World[/]!")
if __name__ == "__main__":
main()
Right: Import rich.print (or use Console.print)
from rich import print
def main() -> None:
print("Hello, [bold magenta]World[/]!")
if __name__ == "__main__":
main()
Wrong: Prompt.ask choices are case-sensitive by default
from rich.prompt import Prompt
def main() -> None:
# User typing "paul" will be rejected.
name = Prompt.ask(
"Enter your name",
choices=["Paul", "Jessica", "Duncan"],
default="Paul",
)
from rich import print
print(name)
if __name__ == "__main__":
main()
Right: Set case_sensitive=False when appropriate
from rich.prompt import Prompt
def main() -> None:
name = Prompt.ask(
"Enter your name",
choices=["Paul", "Jessica", "Duncan"],
default="Paul",
case_sensitive=False,
)
from rich import print
print(name)
if __name__ == "__main__":
main()
Wrong: Passing multiple renderables where a single renderable is expected (e.g., Panel)
from rich import print
from rich.panel import Panel
def main() -> None:
# Panel expects a single renderable as its content.
print(Panel("Hello", "World"))
if __name__ == "__main__":
main()
Right: Combine multiple renderables with Group
from rich import print
from rich.console import Group
from rich.panel import Panel
def main() -> None:
content = Group(
"Hello",
"World",
)
print(Panel(content, title="Greeting"))
if __name__ == "__main__":
main()
Wrong: Relying on exact traceback formatting in snapshot tests across versions
from rich import traceback
def main() -> None:
traceback.install()
raise ValueError("boom")
if __name__ == "__main__":
main()
Right: Assert on stable substrings / exception types, not exact rendered frames
from __future__ import annotations
from rich import traceback
def main() -> None:
traceback.install()
try:
raise ValueError("boom")
except ValueError as exc:
# In tests, assert on message/type rather than exact terminal rendering.
assert "boom" in str(exc)
if __name__ == "__main__":
main()
Wrong: Expecting empty environment variables to enable features
from __future__ import annotations
import os
def main() -> None:
# Empty NO_COLOR will NOT disable colors in Rich 14.0.0+
os.environ["NO_COLOR"] = ""
from rich import print
print("[red]This will still be colored[/]")
if __name__ == "__main__":
main()
Right: Set environment variables to non-empty values
from __future__ import annotations
import os
def main() -> None:
# Set to non-empty value to disable colors
os.environ["NO_COLOR"] = "1"
from rich import print
print("[red]This will not be colored[/]")
if __name__ == "__main__":
main()
References
Migration from v13.x
- 14.0.0: Environment variable semantics changed
- Empty
NO_COLOR is now considered disabled (does not disable colors).
- Empty
FORCE_COLOR is now considered disabled (does not force colors).
- Migration: ensure CI/container environments either unset these variables or set them to a non-empty value to activate behavior.
from __future__ import annotations
import os
from rich.console import Console
def main() -> None:
# Prefer explicit configuration over relying on possibly-empty env vars.
os.environ.pop("NO_COLOR", None)
os.environ.pop("FORCE_COLOR", None)
console = Console()
console.print("Color behavior is now consistent with env var semantics.")
if __name__ == "__main__":
main()
14.0.0: Traceback rendering output changed
- Notes (Py3.11+), Exception Groups, and formatting differences may break snapshot tests.
- Migration: update golden files or switch to assertions on stable content.
13.9.0: Python 3.7 dropped
- Migration: run on Python 3.8+ (or pin Rich < 13.9.0 if you must stay on 3.7).
14.3.0: rich.cells.cell_len signature changed
- Migration: prefer keyword arguments when calling
cell_len to avoid positional mismatch.
14.3.0: IPython Console support
pretty.install(console=...) now respects the Console instance in IPython environments.
- Migration: if you pass a custom Console to
pretty.install(), it will now be used in IPython.
14.3.0: Markdown styling changes
- Markdown headers, tables, and rules have updated styling.
- New styles added:
markdown.table.header and markdown.table.border.
- Migration: review Markdown rendering output; customize styles if needed to match previous appearance.
API Reference
- *rich.print(objects, sep=" ", end="\n", file=None, flush=False) - Rich-enhanced print with markup rendering.
- *rich.print_json(json=None, , data=None, indent=2, highlight=True, skip_keys=False, ensure_ascii=False, check_circular=True, allow_nan=True, default=None, sort_keys=False) - Pretty-print JSON (string or data) with optional highlighting.
- *rich.inspect(obj, , console=None, title=None, help=False, methods=False, docs=True, private=False, dunder=False, sort=True, all=False, value=True) - Introspect and render object details to the console.
- rich.get_console() - Get the global
Console instance used by top-level helpers.
- **rich.reconfigure(*args, kwargs) - Reconfigure the global
Console (use sparingly; prefer explicit Console()).
- rich.console.Console(...) - Primary output object; controls width, color system, recording, etc.
- *rich.console.Console.print(renderables, style=None, markup=True, highlight=None, emoji=True, ...)
- Print renderables (strings, Tables, Markdown, Syntax, Panels, etc.) with styling.
- *rich.console.Console.log(objects, log_locals=False, ...)
- Log with timestamps and optional locals capture for debugging.
- rich.console.Console.status(status, spinner="dots")
- Context manager for a live status spinner while work runs.
- *rich.console.Group(renderables) - Combine multiple renderables into one for containers expecting a single renderable.
- *rich.prompt.Prompt.ask(prompt, , choices=None, default=None, case_sensitive=True, ...)
- Prompt for text input with optional validation and looping.
- rich.prompt.IntPrompt.ask(...) / rich.prompt.FloatPrompt.ask(...)
- Prompt for numeric input with parsing and validation.
- *rich.prompt.Confirm.ask(prompt, , default=False, ...)
- rich.table.Table(title=None, ...) - Build tables for console rendering.
- **rich.table.Table.add_column(header, , style=None, justify=None, ...) / Table.add_row(cells, ...)
- Define columns and add rows.
- rich.progress.track(sequence, description=None, total=None, ...)
- Iterate with a progress bar.
- rich.markdown.Markdown(markdown_text) - Render Markdown as a Rich renderable.
- rich.syntax.Syntax(code, lexer, theme="monokai", line_numbers=False, ...) - Render syntax-highlighted code.
- rich.pretty.install(console=None, ...)
- Enable Rich pretty-printing in REPL/IPython contexts.
- *rich.pretty.pprint(obj, , console=None, indent_guides=True, max_length=None, max_string=None, max_depth=None, expand_all=False, ...)
- Pretty print an object to the console with Rich formatting.
- *rich.pretty.pretty_repr(obj, , max_width=80, indent_size=4, max_length=None, max_string=None, max_depth=None, expand_all=False, ...)
- Generate a pretty string representation of an object.
- rich.traceback.install(...)
- Install Rich traceback handler (note output format changed in 14.0.0).
- *rich.tree.Tree(label, , guide_style="tree.line", ...)
- Create a tree structure for hierarchical data.
- *rich.tree.Tree.add(label, , style=None, guide_style=None, ...)
- Add a branch to the tree; returns a
Tree for nesting.
- *rich.columns.Columns(renderables, , equal=False, expand=False, align="left", ...)
- Arrange renderables in columns.
- *rich.filesize.decimal(size, , precision=1, separator=" ")
- Format file size in decimal units (base 1000: bytes, kB, MB, etc.).
1---2name: rich3description: Terminal rendering library for styled text, tables, progress bars, prompts, markdown, syntax highlighting, and tracebacks.4license: MIT5---6
7## Imports
8
9```python
10import rich
11from rich import print, print_json, inspect
12from rich.console import Console, Group
13from rich.prompt import Prompt, IntPrompt, FloatPrompt, Confirm
14from rich.table import Table
15from rich.progress import track
16from rich.markdown import Markdown
17from rich.syntax import Syntax
18from rich import traceback, pretty
19```
20
21## Core Patterns
22
23### Styled printing with `rich.print` ✅ Current
24```python
25from rich import print
26
27def main() -> None:
28 print("Hello, [bold magenta]World[/]!")
29 print("[green]OK[/] [dim](dim text)[/]")
30 print("A whole line styled via markup, plus an emoji: [bold]Done[/] ✅")
31
32if __name__ == "__main__":
33 main()
34```
35* Use `from rich import print` as a drop-in replacement for built-in `print`.
36* Inline styling uses Rich markup tags (BBCode-like), e.g. `[bold magenta]...[/]`.
37
38### Use a shared `Console` for app-wide output ✅ Current
39```python
40from __future__ import annotations
41
42from rich.console import Console
43from rich.table import Table
44
45def build_table() -> Table:
46 table = Table(title="Build Summary")
47 table.add_column("Step", style="bold")
48 table.add_column("Status", justify="right")
49 table.add_row("Lint", "[green]pass[/]")
50 table.add_row("Tests", "[green]pass[/]")
51 table.add_row("Package", "[yellow]skipped[/]")
52 return table
53
54def main() -> None:
55 console = Console()
56 console.print("Starting build...", style="bold cyan")
57 console.print(build_table())
58 console.log("Build finished", log_locals=False)
59
60if __name__ == "__main__":
61 main()
62```
63* Prefer a single `rich.console.Console` instance for consistent width/color/logging configuration.
64* Use `console.print(..., style="...")` to style an entire renderable/line (and markup for parts).
65
66### JSON pretty printing with `print_json` ✅ Current
67```python
68from __future__ import annotations
69
70from rich import print_json
71
72def main() -> None:
73 payload: dict[str, object] = {
74 "name": "example",
75 "ok": True,
76 "count": 3,
77 "items": ["a", "b", "c"],
78 "meta": {"source": "unit-test"},
79 }
80 print_json(data=payload, indent=2, highlight=True, sort_keys=True)
81
82if __name__ == "__main__":
83 main()
84```
85* `print_json(json=...)` prints a JSON string; `print_json(data=...)` encodes Python data then prints.
86* Useful for debugging structured output with syntax highlighting.
87
88### Progress over an iterable with `track` ✅ Current
89```python
90from __future__ import annotations
91
92import time
93from rich.progress import track
94
95def main() -> None:
96 for _ in track(range(50), description="Working..."):
97 time.sleep(0.01)
98
99if __name__ == "__main__":
100 main()
101```
102* `rich.progress.track(sequence, description=...)` is the quick pattern for a single progress bar.
103
104### Prompts with validation (`Prompt.ask`, `Confirm.ask`) ✅ Current
105```python
106from __future__ import annotations
107
108from rich.prompt import Prompt, IntPrompt, Confirm
109
110def main() -> None:
111 name: str = Prompt.ask("Name", default="Ada")
112 color: str = Prompt.ask(
113 "Favorite color",
114 choices=["red", "green", "blue"],
115 default="green",
116 case_sensitive=False,
117 )
118 age: int = IntPrompt.ask("Age", default=30)
119 proceed: bool = Confirm.ask("Proceed?", default=True)
120
121 from rich import print
122 print(f"Hello [bold]{name}[/], age={age}, color={color}, proceed={proceed}")
123
124if __name__ == "__main__":
125 main()
126```
127* `Prompt.ask(..., choices=[...])` loops until valid input; set `case_sensitive=False` if desired.
128* `Confirm.ask(...)` is for yes/no prompts; `IntPrompt` / `FloatPrompt` parse numeric input.
129
130### Pretty printing with `pretty.pprint` ✅ Current
131```python
132from __future__ import annotations
133
134from rich.pretty import pprint
135
136def main() -> None:
137 data = {
138 "name": "example",
139 "items": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
140 "nested": {"foo": "bar", "baz": [True, False]},
141 }
142
143 # Basic pretty print
144 pprint(data)
145
146 # With max_length to truncate sequences/dicts
147 pprint(data, max_length=3)
148
149 # With max_string to truncate long strings
150 pprint({"long": "Hello" * 50}, max_string=20)
151
152if __name__ == "__main__":
153 main()
154```
155* `pprint(obj, ...)` pretty prints objects with automatic layout and syntax highlighting.
156* Use `max_length=N` to limit items shown in sequences/dicts; use `max_string=N` to truncate strings.
157* Use `expand_all=True` to force multi-line layout even for small objects.
158
159### Trees for hierarchical data ✅ Current
160```python
161from __future__ import annotations
162
163from rich.tree import Tree
164from rich.console import Console
165
166def main() -> None:
167 console = Console()
168
169 tree = Tree("Project Root")
170 tree.add("README.md")
171 src = tree.add("src/", style="bold blue")
172 src.add("main.py")
173 src.add("utils.py")
174 tree.add("tests/", style="bold green")
175
176 console.print(tree)
177
178if __name__ == "__main__":
179 main()
180```
181* `Tree(label)` creates a tree structure for hierarchical data visualization.
182* Use `.add(item, style=..., guide_style=...)` to add branches; returns a `Tree` for nesting.
183
184### Columns for multi-column layout ✅ Current
185```python
186from __future__ import annotations
187
188from rich.columns import Columns
189from rich.console import Console
190from rich.panel import Panel
191
192def main() -> None:
193 console = Console()
194
195 panels = [Panel(f"Item {i}", expand=True) for i in range(6)]
196 columns = Columns(panels, equal=True, expand=True)
197
198 console.print(columns)
199
200if __name__ == "__main__":
201 main()
202```
203* `Columns(renderables, ...)` arranges items in columns.
204* Use `equal=True` for equal-width columns; `expand=True` to fill available width.
205* Use `align="left"`, `"center"`, or `"right"` to control alignment.
206
207## Configuration
208
209- **Console configuration**
210 - Prefer constructing a `Console()` and passing it through your app.
211 - If you rely on Rich's global console, you can access it via:
212 - `rich.get_console() -> Console`
213 - `rich.reconfigure(*args, **kwargs) -> None` (reconfigures the global console)
214- **Environment variables (behavior change in 14.0.0)**
215 - `NO_COLOR`: if set to a **non-empty** value, disables color output; **empty** is treated as disabled (i.e., does not disable colors).
216 - `FORCE_COLOR`: if set to a **non-empty** value, forces color output; **empty** is treated as disabled.
217 - `UNICODE_VERSION`: control Unicode version used for cell width calculations (added in 14.3.0).
218 - `TTY_COMPATIBLE`: override auto-detection of TTY support (added in 14.0.0).
219- **Unicode width handling**
220 - Rich has internal support for Unicode cell width tables; avoid relying on internal loaders.
221 - If using `rich.cells.cell_len`, prefer keyword args (not positional), especially after signature changes in 14.3.0.
222- **Pretty printing in REPL / IPython**
223 - `rich.pretty.install()` enables pretty-printing in the Python REPL.
224 - On 14.3.0+, IPython respects a `Console` passed to `pretty.install(console=...)`.
225
226## Pitfalls
227
228### Wrong: Using built-in `print` and expecting Rich markup to render
229```python
230def main() -> None:
231 # Built-in print will output markup tags literally.
232 print("Hello, [bold magenta]World[/]!")
233
234if __name__ == "__main__":
235 main()
236```
237
238### Right: Import `rich.print` (or use `Console.print`)
239```python
240from rich import print
241
242def main() -> None:
243 print("Hello, [bold magenta]World[/]!")
244
245if __name__ == "__main__":
246 main()
247```
248
249### Wrong: `Prompt.ask` choices are case-sensitive by default
250```python
251from rich.prompt import Prompt
252
253def main() -> None:
254 # User typing "paul" will be rejected.
255 name = Prompt.ask(
256 "Enter your name",
257 choices=["Paul", "Jessica", "Duncan"],
258 default="Paul",
259 )
260 from rich import print
261 print(name)
262
263if __name__ == "__main__":
264 main()
265```
266
267### Right: Set `case_sensitive=False` when appropriate
268```python
269from rich.prompt import Prompt
270
271def main() -> None:
272 name = Prompt.ask(
273 "Enter your name",
274 choices=["Paul", "Jessica", "Duncan"],
275 default="Paul",
276 case_sensitive=False,
277 )
278 from rich import print
279 print(name)
280
281if __name__ == "__main__":
282 main()
283```
284
285### Wrong: Passing multiple renderables where a single renderable is expected (e.g., `Panel`)
286```python
287from rich import print
288from rich.panel import Panel
289
290def main() -> None:
291 # Panel expects a single renderable as its content.
292 print(Panel("Hello", "World"))
293
294if __name__ == "__main__":
295 main()
296```
297
298### Right: Combine multiple renderables with `Group`
299```python
300from rich import print
301from rich.console import Group
302from rich.panel import Panel
303
304def main() -> None:
305 content = Group(
306 "Hello",
307 "World",
308 )
309 print(Panel(content, title="Greeting"))
310
311if __name__ == "__main__":
312 main()
313```
314
315### Wrong: Relying on exact traceback formatting in snapshot tests across versions
316```python
317from rich import traceback
318
319def main() -> None:
320 traceback.install()
321 raise ValueError("boom")
322
323if __name__ == "__main__":
324 main()
325```
326
327### Right: Assert on stable substrings / exception types, not exact rendered frames
328```python
329from __future__ import annotations
330
331from rich import traceback
332
333def main() -> None:
334 traceback.install()
335 try:
336 raise ValueError("boom")
337 except ValueError as exc:
338 # In tests, assert on message/type rather than exact terminal rendering.
339 assert "boom" in str(exc)
340
341if __name__ == "__main__":
342 main()
343```
344
345### Wrong: Expecting empty environment variables to enable features
346```python
347from __future__ import annotations
348
349import os
350
351def main() -> None:
352 # Empty NO_COLOR will NOT disable colors in Rich 14.0.0+
353 os.environ["NO_COLOR"] = ""
354 from rich import print
355 print("[red]This will still be colored[/]")
356
357if __name__ == "__main__":
358 main()
359```
360
361### Right: Set environment variables to non-empty values
362```python
363from __future__ import annotations
364
365import os
366
367def main() -> None:
368 # Set to non-empty value to disable colors
369 os.environ["NO_COLOR"] = "1"
370 from rich import print
371 print("[red]This will not be colored[/]")
372
373if __name__ == "__main__":
374 main()
375```
376
377## References
378
379- [Official Documentation](https://rich.readthedocs.io/)
380- [GitHub Repository](https://github.com/Textualize/rich)
381
382## Migration from v13.x
383
384- **14.0.0: Environment variable semantics changed**
385 - Empty `NO_COLOR` is now considered disabled (does not disable colors).
386 - Empty `FORCE_COLOR` is now considered disabled (does not force colors).
387 - Migration: ensure CI/container environments either unset these variables or set them to a non-empty value to activate behavior.
388
389```python
390from __future__ import annotations
391
392import os
393from rich.console import Console
394
395def main() -> None:
396 # Prefer explicit configuration over relying on possibly-empty env vars.
397 os.environ.pop("NO_COLOR", None)
398 os.environ.pop("FORCE_COLOR", None)
399 console = Console()
400 console.print("Color behavior is now consistent with env var semantics.")
401
402if __name__ == "__main__":
403 main()
404```
405
406- **14.0.0: Traceback rendering output changed**
407 - Notes (Py3.11+), Exception Groups, and formatting differences may break snapshot tests.
408 - Migration: update golden files or switch to assertions on stable content.
409
410- **13.9.0: Python 3.7 dropped**
411 - Migration: run on Python 3.8+ (or pin Rich < 13.9.0 if you must stay on 3.7).
412
413- **14.3.0: `rich.cells.cell_len` signature changed**
414 - Migration: prefer keyword arguments when calling `cell_len` to avoid positional mismatch.
415
416- **14.3.0: IPython Console support**
417 - `pretty.install(console=...)` now respects the Console instance in IPython environments.
418 - Migration: if you pass a custom Console to `pretty.install()`, it will now be used in IPython.
419
420- **14.3.0: Markdown styling changes**
421 - Markdown headers, tables, and rules have updated styling.
422 - New styles added: `markdown.table.header` and `markdown.table.border`.
423 - Migration: review Markdown rendering output; customize styles if needed to match previous appearance.
424
425## API Reference
426
427- **rich.print(*objects, sep=" ", end="\\n", file=None, flush=False)** - Rich-enhanced print with markup rendering.
428- **rich.print_json(json=None, *, data=None, indent=2, highlight=True, skip_keys=False, ensure_ascii=False, check_circular=True, allow_nan=True, default=None, sort_keys=False)** - Pretty-print JSON (string or data) with optional highlighting.
429- **rich.inspect(obj, *, console=None, title=None, help=False, methods=False, docs=True, private=False, dunder=False, sort=True, all=False, value=True)** - Introspect and render object details to the console.
430- **rich.get_console()** - Get the global `Console` instance used by top-level helpers.
431- **rich.reconfigure(*args, **kwargs)** - Reconfigure the global `Console` (use sparingly; prefer explicit `Console()`).
432- **rich.console.Console(...)** - Primary output object; controls width, color system, recording, etc.
433- **rich.console.Console.print(*renderables, style=None, markup=True, highlight=None, emoji=True, ...)**
434 - Print renderables (strings, Tables, Markdown, Syntax, Panels, etc.) with styling.
435- **rich.console.Console.log(*objects, log_locals=False, ...)**
436 - Log with timestamps and optional locals capture for debugging.
437- **rich.console.Console.status(status, spinner="dots")**
438 - Context manager for a live status spinner while work runs.
439- **rich.console.Group(*renderables)** - Combine multiple renderables into one for containers expecting a single renderable.
440- **rich.prompt.Prompt.ask(prompt, *, choices=None, default=None, case_sensitive=True, ...)**
441 - Prompt for text input with optional validation and looping.
442- **rich.prompt.IntPrompt.ask(...) / rich.prompt.FloatPrompt.ask(...)**
443 - Prompt for numeric input with parsing and validation.
444- **rich.prompt.Confirm.ask(prompt, *, default=False, ...)**
445 - Prompt for yes/no input.
446- **rich.table.Table(title=None, ...)** - Build tables for console rendering.
447- **rich.table.Table.add_column(header, *, style=None, justify=None, ...) / Table.add_row(*cells, ...)**
448 - Define columns and add rows.
449- **rich.progress.track(sequence, description=None, total=None, ...)**
450 - Iterate with a progress bar.
451- **rich.markdown.Markdown(markdown_text)** - Render Markdown as a Rich renderable.
452- **rich.syntax.Syntax(code, lexer, theme="monokai", line_numbers=False, ...)** - Render syntax-highlighted code.
453- **rich.pretty.install(console=None, ...)**
454 - Enable Rich pretty-printing in REPL/IPython contexts.
455- **rich.pretty.pprint(obj, *, console=None, indent_guides=True, max_length=None, max_string=None, max_depth=None, expand_all=False, ...)**
456 - Pretty print an object to the console with Rich formatting.
457- **rich.pretty.pretty_repr(obj, *, max_width=80, indent_size=4, max_length=None, max_string=None, max_depth=None, expand_all=False, ...)**
458 - Generate a pretty string representation of an object.
459- **rich.traceback.install(...)**
460 - Install Rich traceback handler (note output format changed in 14.0.0).
461- **rich.tree.Tree(label, *, guide_style="tree.line", ...)**
462 - Create a tree structure for hierarchical data.
463- **rich.tree.Tree.add(label, *, style=None, guide_style=None, ...)**
464 - Add a branch to the tree; returns a `Tree` for nesting.
465- **rich.columns.Columns(renderables, *, equal=False, expand=False, align="left", ...)**
466 - Arrange renderables in columns.
467- **rich.filesize.decimal(size, *, precision=1, separator=" ")**
468 - Format file size in decimal units (base 1000: bytes, kB, MB, etc.).