Skip to main content

Utilities for working with marimo notebooks, including Pydantic model display and a notebook-native hybrid design system

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.style — notebook-native design primitives

A small design-system for rendering Pydantic-backed inspection cards in marimo notebooks. The style system is notebook-native: components return marimo renderables, cards can host both styled HTML fragments and native notebook outputs, and mohtml remains the HTML authoring tool for the styled atoms. The package includes tokens (Style, ColorPalette, Typography, SpacingScale), atoms (Badge, Title, DataItem, DateStamp, ProjectStamp, LabeledList, MetaStamp), a flexible Card container, and a plotly-backed chart family (PieChart, BarChart, HistogramChart, ViolinChart, HeatmapChart) that share a common PlotlyChart base.

from marimo_utils.style import (
    BarChart, BarItem, Card, PaletteToneName, Style, Title,
)

style = Style.default()

card = Card(
    style=style,
    width="22rem",
    height="22rem",  # optional; omit for unconstrained height
    title=Title(
        style=style,
        drop_text="Bar Card",
        text="Class Distribution",
    ).render(),
    content=BarChart(
        style=style,
        height=None,  # responsive: fills remaining vertical space in the card
        items=[
            BarItem(label="Samples", value=120, tone=PaletteToneName.SUCCESS),
            BarItem(label="Pending", value=18, tone=PaletteToneName.WARNING),
            BarItem(label="Failed", value=3, tone=PaletteToneName.DANGER),
        ],
    ),
).render()

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 tone-driven palette (PaletteToneName) that unifies colors across atoms and charts. Style.tone_colorscale(tone) provides a matching sequential gradient for heatmaps. Card accepts any HtmlRenderable as content; <script>-bearing HTML (plotly) is routed through dr_widget.inline.ActiveHtml so charts execute inside marimo's React tree.

Sizing model. Charts default to width=None (fill container) with responsive=True, and each chart type keeps a sensible fixed height. Pass explicit ints to pin either dimension; pass height=None to let plotly fill a constrained Card(height=...) vertically.

See nbs/style_components.py for a live demo of every atom, chart, and card variant, and IMPORT_STYLE.md for design notes on the mohtml leverage points and CSS helper.

Changes

0.5.0

  • Adds four Card-ready chart primitives alongside PieChart: BarChart / BarItem, HistogramChart, ViolinChart / ViolinGroup, HeatmapChart. All share per-tone palette colors via PaletteToneName and plug into Card the same way PieChart does.
  • Refactors marimo_utils.style.charts into a subpackage with a shared PlotlyChart base that owns _repr_html_, __str__, reactive(), empty-state rendering, and dimension application. Subclasses implement only _has_data and _build_figure. Public imports are unchanged — everything is still re-exported from marimo_utils.style.
  • Adds Style.tone_colorscale(tone) — a two-stop [bg → border] sequential colorscale for heatmap / choropleth use.
  • Turns on plotly responsive mode by default (PlotlyChart.responsive = True, config passed to pio.to_html). Charts now default to width=None (fill container) and resize with their wrapper.
  • Adds Card.height: str | None = None (CSS value). When set, the card becomes a display: flex; flex-direction: column container and wraps its content region with flex: 1 1 auto; min-height: 0 so a responsive chart (height=None) fills the remaining vertical space below the title and header.

0.4.0

  • Routes <script>-bearing HTML fragments (notably Plotly) through dr_widget.inline.ActiveHtml so Plotly charts render inside a Card even though marimo's React tree strips inline scripts.
  • Drops the local _active_html.py copy; ActiveHtml now lives in the dr-widget package.
  • Adds dr-widget as a dependency.

0.3.0

  • Hard-cuts marimo_utils.style to a notebook-native render contract for marimo notebooks.
  • Keeps mohtml as the HTML authoring layer for styled atoms while making Card slots 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

marimo_utils-0.5.0.tar.gz (133.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

marimo_utils-0.5.0-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file marimo_utils-0.5.0.tar.gz.

File metadata

  • Download URL: marimo_utils-0.5.0.tar.gz
  • Upload date:
  • Size: 133.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.0

File hashes

Hashes for marimo_utils-0.5.0.tar.gz
Algorithm Hash digest
SHA256 62d14844773ee89e7a9dd2378f2606775f94a1864fc890fc8bfc3cbd8f23cde8
MD5 9ad14e40ead547d224d38e40d989cee0
BLAKE2b-256 c43d33b830145c56561fdd6d17822697f119b63a9ab82c5a37de1f34f780808d

See more details on using hashes here.

File details

Details for the file marimo_utils-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for marimo_utils-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e80377f749b875dd5b84a6df36d65e2205a9b68c736a05614e5db92c4791aa19
MD5 feb6261752007a7cc706b17e47a43aaa
BLAKE2b-256 4dccbf03179ac18268ae25a845461dc5aed54e8729dcff6363c8145be9551498

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page