Search

Rich, a Python library for more stylish output

Display tables, HTML and more from the terminal.


Rich, a Python library for more stylish output

Making context outputs more elegant is the challenge for almost everyone wherever they go: console, web, mobile or graphical.

The Rich library is the most innovative in this regard and your TUI apps will look even more professional!

This API makes it easy to add color and style to terminal output. It can also render beautiful tables, progress bars, markdown, syntax highlighted source code, tracebacks and more - ready to use.

Installation

To install it is very simple, just use pip, you can install only for your user:


pip install rich --user

Or for your entire system

sudo pip install rich

Use

At first you can see all the formatting possibilities by running the command:

python -m rich

The output will be something like:

Rich

Another basic example of usage, using style and hexadecimal colors: vim hello.py

from rich.console import Console

console = Console()
console.print("Terminal", "Root", style="#ccc010 bold")

Run: python hello.py, exit:

Rich, a Python library for more stylish output

You can even use HTML-style tags, but with square brackets, for example:

from rich.console import Console

console = Console()
console.print("[bold]Website[/bold]: [bold cyan]Terminal Root[/bold cyan] [u]Linux[/u] [i]and[/i] [bold yellow]Programming[/bold yellow].")

In addition to tables, see this gif:

GIF

Access the repository on GitHub and learn more:

https://github.com/willmcgugan/rich


python


Share



Comments