{"id":118157,"date":"2026-07-08T15:53:26","date_gmt":"2026-07-08T10:23:26","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=118157"},"modified":"2026-07-08T15:53:28","modified_gmt":"2026-07-08T10:23:28","slug":"python-rich-library","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/python-rich-library\/","title":{"rendered":"What is Python Rich Library: Beautiful Terminal CLI Output"},"content":{"rendered":"\n<p>Most Python developers have written scripts whose output is a wall of plain print() statements no structure, no colour, no way to tell what is important. The Python Rich library solves this comprehensively. Created by Will McGuinnen and released in 2020, Rich turned terminal output from an afterthought into a first-class experience. In this blog, we cover Rich&#8217;s most useful features: styled text, tables, progress bars, syntax highlighting, and live displays, each with practical code you can drop into your own scripts today.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>TL;DR<\/strong> <strong>Summary<\/strong><\/h2>\n\n\n\n<ul>\n<li>Python Rich is a third-party library that transforms plain terminal output into beautifully formatted, colour-coded text with tables, progress bars, syntax-highlighted code, panels, and live displays, all with a single import. <\/li>\n\n\n\n<li>It works on Windows, macOS, and Linux without any extra dependencies, and is used by popular tools like Textual, Pytest, and pip itself. If you build CLI scripts, developer tools, or data pipelines, Rich makes your terminal output professional and readable with very little code.<\/li>\n<\/ul>\n\n\n\n<p>Want to build professional Python CLI tools, scripts, and pipelines with real projects and mentorship? Check out <strong>HCL GUVI&#8217;s<\/strong><a href=\"https:\/\/www.guvi.in\/courses\/programming\/python-zero-to-hero\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=Python+Rich+Library%3A+Beautiful+Terminal+CLI+Output\" target=\"_blank\" rel=\"noreferrer noopener\"><strong> Python Programming Course<\/strong><\/a> designed for learners who want job-ready Python skills with hands-on practice and structured guidance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Getting Started with the Python Rich Library<\/strong><\/h2>\n\n\n\n<p>Install Rich with pip; it has no mandatory external dependencies:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install rich<\/code><\/pre>\n\n\n\n<p>The simplest upgrade is replacing Python&#8217;s built-in print() with Rich&#8217;s version it accepts markup tags for colour and style inline:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>from rich import print<br>print(&#8216;[bold green]Success:[\/bold green] Data pipeline completed.&#8217;)<br>print(&#8216;[bold red]Error:[\/bold red] Connection to database failed.&#8217;)<br>print(&#8216;[yellow]Warning:[\/yellow] Cache is 90% full.&#8217;)<br>print(&#8216;[bold cyan underline]Processing file 42 of 100\u2026[\/bold cyan underline]&#8217;)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Rich&#8217;s markup syntax is inspired by BBCode wrap text in [style] and [\/style] tags. Styles can be combined freely: [bold red underline] stacks all three. Any valid terminal colour name, hex code, or RGB value works<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Console Object: Rich&#8217;s Core API<\/strong><\/h2>\n\n\n\n<p>For anything beyond basic styled print, use the Console class; it gives you full control over output style, width, file destination, and logging integration.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>console = Console()\n \nconsole.print('Standard output with Rich styling')\nconsole.print('&#91;bold]Important:&#91;\/bold] This message stands out')\nconsole.log('&#91;green]Task completed&#91;\/green]', log_locals=True)\n \n# Write to stderr instead of stdout\nerr_console = Console(stderr=True)\nerr_console.print('&#91;red]Error: file not found&#91;\/red]')\n \n# Capture output as a string\nfrom rich.console import Console\ncapture_console = Console(record=True)\ncapture_console.print('&#91;blue]Captured output&#91;\/blue]')\ntext = capture_console.export_text()<\/code><\/pre>\n\n\n\n<p>console.log() adds a timestamp and source file reference automatically, making it ideal for replacing print-based debug logging in scripts and pipelines.<\/p>\n\n\n\n<p>Want to build professional Python CLI tools, scripts, and pipelines with real projects and mentorship? Check out <strong>HCL GUVI&#8217;s<\/strong><a href=\"https:\/\/www.guvi.in\/courses\/programming\/python-zero-to-hero\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=Python+Rich+Library%3A+Beautiful+Terminal+CLI+Output\" target=\"_blank\" rel=\"noreferrer noopener\"><strong> Python Programming Course<\/strong><\/a> designed for learners who want job-ready Python skills with hands-on practice and structured guidance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Tables: Structured Data in the Terminal<\/strong><\/h2>\n\n\n\n<p>Rich&#8217;s Table class renders database-style tables directly in the terminal with column headers, borders, alignment, and optional row styles.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>from rich.console import Console<br>from rich.table import Table<br><br>console = Console()<br>table = Table(title=&#8217;Model Benchmark Results&#8217;)<br><br>table.add_column(&#8216;Model&#8217;, style=&#8217;cyan&#8217;,&nbsp; no_wrap=<strong>True<\/strong>)<br>table.add_column(&#8216;Accuracy&#8217;, style=&#8217;green&#8217;, justify=&#8217;right&#8217;)<br>table.add_column(&#8216;Latency&#8217;,&nbsp; style=&#8217;yellow&#8217;,justify=&#8217;right&#8217;)<br>table.add_column(&#8216;Size&#8217;, justify=&#8217;right&#8217;)<br><br>table.add_row(&#8216;GPT-4o&#8217;, &#8216;94.2%&#8217;, &#8216;1.2s&#8217;,&nbsp; &#8216;1.8 TB&#8217;)<br>table.add_row(&#8216;Claude 3.5&#8242;,&#8217;93.8%&#8217;, &#8216;0.9s&#8217;,&nbsp; &#8216;1.2 TB&#8217;)<br>table.add_row(&#8216;Llama 3.1&#8217;, &#8216;89.4%&#8217;, &#8216;0.4s&#8217;,&nbsp; &#8217;70 B&#8217;)<br>table.add_row(&#8216;Mistral 7B&#8217;,&#8217;85.1%&#8217;, &#8216;0.2s&#8217;,&nbsp; &#8216;7 B&#8217;)<br><br>console.<strong>print<\/strong>(table)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Tables automatically size columns to fit the terminal width. You can customise border style, row styles, cell padding, and header formatting making even complex data immediately readable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Progress Bars and Live Displays<\/strong><\/h2>\n\n\n\n<p>Rich&#8217;s Progress class renders smooth, multi-task progress bars that update in place far more informative than printing a percentage on each line.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>import time<br>from rich.progress import Progress, SpinnerColumn, TimeElapsedColumn<br><br>with Progress(<br>&nbsp; &nbsp; SpinnerColumn(),<br>&nbsp; &nbsp; &#8216;[progress.description]{task.description}&#8217;,<br>&nbsp; &nbsp; &#8216;[progress.percentage]{task.percentage:&gt;3.0f}%&#8217;,<br>&nbsp; &nbsp; TimeElapsedColumn(),<br>) <strong>as<\/strong> progress:<br>&nbsp; &nbsp; download = progress.add_task(&#8216;[cyan]Downloading&#8230;&#8217;, total=100)<br>&nbsp; &nbsp; process&nbsp; = progress.add_task(&#8216;[green]Processing&#8230;&#8217;,&nbsp; total=50)<br><br>&nbsp; &nbsp; <strong>while<\/strong> not progress.finished:<br>&nbsp; &nbsp; &nbsp; &nbsp; time.sleep(0.05)<br>&nbsp; &nbsp; &nbsp; &nbsp; progress.update(download, advance=1)<br>&nbsp; &nbsp; &nbsp; &nbsp; <strong>if<\/strong> progress.tasks[0].completed &gt; 50:<br>&nbsp; &nbsp; &nbsp; &nbsp; progress.update(process, advance=1)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Multiple tasks display simultaneously, each with its own bar and description. Rich handles the cursor movement and terminal refresh automatically; no curses or ANSI escape code knowledge needed.<\/p>\n\n\n\n<p><strong>Read more: <\/strong><a href=\"https:\/\/www.guvi.in\/blog\/how-to-use-the-official-python-documentation\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>How to Use the Official Python Documentation When You\u2019re Just Starting<\/strong><\/a><\/p>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #FFFFFF; font-size: 18px; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 750px;\">\n  \n  <strong style=\"font-size: 22px; color: #FFFFFF;\">\ud83d\udca1 Did You Know?<\/strong>\n  <br \/><br \/>\n\n  The <strong style=\"color: #FFFFFF;\">Python Rich<\/strong> library is used by popular developer tools such as <strong style=\"color: #FFFFFF;\">pip<\/strong>, <strong style=\"color: #FFFFFF;\">Pytest<\/strong>, <strong style=\"color: #FFFFFF;\">Textual<\/strong>, and the <strong style=\"color: #FFFFFF;\">Ruff<\/strong> linter. Despite being relatively young, Rich has become one of the most widely adopted Python terminal libraries, helping developers create colorful console output, interactive progress bars, formatted tables, and modern command-line interfaces with minimal code.\n\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Syntax Highlighting, Panels, and Inspecting Objects<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Syntax Highlighting<\/strong><\/h3>\n\n\n\n<p>Rich can syntax-highlight code in the terminal for any language supported by the Pygments library: Python, JSON, SQL, JavaScript, YAML, and more:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>from rich.syntax import Syntax<br>from rich.console import Console<br>console = Console()<br>code = &#8221;&#8217;<br>def fibonacci(n):<br>&nbsp; &nbsp; if n &lt; 2: return n<br>&nbsp; &nbsp; return fibonacci(n-1) + fibonacci(n-2)<br>&#8221;&#8217;<br>syntax = Syntax(code, &#8216;python&#8217;, theme=&#8217;monokai&#8217;, line_numbers=<strong>True<\/strong>)<br>console.<strong>print<\/strong>(syntax)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Panels<\/strong><\/h3>\n\n\n\n<p>Panels wrap any content in a styled border box, useful for separating sections in long script output or highlighting key results:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>from rich.panel import Panel<br>from rich.console import Console<br><br>console = Console()<br>console.<strong>print<\/strong>(Panel(&#8216;[bold green]Pipeline Complete[\/bold green]\\n&#8217;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;Processed 10,432 records in 4.2s.&#8217;,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=&#8217;Status&#8217;, border_style=&#8217;green&#8217;))<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Inspecting Objects<\/strong><\/h3>\n\n\n\n<p>rich.inspect() prints a formatted overview of any Python object: its type, attributes, and methods, making it a powerful debugging tool:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>from rich import inspect<br>import requests<br>r = requests.get(&#8216;https:\/\/httpbin.org\/get&#8217;)<br>inspect(r, methods=<strong>True<\/strong>) &nbsp; # shows all attributes and callable methods<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Python Rich Library: Feature Quick Reference<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Feature<\/strong><\/td><td><strong>Class \/ Function<\/strong><\/td><td><strong>Use Case<\/strong><\/td><\/tr><tr><td><strong>Styled text<\/strong><\/td><td>print() \/ Console.print()<\/td><td>Colour, bold, italic terminal output<\/td><\/tr><tr><td><strong>Structured tables<\/strong><\/td><td>Table<\/td><td>Display data in column-aligned format<\/td><\/tr><tr><td><strong>Progress bars<\/strong><\/td><td>Progress<\/td><td>Track long-running tasks in real time<\/td><\/tr><tr><td><strong>Syntax highlighting<\/strong><\/td><td>Syntax<\/td><td>Display code with language colouring<\/td><\/tr><tr><td><strong>Panels<\/strong><\/td><td>Panel<\/td><td>Box-framed sections in terminal output<\/td><\/tr><tr><td><strong>Object inspection<\/strong><\/td><td>inspect()<\/td><td>Debug any Python object interactively<\/td><\/tr><tr><td><strong>Logging integration<\/strong><\/td><td>Console.log()<\/td><td>Timestamped, styled debug logging<\/td><\/tr><tr><td><strong>Live display<\/strong><\/td><td>Live<\/td><td>Update any renderable in place<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Mistakes When Using the Python Rich Library<\/strong><\/h2>\n\n\n\n<p><strong>1. Importing print from rich globally and breaking third-party code: <\/strong>from rich import print replaces the built-in globally in that module. If a third-party library imports print from your module&#8217;s namespace, it may receive Rich&#8217;s version unexpectedly. Prefer Console().print() for explicit, scoped usage in production code.<\/p>\n\n\n\n<p><strong>2. Using Rich markup characters in raw data: <\/strong>Square brackets in Rich output are interpreted as markup tags. If you print user data or paths that contain square brackets, they may be misinterpreted or swallowed. Use console.print(data, markup=False) or escape them with rich. markup.escape(data) before printing.<\/p>\n\n\n\n<p><strong>3. Creating a new Console instance per call: <\/strong>Instantiating Console() repeatedly can cause inconsistent width detection and output buffering. Create a single Console instance at module level and reuse it across your application.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>The Python Rich library transforms what terminal output can be from a raw stream of text into a structured, readable, professional interface for your scripts and tools. Whether you are logging pipeline results, debugging data transformations, or building a developer CLI, Rich&#8217;s tables, progress bars, syntax highlighting, and panels make your output significantly more useful with very little extra code. The best way to start is to add Rich to a script you already have: replace one print() with a styled console.print(), wrap one data structure in a Table, and add a Progress bar to one loop.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQ<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1782191250252\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">1.\u00a0 \u00a0 <strong>What is the Python Rich library?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Rich is a third-party Python library that adds beautiful, colourful, formatted output to terminal applications. It supports styled text with markup tags, tables, progress bars, syntax-highlighted code, panels, live displays, and object inspection all without requiring special terminal configurations.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782191255491\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">2.\u00a0 \u00a0 <strong>How do I install the Python Rich library? <\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Install Rich using pip: pip install rich. It has no mandatory external dependencies and works on Windows, macOS, and Linux in any modern terminal. For syntax highlighting, Rich uses Pygments, which is included as an optional dependency.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782191280964\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">3.\u00a0 \u00a0 <strong>What is the difference between rich.print and the built-in print? <\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>from rich import print replaces the built-in with a version that accepts markup tags like [bold red] for inline styling. It is a drop-in replacement for simple cases but can cause issues with raw data containing square brackets. For production code, prefer using a Console instance directly.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782191318723\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">4.\u00a0 \u00a0 <strong>How do I display a table in the terminal using Rich? <\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Create a Table object, add columns with table.add_column(), add rows with table.add_row(), then print it with console.print(table). You can customise column styles, alignment, border style, and column width to match the data you are displaying.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782191333371\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">5.\u00a0 \u00a0 <strong>Can Rich display real-time progress bars? <\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes. Rich&#8217;s Progress class renders smooth, multi-task progress bars that update in place. Use it as a context manager, add tasks with progress.add_task(), and call progress.update() with advance= to update each task&#8217;s completion. SpinnerColumn, TimeElapsedColumn, and other built-in columns can be composed freely.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782191346719\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">6.\u00a0 \u00a0 <strong>How does Rich handle syntax highlighting?\u00a0<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Rich uses the Syntax class to highlight code in any language supported by Pygments. Pass the code string, language name, and a theme name (such as &#8216;monokai&#8217; or &#8216;github-dark&#8217;) to Syntax(), then print it with a Console instance. Line numbers can be shown with line_numbers=True.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782191418786\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">7.\u00a0 \u00a0 <strong>What is rich.inspect() used for?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>rich.inspect(obj) prints a formatted overview of any Python object, including its type, attributes, and optionally its methods. It is a powerful debugging tool that reveals far more than print(dir(obj)) while remaining readable in the terminal.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Most Python developers have written scripts whose output is a wall of plain print() statements no structure, no colour, no way to tell what is important. The Python Rich library solves this comprehensively. Created by Will McGuinnen and released in 2020, Rich turned terminal output from an afterthought into a first-class experience. In this blog, [&hellip;]<\/p>\n","protected":false},"author":63,"featured_media":119392,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[717],"tags":[],"views":"38","authorinfo":{"name":"Vishalini Devarajan","url":"https:\/\/www.guvi.in\/blog\/author\/vishalini\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/06\/python-rich-library-300x120.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/118157"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=118157"}],"version-history":[{"count":5,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/118157\/revisions"}],"predecessor-version":[{"id":121949,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/118157\/revisions\/121949"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/119392"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=118157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=118157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=118157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}