Posts tagged: rich

All posts with the tag "rich"

1 posts latest post 2023-07-29
Textual - Using Rich Inspect to interrogate Python objects Textual is a TUI framework for Python, inspired by modern web development. Textual Documentation · textual.textualize.io I love rich inspect. It’s one of my most often used features of rich. It gives you a great human readable insight into python object instances. I have a pyflyby entry for it so that I can just run it ang get automatic imports. To not clash with the standard library inspect, which is quite useful on it’s own, I have aliased it to.

Adding a __render__ method that returns a rich renderable to any python class makes it display this output if printed with rich. This also includes being nested inside a rich Layout.

import rich
from rich.panel import Panel


class ShowMe:
    def __rich__(self):
        return Panel("hello", border_style="gold1")


if __name__ == "__main__":
    rich.print(ShowMe())
results of printing ShowMe with rich