Richly display objects¶
marimo has built-in rich representations of many objects, including native
Python objects like lists and dicts as well as marimo objects like UI
elements and libraries, including matplotlib,
seaborn, Plotly, altair pandas, and more. These rich representations are
displayed for the last expression of a cell, or when using
mo.output.append.
You can register rich displays with marimo for your own objects.
Option 1: Implement an IPython _repr_*_() method¶
marimo can render objects that implement
IPython’s _repr_*_() protocol
for rich display. Here is an example of implementing _repr_html_, borrowed
from IPython’s documentation:
class Shout:
def __init__(self, text):
self.text = text
def _repr_html_(self):
return "<h1>" + self.text + "</h1>"
We support the following methods:
_repr_html__repr_mimebundle__repr_svg__repr_json__repr_png__repr_jpeg__repr_markdown__repr_latex__repr_text_
Option 2: Implement a _mime_ method¶
When displaying an object, marimo’s media viewer checks for the presence of a
method called _mime_. This method should take no arguments and return
a tuple of two strings, the mime type and data to be displayed as a string.
Examples.
Option 3: Add a formatter to the marimo repo¶
The recommended way to render rich displays of objects in marimo is to
implement either the IPython _repr_*_()_ protocol or marimo’s _mime_()
protocol. If you are a a user of a library that does not render properly in
marimo, consider asking the library maintainers to implement one of these
protocols.
If it is not possible to implement a renderer protocol on the type you want displayed, we will consider contributions to add formatters to the marimo codebase. Look at our codebase for examples, then open a pull request.