Using raw DOTΒΆ

To render a ready-made DOT source code string (instead of assembling one with the higher-level interface of Graph or Digraph), create a graphviz.Source object holding your DOT string:

>>> import graphviz

>>> src = graphviz.Source('digraph "the holy hand grenade" { rankdir=LR; 1 -> 2 -> 3 -> lob }')

>>> src
<graphviz.sources.Source object at 0x...>

Use the render() method to save and render it:

>>> doctest_mark_exe()

>>> src.render('doctest-output/holy-grenade.gv').replace('\\', '/')
'doctest-output/holy-grenade.gv.pdf'
>>> doctest_mark_exe()

>>> src.render('doctest-output/holy-grenade.gv', view=True).replace('\\', '/')
'doctest-output/holy-grenade.gv.pdf'
_images/holy-grenade.svg

Hint

Apart from lacking editing methods, Source objects have the same basic API as the higher-level Graph and Digraph objects (e.g. save(), render(), view(), pipe() methods, engine and format attributes, Jupyter notebook _repr_mimebundle_(), etc. See API docs).