Three Rich tips
I've mentioned Will McGugan's excellent library Rich on this blog before. It is a great tool for building nice terminal interfaces, but it is also an important local development tool. Here's three top tips:
- Rich can be registered as a handler to render stacktraces. As well as the aesthetics, using Rich to handle stacktraces like this provides additional context which improves the usefulness of error messages in comparison to python's default handler.
-
Rich.inspect can be used to examine a python object at runtime. I used to use
dir()
orvars()
for this, butrich.inspect()
is a big step up. - Rich can be used as a log handler. The docs cover how to use it with python's
logging
module, but Will has also published this blog post showing how to configure Django to use Rich as the default log handler.