Utilities for working with marimo notebooks: Pydantic model display plus a Tailwind + shadcn UI primitives package
Project description
marimo-utils
Utilities for working with marimo notebooks.
Installation
pip install marimo-utils
Usage
@add_marimo_display() decorator
Adds a _display_ method to Pydantic models for rich rendering in marimo notebooks.
from pydantic import BaseModel
from marimo_utils import add_marimo_display
@add_marimo_display()
class MyConfig(BaseModel):
name: str
value: int
When a MyConfig instance is the last expression in a marimo cell, it renders with the class name, source file path, and all field values.
marimo_utils.ui — Tailwind + shadcn primitives for marimo
Pydantic-backed UI primitives that render through Tailwind (Play CDN) themed with shadcn/ui defaults. The package ships small composable atoms (Badge, CardTitle, CardDescription, DataItem, DateStamp, LabeledList, LucideIcon, ProjectStamp), a flexible Card container, and a plotly-backed chart family (BarChart, HeatmapChart, HistogramChart, LineChart, PieChart, ScatterChart, ViolinChart) sharing a common PlotlyChart base. Call bootstrap_tailwind() once in a notebook to inject shadcn's CSS variables on :root plus the utility rules that depend on them, then load the Tailwind CDN.
import marimo as mo
from marimo_utils.ui import (
BarChart, BarItem, Card, ChartColor, bootstrap_tailwind,
)
bootstrap_tailwind()
Card(
title="Class Distribution",
description="Class counts across the training split",
content=BarChart(
items=[
BarItem(label="Class A", value=5),
BarItem(label="Class B", value=10),
BarItem(label="Class C", value=5, color=ChartColor.THREE),
BarItem(label="Class D", value=1),
],
height=220,
),
width="w-80",
).render()
Components use shadcn's stock variant names (default, secondary, destructive, outline). Charts cycle through the --chart-1 → --chart-5 palette by default; pin specific items with color=ChartColor.X. Every PlotlyChart subclass renders through the same contract: plotly HTML with responsive: true + include_plotlyjs="cdn", a .reactive() opt-in for marimo-reactive widgets, and a Card-friendly transparent background. <script>-bearing HTML (plotly) is routed through dr_widget.inline.ActiveHtml so charts execute inside marimo's React tree.
See nbs/ui_components.py for a live demo of every atom, chart, and card variant side-by-side.
Changes
0.6.0 — Tailwind + shadcn UI package
- Breaking: removes
marimo_utils.style(the inline-CSS design system) and renames the Tailwind implementation frommarimo_utils.twto the canonicalmarimo_utils.ui. - Adds
ScatterChart/ScatterSeriesandLineChart/LineSeries(with solid/dotted/dashed styling viaLineDash) — multi-series numeric-axis charts that acceptx_rangeandy_range. - Every chart section in
nbs/ui_components.pynow renders both a standalone chart and a Card-wrapped variant viamo.hstack, exercising the shadow-DOM embedding path uniformly. - Renames the demo notebook from
nbs/style_components_tw.pytonbs/ui_components.py.
Migration from 0.5.x. The rename is not purely syntactic — marimo_utils.ui uses shadcn's stock variant names (default, secondary, destructive, outline) instead of the old tone palette, and charts use ChartColor.ONE..FIVE instead of PaletteToneName. Common translations:
0.5.x (marimo_utils.style) |
0.6.0 (marimo_utils.ui) |
|---|---|
from marimo_utils.style import ... |
from marimo_utils.ui import ... |
Style.default() / passing style=... |
removed — call bootstrap_tailwind() once per notebook |
Title(drop_text=..., text=...) |
CardTitle(text=...) + CardDescription(text=...) |
PaletteToneName.SUCCESS / .WARNING / .DANGER |
ChartColor.ONE..FIVE (neutral categorical palette) |
Style.tone_colorscale(tone) |
chart_colorscale(ChartColor.X) |
Card(style=..., width="22rem", height="22rem", title=..., content=...) |
Card(title=..., description=..., content=..., width="w-80").render() (Tailwind width utilities) |
Chart height=None for responsive fill inside a sized Card |
Charts have fixed default heights; pass explicit height=220 for in-card use |
See nbs/ui_components.py for current usage of every atom and chart.
0.5.0
- Adds four Card-ready chart primitives alongside
PieChart:BarChart/BarItem,HistogramChart,ViolinChart/ViolinGroup,HeatmapChart. All share per-tone palette colors viaPaletteToneNameand plug intoCardthe same wayPieChartdoes. - Refactors the charts module into a subpackage with a shared
PlotlyChartbase that owns_repr_html_,__str__,reactive(), empty-state rendering, and dimension application. Subclasses implement only_has_dataand_build_figure. - Adds a two-stop
[bg → border]sequential colorscale helper for heatmap / choropleth use. - Turns on plotly responsive mode by default (
PlotlyChart.responsive = True, config passed topio.to_html). Charts now default towidth=None(fill container) and resize with their wrapper. - Adds
Card.heightso cards become adisplay: flex; flex-direction: columncontainer and responsive charts fill the remaining vertical space.
0.4.0
- Routes
<script>-bearing HTML fragments (notably Plotly) throughdr_widget.inline.ActiveHtmlso Plotly charts render inside aCardeven though marimo's React tree strips inline scripts. - Drops the local
_active_html.pycopy;ActiveHtmlnow lives in thedr-widgetpackage. - Adds
dr-widgetas a dependency.
0.3.0
- Hard-cuts the design package to a notebook-native render contract for marimo notebooks.
- Keeps
mohtmlas the HTML authoring layer for styled atoms while makingCardslots compatible with native notebook outputs. - Adds reusable pie-chart primitives (
PieChart,PieSlice) for chart-in-card composition.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file marimo_utils-0.7.0.tar.gz.
File metadata
- Download URL: marimo_utils-0.7.0.tar.gz
- Upload date:
- Size: 156.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df04390f6cc5165aa4976296b3cc1c7b295667c7ab27ec9b2c47adf01b536d35
|
|
| MD5 |
3cce007f3a01645571275223d52de88d
|
|
| BLAKE2b-256 |
8fcab9914c2c839f66a1e63f2ee07cb195db0a08269f11a862477e2f754d609b
|
File details
Details for the file marimo_utils-0.7.0-py3-none-any.whl.
File metadata
- Download URL: marimo_utils-0.7.0-py3-none-any.whl
- Upload date:
- Size: 38.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63b1532f3dce3578b63d2d81a45352a176ba52469090280d52e12f860180ac42
|
|
| MD5 |
581b686a3d064d319bda2e3ee5825fb7
|
|
| BLAKE2b-256 |
8a1822191333ad07af7b6e1866341746203ac29c7f6956d686d57fa8060162d9
|