Piped outputΒΆ

To directly access the raw results from the Graphviz dot layout command as binary bytes or as decoded str (for plain-text formats like SVG) instead of writing to a file, use the pipe() method of your Graph or Digraph object:

>>> import graphviz

>>> h = graphviz.Graph('hello', format='svg')

>>> h.edge('Hello', 'World')
>>> doctest_mark_exe()

>>> h.pipe(format='pdf')[:4]
b'%PDF'

>>> print(h.pipe(encoding='utf-8'))
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg
...
</svg>

Tip

Because pipe() returns the raw stdout from the layout subprocess by default (bytes), you usually want to decode the return value when piping into formats like 'svg' or 'plain',

Caution

The output for pipe() is buffered in memory, so avoid this method if the data size is large.