pyd2lang-native¶
Native Python bindings for the d2lang diagram compiler.
Compile D2 diagram code to SVG directly from Python without requiring the d2 CLI.
Includes five built-in component libraries with ADI brand themes:
ADI — 64 analog/mixed-signal shapes for signal chain diagrams
SW — 32 software/AI shapes for architecture and agent pipeline diagrams
JIF — pyadi-jif block diagram shapes for converters, clocks, JESD, and FPGA paths
DataX — overview styles matching the SVG diagrams in ADI DataX docs
clean — 21 flat neutral/clay technical diagramming classes with light and dark themes
Installation¶
pip install pyd2lang-native
Quick Start¶
import d2
svg = d2.compile("x -> y")
With ADI components:
import d2
code = """
direction: right
adc1: AD7606 { class: adc }
filt1: LTC1560 { class: filter-lp }
amp1: LT6230 { class: amplifier }
amp1 -> filt1: Analog { class: adi-signal-analog }
filt1 -> adc1: Filtered { class: adi-signal-analog }
"""
svg = d2.compile(code, library="adi")
With SW components:
import d2
code = """
agent: Auditor { class: sw-agent }
model: Claude { class: sw-model }
tool: Search { class: sw-tool }
doc: Seed { class: sw-document }
doc -> agent { class: sw-flow-data }
agent -> tool -> model { class: sw-flow }
model -> agent { class: sw-flow-feedback }
"""
svg = d2.compile(code, library="sw")
With JIF components:
import d2
code = """
direction: right
adc: ADC { class: adc }
ddc: DDC { class: ddc }
framer: JESD204 Framer { class: jesd204framer }
adc -> ddc -> framer
"""
svg = d2.compile(code, library="jif")
With DataX overview styles:
import d2
code = """
direction: down
title: ADI DataX Stack { class: datax-title }
panel: Layers { class: datax-panel
app: Applications { class: datax-application }
lib: libiio / pyadi-iio { class: datax-info }
drv: Linux IIO Drivers { class: datax-driver }
hw: Hardware { class: datax-hardware }
app -> lib -> drv -> hw { class: datax-flow }
}
"""
svg = d2.compile(code, library="datax")