Skip to main content

Graphviz utility functions.

Project description

Graphviz utility functions.

Latest release 20221207: New gvsvg() convenience function to return SVG.

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 gvsvg(dot_s, **kw)

Convenience wrapper for gvprint which returns an SVG string.

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 20221207: New gvsvg() convenience function to return SVG.

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.

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-20221207.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

cs.gvutils-20221207-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file cs.gvutils-20221207.tar.gz.

File metadata

  • Download URL: cs.gvutils-20221207.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for cs.gvutils-20221207.tar.gz
Algorithm Hash digest
SHA256 9260bee9ae5b8020e26c602d264de19957403f7ed8f71e0863ace48b1630f3bd
MD5 048caf0a2a46864f9edf02f9776040be
BLAKE2b-256 a0f52598c2f2c65ae16a2ba6fe68a9e1a213964c4493be0134ee454e4f690265

See more details on using hashes here.

File details

Details for the file cs.gvutils-20221207-py3-none-any.whl.

File metadata

File hashes

Hashes for cs.gvutils-20221207-py3-none-any.whl
Algorithm Hash digest
SHA256 4f3348a9e47875e346fa36d88107419159e39faf5af7317e8b117acb316203c9
MD5 a73f2edb1cda316d40b1bfa742fd231f
BLAKE2b-256 6d5cd6a8c4376c45c3188908cb34f818506fd41cadfed83fed5b150dc700ee2e

See more details on using hashes here.

Supported by

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