DEV Community

Waylon Walker
Waylon Walker

Posted on • Edited on • Originally published at waylonwalker.com

5 2

Adding __rich__ methods to python classes

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 of 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())
Enter fullscreen mode Exit fullscreen mode

results of printing ShowMe with rich


I'm shortening up my content pipeline and getting small ideas out more often by creating small tils that will eventually bubble up into larger peices.

All of my tils are on my website -> https://waylonwalker.com/til

Top comments (0)

Image of PulumiUP 2025

Let's talk about the current state of cloud and IaC, platform engineering, and security.

Dive into the stories and experiences of innovators and experts, from Startup Founders to Industry Leaders at PulumiUP 2025.

Register Now

👋 Kindness is contagious

Dive into this insightful write-up, celebrated within the collaborative DEV Community. Developers at any stage are invited to contribute and elevate our shared skills.

A simple "thank you" can boost someone’s spirits—leave your kudos in the comments!

On DEV, exchanging ideas fuels progress and deepens our connections. If this post helped you, a brief note of thanks goes a long way.

Okay