D2 Widget

Visualization Opensource Full-stack Platform
D2 Widget

A Python widget that embeds the D2 diagram language directly into Jupyter and Marimo. It provides live, text-based diagramming with inline previews, so diagrams stay close to the surrounding analysis.

The workflow for creating diagrams in computational notebooks is often a broken experience. It forces a context switch to external tools, reducing a dynamic process of thought and exploration into a static one of importing and managing images. This interruption breaks the very interactive loop that makes notebooks a powerful environment for analysis and documentation.

This widget brings the diagramming process back into the notebook. It integrates the declarative diagram language D2 directly into environments like Jupyter and Marimo , so you can write text-based diagrams and see live previews inline. The goal is to treat diagrams as code: versionable, reproducible, and integrated with the surrounding analysis.

The implementation uses anywidget to bridge the Python backend with a lightweight frontend. By handling notebook-specific integration details behind the scenes, the widget stays simple to use for quick sketches and programmatic diagram generation.

Stack

While the problem is more important than the tools, the tech stack tells a story about the project's architecture and trade-offs. Here's what this project is built on: