Rich & Textual
Why do I need it?
These two co-related modules will make your command line tools better. “Rich is a Python library for rich text and beautiful formatting in the terminal”, “Textual is a TUI (Text User Interface) framework for Python inspired by modern web development.” which uses Rich for printing. See https://github.com/Textualize/rich and https://github.com/Textualize/textual
It can also do logging, better REPL printing, trees and much more!
install
pip install textual
import
import rich
Why would I use it?
If your making a command line tool this will allow you to create a simple UI (and much easier than using ncurses )
Show me more!
#!/usr/bin/env python
from rich import print
print("We can just replace [bold magenta]print[/bold magenta]!")
print("We can use emoji's",":smiley:")
Simple progress bars
#!/usr/bin/env python
from rich.progress import track
def do_work(s) :
for i in range(0,10000000) :
pass
for step in track(range(100)):
do_work(step)
Make the REPL better
>>> from rich import pretty
>>> pretty.install()
Better inspect
from rich import inspect
import math
inspect(math.cos,methods=True)