

GitHub - Textualize/rich: Rich is a Python library for rich text and beautiful f...
source link: https://github.com/Textualize/rich
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Textualize/rich: Rich is a Python library for rich text and beautiful formatting in the terminal.
Files
English readme • 中文 readme • Lengua española readme • Deutsche readme • Läs på svenska • 日本語 readme • 한국어 readme • Français readme • Schwizerdütsch readme • हिन्दी readme • Português brasileiro readme • Italian readme • Русский readme
Rich is a Python library for rich text and beautiful formatting in the terminal.
The Rich API makes it easy to add color and style to terminal output. Rich can also render pretty tables, progress bars, markdown, syntax highlighted source code, tracebacks, and more — out of the box.
For a video introduction to Rich see calmcode.io by @fishnets88.
See what people are saying about Rich.
Compatibility
Rich works with Linux, OSX, and Windows. True color / emoji works with new Windows Terminal, classic terminal is limited to 16 colors. Rich requires Python 3.6.1 or later.
Rich works with Jupyter notebooks with no additional configuration required.
Installing
Install with pip
or your favorite PyPI package manager.
python -m pip install rich
Run the following to test Rich output on your terminal:
python -m rich
Rich Print
To effortlessly add rich output to your application, you can import the rich print method, which has the same signature as the builtin Python function. Try this:
from rich import print print("Hello, [bold magenta]World[/bold magenta]!", ":vampire:", locals())
Rich REPL
Rich can be installed in the Python REPL, so that any data structures will be pretty printed and highlighted.
>>> from rich import pretty >>> pretty.install()
Using the Console
For more control over rich terminal content, import and construct a Console object.
from rich.console import Console console = Console()
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. Note that unlike the builtin print
function, Rich will word-wrap your text to fit within the terminal width.
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:
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 [bold cyan]Will[/bold cyan] there [u]is[/u] a [i]way[/i].")
You can use a Console object to generate sophisticated output with minimal effort. See the Console API docs for details.
Rich Inspect
Rich has an inspect function which can produce a report on any Python object, such as class, instance, or builtin.
>>> my_list = ["foo", "bar"] >>> from rich import inspect >>> inspect(my_list, methods=True)
See the inspect docs for details.
Rich Library
Rich contains a number of builtin renderables you can use to create elegant output in your CLI and help you debug your code.
Click the following headings for details:
Log
Logging Handler
Emoji
Tables
Progress Bars
Status
Tree
Columns
Markdown
Syntax Highlighting
Tracebacks
All Rich renderables make use of the Console Protocol, which you can also use to implement your own Rich content.
Rich for enterprise
Available as part of the Tidelift Subscription.
The maintainers of Rich and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. Learn more.
Projects using Rich
Here are a few projects using Rich:
- BrancoLab/BrainRender a python package for the visualization of three dimensional neuro-anatomical data
- Ciphey/Ciphey Automated decryption tool
- emeryberger/scalene a high-performance, high-precision CPU and memory profiler for Python
- hedythedev/StarCli Browse GitHub trending projects from your command line
- intel/cve-bin-tool This tool scans for a number of common, vulnerable components (openssl, libpng, libxml2, expat and a few others) to let you know if your system includes common libraries with known vulnerabilities.
- nf-core/tools Python package with helper tools for the nf-core community.
- cansarigol/pdbr pdb + Rich library for enhanced debugging
- plant99/felicette Satellite imagery for dummies.
- seleniumbase/SeleniumBase Automate & test 10x faster with Selenium & pytest. Batteries included.
- smacke/ffsubsync Automagically synchronize subtitles with video.
- tryolabs/norfair Lightweight Python library for adding real-time 2D object tracking to any detector.
- ansible/ansible-lint Ansible-lint checks playbooks for practices and behaviour that could potentially be improved
- ansible-community/molecule Ansible Molecule testing framework
- +Many more!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK