How to get Rich with Python (a terminal rendering library)
I'm happy to announce the release of version 1.0.0 of Rich - my Python library for fancy terminal rendering.
Rich is a project I started back in October 2019 when I was staying in Wuhan, a few weeks before it was locked down. Back then it was a toy project designed to pass the time while traveling. In the spirit of XKCD 927 I wanted to create a library that could display rich content in the terminal as effortlessly as you can with HTML.
Naturally, it took a lot longer than I had anticipated. Once I had the core feature of text which can word wrap while preserving style attributes, I used it to implement syntax highlighting, Markdown rendering, pretty tracebacks, progress bars, and more. At the risk of over-engineer I've drawn a line in the core feature set for this
1.0 release, which has enough batteries incuded for now.
Rich is also something of a framework in that it defines a protocol you can use to render custom objects with style and color to the terminal. This could be rich text, but could also be a table or markdown. Here's a trivial example from the docs:
Rich already knows how to render simple types, and will pretty print and colorize containers by default. Here's an example that shows what happens when you print a
dict with Rich:
console.log which I always miss when working in the back-end.
I'm hoping that library developers will begin to implement the Rich protocol. At the simplest level it doesn't even require you to add Rich as a dependancy.
Rich is production ready, with high test coverage, and completely typed. It follows semver. See the Rich docs for the details.
I can forgive the clickbait title but not the pun. Also, this is an amazing library!
Thanks, Evan. And sorry.
Hi! Great library. Can I somehow clear the screen using the library? Currently I do:
Not currently, but that seems something that is worth adding. Could you post an issue on the Github repos to remind me? https://github.com/willmcgugan/rich
Hi, is there any simple way to use Rich in Visual Studio Code?
Hi. Rich works fine in the vscode terminal. Are you having problems with it?
I guess it works, but I have to use the
printto get the beautiful output, right? What I asked is that if there is any vscode extension that beautifies the console output automatically. My line of work is data analysis so I often look up contents of arrays and DataFrames in console. It would be great if I just type an object name in console and get the beautified output.
Ah. The only way that could work would be by wrapping stdout. Which is theoretically possible. I'll think about it. It actually sounds like Jupyter would be more the tool of your trade than the terminal.
Thank you, I look forward to it.
Hi, Thanks for this great library. Is it possible to add a list as row.
I went through your examples and figured it out. Thanks for this wonderful library again.