Rich is a Python library for rich text and beautiful formatting in the terminal.
Go to file
Will McGugan bf7fa2d5ad add images 2019-12-23 16:31:22 +00:00
examples integrated markdown rendering 2019-12-21 22:24:15 +00:00
imgs add images 2019-12-23 16:31:22 +00:00
rich add images 2019-12-23 16:31:22 +00:00
tests added examples 2019-12-18 16:46:24 +00:00
tools emoji support 2019-11-26 17:38:47 +00:00
.gitignore readme 2019-12-23 16:21:51 +00:00
Makefile readme 2019-12-23 16:21:51 +00:00
README.md add images 2019-12-23 16:31:22 +00:00
poetry.lock log highlighter 2019-12-16 19:34:27 +00:00
pyproject.toml log highlighter 2019-12-16 19:34:27 +00:00

README.md

Rich

Rich is a Python library for rich text and advanced formatting to the terminal. Rich provided an easy to use API for colored text (up to 16.7million colors) with bold / italic / underline etc. and a number of more sophisticated formatting options, such as syntax / regex highlighting, emoji, tables, and markdown rendering.

Rich is also a framework in that it implements a simple protocol which you may use to make custom objects renderable with advanced terminal formatting.

Installing

Rich may be installed with pip or your favorite PyPi package manager.

pip install rich

Basic Usage

The first step to using the rich console is to import and construct the Console object.

from rich.console import Console

console = Console()

Most applications will require one Console instance. The easiest way to manage your console instance would be to construct an instance at the module level and import it where needed.

The Console object has a print method which has an intentionally similar interface to the builtin print function. Here's an example of use:

console.print("Hello", "World!")

As you might expect, this will print "Hello World!" to the terminal. The only difference from the print function is that the output is word-wrapped by default (Rich auto-detects the width of the terminal).

There are a few ways of adding color and style to your output. You can set a style for the entire output, by adding a style keyword argument. Here's an example:

console.print("Hello", "World!", style="bold red")

The output will be something like the following:

Hello World! 

That's fine for styling a line of text at a time. For more finely grained styling, Rich renders a special markup which is similar in syntax to bbcode. Here's an example:

console.print("Where there is a [b]Will[/b] there is a [i]way[/i].")
Where there is a Will there is a way. 

Emoji

Rich supports a simple way of inserting emoji in to terminal output, by using the name of the emoji between two colons. Here's an example:

console.print(":smiley: :vampire: :pile_of_poo: :thumbs_up: :raccoon:")
😃 🧛 💩 👍 🦝 

Please use this feature wisely.