Graphviz utility functions.
Latest release 20260531:
- New DOT_KEYWORDS, update quote() to quote keywords.
- New Node and Graph classes for constructing a graphviz style node graph.
- gvprint: print a final newline after the sixel output.
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).
Short summary:
DOTNodeMixin: A mixin providing methods for things which can be drawn as nodes in a DOT graph description.Graph: A representation of a graphviz graph suitable for transcribing as DOT.gvdata: Convenience wrapper forgvprintwhich returns the binary image data.gvdataurl: Convenience wrapper forgvprintwhich returns the binary image data as adata:URL.gvprint: Print the graph specified bydot_s, a graph in graphViz DOT syntax, tofile(defaultsys.stdout) in formatfmtusing the engine specified bylayout(default'dot').gvsvg: Convenience wrapper forgvprintwhich returns an SVG string.Node: Node(id: str, rankdir: str = 'LR', shape: str = 'rect', attrs: dict = ).quote: Quote a string for use in DOT syntax. This implementation passes non-keyword identifiers and sequences of decimal numerals through unchanged and double quotes other strings.
Module contents:
class DOTNodeMixin: A mixin providing methods for things which can be drawn as nodes in a DOT graph description.
DOTNodeMixin.__getattr__(self, attr: str):
Recognise various dot_node_* attributes.
dot_node_*color is an attribute derives from self.DOT_NODE_COLOR_*PALETTE.
DOTNodeMixin.dot_node(self, label=None, **node_attrs) -> str:
A DOT syntax node definition for self.
DOTNodeMixin.dot_node_attrs(self) -> Mapping[str, str]:
The default DOT node attributes.
DOTNodeMixin.dot_node_attrs_str(attrs):
An attributes mapping transcribed for DOT,
ready for insertion between [] in a node definition.
DOTNodeMixin.dot_node_id:
An id for this DOT node, also the default index into the palettes.
DOTNodeMixin.dot_node_label(self) -> str:
The default node label.
This implementation returns str(self)
and a common implementation might return self.name or similar.
DOTNodeMixin.dot_node_palette_key:
The default palette index is `self.dot_node_id``.
Graph.add(self, *items):
Add a Node id or a Nodes or Graphs to self.nodes.
Graph.as_dot(self, *, fold=False, indent='', subindent=' ', graphtype=None) -> str:
Return a DOT representation of this Graph.
Parameters:
fold: defaultFalse; if true then produce indented multiline textindent: the prevailing indent iffold, default""subindent: incremental indent of nested items iffold, default" "
Graph.join(self, *items, **attrs):
Join the specified Nodes, Node ids or Graphs in an edge.
Graph.mapping_as_dot(kv: Mapping[str, Any]):
Transcribe a mapping as DOT i.e. an a_list.
-
gvdata(dot_s, **kw): Convenience wrapper forgvprintwhich returns the binary image data. -
gvdataurl(dot_s, **kw): Convenience wrapper forgvprintwhich returns the binary image data as adata:URL. -
gvprint(dot_s, file=None, fmt=None, layout=None, dataurl_encoding=None, **dot_kw): Print the graph specified bydot_s, a graph in graphViz DOT syntax, tofile(defaultsys.stdout) in formatfmtusing the engine specified bylayout(default'dot').If
fmtis unspecified it defaults to'png'unlessfileis a terminal in which case it defaults to'sixel'.In addition to being a file or file descriptor,
filemay also take the following special values:GVCAPTURE: causesgvprintto return the image data asbytesGVDATAURL: causesgvprintto return the image data as adata:URL
For
GVDATAURL, the parameterdataurl_encodingmay be used to override the default encoding, which is'utf8'forfmtvalues'dot'and'svg', otherwise'base64'.This uses the graphviz utility
dotto draw graphs. If printing in SIXEL format theimg2sixelutility is required, see https://saitoha.github.io/libsixel/.Example:
data_url = gvprint('digraph FOO {A->B}', file=GVDATAURL, fmt='svg') -
gvsvg(dot_s, **gvdata_kw): Convenience wrapper forgvprintwhich returns an SVG string. -
class Node(DOTNodeMixin): Node(id: str, rankdir: str = 'LR', shape: str = 'rect', attrs: dict = ) -
quote(s): Quote a string for use in DOT syntax. This implementation passes non-keyword identifiers and sequences of decimal numerals through unchanged and double quotes other strings.
Release Log
Release 20260531:
- New DOT_KEYWORDS, update quote() to quote keywords.
- New Node and Graph classes for constructing a graphviz style node graph.
- gvprint: print a final newline after the sixel output.
Release 20230816: DOTNodeMixin: new dot_node_attrs_str for transcribing a node attributes list.
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.
Metadata
Release files for cs-gvutils 20260531
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cs_gvutils-20260531.tar.gz | 7.5 kB | Without provenance | Details for cs_gvutils-20260531.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cs_gvutils-20260531-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for cs_gvutils-20260531-py2.py3-none-any.whl |
Total release size: 16.4 kB
Release files / cs_gvutils-20260531.tar.gz
| Download URL | cs_gvutils-20260531.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b617925cb2cd573863ab2577c6164d850f3550c8aa488338d7fb353fc75d673
|
|
BLAKE2b-256 checksum How to use checksums |
0b8bf14c64f140a34b6dcefb8f69e242251d1bcc0f29d5cda8a28852399bc510
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / cs_gvutils-20260531-py2.py3-none-any.whl
| Download URL | cs_gvutils-20260531-py2.py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
f3eb95635d7b1a1cc9c5df07843fa3e67fbc73955916d8f3f631d4ebdd10a8e6
|
|
BLAKE2b-256 checksum How to use checksums |
785779d8ff2210f8b65a330b42c3032c61fce48b0e6e12d6b47e28a3c495acc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Security for cs-gvutils 20260531
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.