Skip to main content

Graphviz utility functions.

Project description

Graphviz utility functions.

Latest release 20220827:

  • Remove dependency on cs.lex - now we need only the stdlib.
  • New GVCAPTURE value for gvprint(file=) to return the binary image data as a bytes object; associated gvdata() convenience function.
  • New GVDATAURL value for gvprint(file=) to return the binary image data as a data URL; associated gvdataurl() convenience function.

See also the [https://www.graphviz.org/documentation/](graphviz documentation) and particularly the [https://graphviz.org/doc/info/lang.html](DOT language specification) and the [https://www.graphviz.org/doc/info/command.html](dot command line tool).

Class DOTNodeMixin

A mixin providing methods for things which can be drawn as nodes in a DOT graph description.

Function gvdata(dot_s, **kw)

Convenience wrapper for gvprint which returns the binary image data.

Function gvdataurl(dot_s, **kw)

Convenience wrapper for gvprint which returns the binary image data as a data: URL.

Function gvprint(dot_s, file=None, fmt=None, layout=None, **dot_kw)

Print the graph specified by dot_s, a graph in graphViz DOT syntax, to file (default sys.stdout) in format fmt using the engine specified by layout (default 'dot').

If fmt is unspecified it defaults to 'png' unless file is a terminal in which case it defaults to 'sixel'.

In addition to being a file or file descriptor, file may also take the following special values:

  • GVCAPTURE: causes gvprint to return the image data as bytes
  • GVDATAURL: causes gvprint to return the image data as a data: URL

This uses the graphviz utility dot to draw graphs. If printing in SIXEL format the img2sixel utility is required, see https://saitoha.github.io/libsixel/.

Example:

  data_url = gvprint('digraph FOO {A->B}', file=GVDATAURL, fmt='svg')

produces a data: URL rendering as:

Function quote(s)

Quote a string for use in DOT syntax. This implementation passes identifiers and sequences of decimal numerals through unchanged and double quotes other strings.

Release Log

Release 20220827:

  • Remove dependency on cs.lex - now we need only the stdlib.
  • New GVCAPTURE value for gvprint(file=) to return the binary image data as a bytes object; associated gvdata() convenience function.
  • New GVDATAURL value for gvprint(file=) to return the binary image data as a data URL; associated gvdataurl() convenience function.

Release 20220805.1: New DOTNodeMixin, a mixin for classes which can be rendered as a DOT node.

Release 20220805: Initial PyPI release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cs.gvutils-20220827.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

cs.gvutils-20220827-py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page