Skip to main content

Graphviz utility functions.

Latest release 20221118:

  • quote: provide escape sequence for newline.
  • DOTNodeMixin: provide .dot_node_id property, default str(id(self)).
  • DOTNodeMixin.dot_node: omit [attrs] if they are empty.
  • DOTNodeMixin: new .dot_node_palette_key property, new getattr for .dot_node_*color attributes, new empty default DOT_NODE_COLOR_PALETTE and DOT_NODE_FILLCOLOR_PALETTE class attributes.
  • DOTNodeMixin.dot_node: include the node label in the attributes.
  • Add colours to DOTNodeMixin.dot_node_attrs and fix "fontcolor".

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, dataurl_encoding=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

For GVDATAURL, the parameter dataurl_encoding may be used to override the default encoding, which is 'utf8' for fmt values 'dot' and 'svg', otherwise 'base64'.

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')

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 20221118:

  • quote: provide escape sequence for newline.
  • DOTNodeMixin: provide .dot_node_id property, default str(id(self)).
  • DOTNodeMixin.dot_node: omit [attrs] if they are empty.
  • DOTNodeMixin: new .dot_node_palette_key property, new getattr for .dot_node_*color attributes, new empty default DOT_NODE_COLOR_PALETTE and DOT_NODE_FILLCOLOR_PALETTE class attributes.
  • DOTNodeMixin.dot_node: include the node label in the attributes.
  • Add colours to DOTNodeMixin.dot_node_attrs and fix "fontcolor".

Release 20220827.1: gvprint: new optional parameter dataurl_encoding to specify the data URL encoding.

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.

Release files for cs-gvutils 20221118

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs-gvutils 20221118
File Size Uploaded
cs.gvutils-20221118.tar.gz 6.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cs-gvutils 20221118
File Interpreter ABI Platform
cs.gvutils-20221118-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / cs.gvutils-20221118.tar.gz

Download URL cs.gvutils-20221118.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a2f7e97c038c6eb12ea0f8bba2c50fdae8f47d87fc39c8c9363ac6c60a4c0e8d
BLAKE2b-256 checksum
How to use checksums
bbf234c931d2d0d2f0b9db6882a8c1eefbe7e7ff9baac350c9f96caa2666d3c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / cs.gvutils-20221118-py3-none-any.whl

Download URL cs.gvutils-20221118-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0449443d89deae90bb7a6046bacaf12b6f32a3e43a1cbc1f8aa5613a93a2d6a
BLAKE2b-256 checksum
How to use checksums
5660e7949dc82caf839d827d89a3df682ac1087db4c7350e8b6d0ea23de15119
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

20221118 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page