D2 Widget

Visualization Opensource Full-stack Platform
D2 Widget

A Python widget that eliminates the friction of creating diagrams in notebooks by integrating the D2 declarative language directly into Jupyter and Marimo. It restores the interactive workflow by providing live, text-based diagramming with inline previews, removing the need for external tools and context switching.

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 was created to solve that problem by bringing the diagramming process back into the notebook. It integrates the declarative diagram language D2 directly into environments like Jupyter and Marimo , allowing you to write text-based diagrams and see live, interactive previews inline. The goal is to treat diagrams as code—versionable, reproducible, and seamlessly integrated with the surrounding analysis.

The implementation is designed to feel native to the notebook. It uses anywidget to bridge the Python backend with a lightweight frontend, ensuring a smooth user experience without heavy dependencies. By handling the complexities of different notebook environments behind the scenes, it provides a clean and simple API for both quick, ad-hoc visualizations 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: