rich

A Python library for rendering rich text, tables, progress bars, and syntax-highlighted code in the terminal.

Library
PyPI
v15.0.0
57,489 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
56 /100 Fair
Development Activity 12
Maintenance 48
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
89 /100 Excellent
Architecture 85
Code Quality 88
Innovation 92
Learning Curve 90

Rich turns plain terminal output into readable, well-formatted text with almost no extra code. A single import replaces the built-in print function with one that understands colors, styles, and a compact BBCode-like markup, while a Console object gives finer control over layout, word-wrapping, and terminal width detection.

Beyond text styling, Rich ships a full set of renderables: tables that auto-size to their content, progress bars that track multiple concurrent tasks, live-updating displays that redraw in place, Markdown rendering, and Pygments-backed syntax highlighting for code blocks and tracebacks. Any object can plug into this system by implementing the __rich_console__ protocol, so third-party libraries can render themselves through Rich without Rich needing to know about them in advance.

It also works outside the terminal: pretty.install() upgrades the Python REPL to auto-format data structures, and output can be exported to HTML or SVG for embedding elsewhere, including Jupyter notebooks.

What You Get

  • A Console object and drop-in print() replacement with markup-based colors and styles
  • Renderables for tables, panels, columns, trees, and progress bars that auto-size to terminal width
  • Live-updating displays (Live, Progress) that redraw in place without flicker
  • Pygments-backed syntax highlighting for code blocks and exception tracebacks
  • Markdown rendering and pretty-printing of Python data structures (pretty.install())
  • HTML and SVG export of rendered output for embedding outside the terminal

Common Use Cases

  • Formatting CLI tool output with colors, tables, and progress indicators
  • Rendering readable, syntax-highlighted tracebacks for easier debugging
  • Building live dashboards or progress displays for long-running scripts
  • Pretty-printing complex data structures during interactive REPL sessions
  • Rendering Markdown or code snippets directly in terminal-based tools

Under The Hood

Architecture Rich centers on a Console object (rich/console.py, ~2,700 lines) that orchestrates rendering: any object implementing the renderable protocol (__rich_console__ and __rich_measure__, defined in rich/protocol.py and rich/abc.py) can be handed to console.print() and rendered without Console needing prior knowledge of its type. Renderables (Table, Panel, Markdown, Syntax, Progress, Layout, and others, each its own module) yield a stream of Segment objects — the atomic unit pairing text with a Style — which Console then converts into ANSI control codes via control.py, with a separate ctypes-based path through _win32_console.py/_windows_renderer.py for older Windows terminals. Live and Progress build on this same Console/Segment pipeline to redraw regions in place. This protocol-based, duck-typed design means the core abstraction to change carefully is the renderable protocol itself — nearly every built-in renderable and any third-party integration depends on it.

Tech Stack Rich targets Python 3.9+ and is built/packaged with Poetry (poetry-core backend, pyproject.toml). Its only required runtime dependencies are pygments (>=2.13) for syntax highlighting and markdown-it-py (>=2.2.0) for Markdown rendering, with ipywidgets as an optional extra for Jupyter integration. There is no web or database layer — it’s a pure terminal-rendering library. Development tooling includes pytest for testing, black and isort (black profile) for formatting, mypy in strict mode for type checking, and pre-commit hooks (pycln, codespell, and standard hygiene checks) enforced via GitHub Actions CI (pythonpackage.yml, codeql.yml for security scanning).

Code Quality The repo ships a py.typed marker and enforces mypy in strict mode with additional error codes enabled (ignore-without-code, redundant-expr, truthy-bool), indicating a genuine commitment to type safety rather than a token typed export. Test coverage is extensive: 68 files under tests/, covering individual renderables (tables, panels, columns, bars, colors, control sequences) with a shared conftest.py and dedicated SVG/card rendering test helpers. Formatting and import order are enforced via black and isort through pre-commit, and a custom errors.py module defines a clear exception hierarchy rather than relying on generic exceptions. CI runs the test suite plus CodeQL security scanning on every change.

API Design Rich’s headline design choice is making the common case a near drop-in replacement for the built-in print — from rich import print requires no other setup to get colored, word-wrapped output. Styling is expressed through a compact BBCode-like markup ([bold red]...[/]) rather than manual ANSI escape codes, and more advanced usage flows naturally through a single Console object rather than a scattered API surface. Documentation is thorough (readthedocs reference plus READMEs translated into 17 languages), and the renderable protocol keeps the public API small while still letting advanced users define fully custom renderables. The result is very low boilerplate for basic use and a consistent mental model as usage grows more advanced.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers