Sunday, August 9, 2020

Will McGugan: A prettier Python REPL with Rich

Rich 5.1.0 adds the ability to integrate highlighted pretty printing with the Python REPL. Here's how you would use it in a session:

>>> from rich import pretty
>>> pretty.install()

Assuming you have installed Rich of course.

Now any data will be formatted and highlighted. Here's an example:

© 2020 Will McGugan

Rich will expand builtin containers until the output fits in to the width of the screen.

In addition to Python data structures, any object supporting the Rich Console Protocol will be displayed. Here's an example:

© 2020 Will McGugan

The Panel class is one of a number of renderables in Rich.

The formatting and highlighting really comes in to its own when you're working with JSON data. The following video shows an example of pretty printing data queried from a web service. In this instance, its cat facts.

Just discovered Rich?

Follow @willmcgugan for updates regarding Rich.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...