API Reference¶
compile¶
- d2.compile(code: str, library: str | None = None, theme: str = 'light', adi: bool = False) str | None¶
Compile D2 diagram code to SVG.
- Parameters:
code – D2 diagram source code.
library – Component library to include. Either
"adi"for Analog Devices signal-chain components,"sw"for software/AI architecture components,"jif"for pyadi-jif block diagrams,"datax"for ADI DataX overview diagrams,"clean"for the flat neutral/clay technical diagramming components, orNonefor plain D2 compilation.theme – Theme variant when a library is used. Either
"light"or"dark".adi – Deprecated. Use
library="adi"instead.
- Returns:
SVG string on success, None on failure.
- Raises:
RuntimeError – If D2 compilation or rendering fails.
ValueError – If both adi and library are set, or if library is not a recognized name.
Constants¶
ADI Library¶
- d2.ADI_COMPONENTS: list[str]¶
List of all 64 ADI component class names (see ADI Shapes).
SW Library¶
- d2.SW_THEME_CLASSES: list[str]¶
List of all SW theme class names:
[ "sw-container", "sw-container-cream", "sw-container-green", "sw-container-amber", "sw-container-red", "sw-container-white", "sw-step-blue", "sw-step-green", "sw-step-amber", "sw-step-white", "sw-title", "sw-subtitle", "sw-note", "sw-flow", "sw-flow-data", "sw-flow-control", "sw-flow-async", "sw-flow-error", "sw-flow-success", "sw-flow-feedback", "sw-flow-light", ]
JIF Library¶
- d2.JIF_COMPONENTS: list[str]¶
List of all JIF component class names used by pyadi-jif
Node.ntypevalues (see JIF Shapes).
DataX Library¶
- d2.DATAX_COMPONENTS: list[str]¶
List of DataX semantic box class names (see ADI DataX Overview Library).
- d2.DATAX_THEME_CLASSES: list[str]¶
List of DataX typography, panel, band, and flow class names (see ADI DataX Overview Library).
clean Library¶
- d2.CLEAN_COMPONENTS: list[str]¶
List of the 21 clean component class names (flat, neutral-tint + clay-accent technical diagramming shapes; see clean Shapes).