0% found this document useful (0 votes)
20 views4 pages

Python Graph Manipulation with Graphviz

gv_python is a Python extension that provides access to the graph manipulation capabilities of Graphviz. It allows users to create graphs and graph objects like nodes and edges, set attributes, perform layouts using Graphviz algorithms, and render graphs to files, channels or strings. The module includes functions for common graph operations like adding/removing objects, iterating over graph components, and transforming graphs.

Uploaded by

hdhdhdh hfjfjf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Python Graph Manipulation with Graphviz

gv_python is a Python extension that provides access to the graph manipulation capabilities of Graphviz. It allows users to create graphs and graph objects like nodes and edges, set attributes, perform layouts using Graphviz algorithms, and render graphs to files, channels or strings. The module includes functions for common graph operations like adding/removing objects, iterating over graph components, and transforming graphs.

Uploaded by

hdhdhdh hfjfjf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

gv(3python) gv(3python)

NAME
gv_python - graph manipulation in python

SYNOPSIS
#!/usr/bin/python
import sys
import gv

USAGE
INTRODUCTION
gv_python is a dynamically loaded extension for python that provides access to the graph facilities of
graphviz.

COMMANDS
New graphs
New empty graph
graph_handle [Link] (name);
graph_handle [Link] (name);
graph_handle [Link] (name);
graph_handle [Link] (name);
New graph from a dot-syntax string or file
graph_handle [Link] (string);
graph_handle [Link] (string filename);
graph_handle [Link] (channel);
Add new subgraph to existing graph
graph_handle [Link] (graph_handle, name);
New nodes
Add new node to existing graph
node_handle [Link] (graph_handle, name);
New edges
Add new edge between existing nodes
edge_handle [Link] (tail_node_handle, head_node_handle);
Add a new edge between an existing tail node, and a named head node which will be induced in the graph
if it doesn’t already exist
edge_handle [Link] (tail_node_handle, head_name);
Add a new edge between an existing head node, and a named tail node which will be induced in the graph
if it doesn’t already exist
edge_handle [Link] (tail_name, head_node_handle);
Add a new edge between named tail and head nodes which will be induced in the graph if they don’t
already exist
edge_handle [Link] (graph_handle, tail_name, head_name);
Setting attribute values
Set value of named attribute of graph/node/edge - creating attribute if necessary
string [Link] (graph_handle, attr_name, attr_value);
string [Link] (node_handle, attr_name, attr_value);
string [Link] (edge_handle, attr_name, attr_value);

17 December 2016 1
gv(3python) gv(3python)

Set value of existing attribute of graph/node/edge (using attribute handle)


string [Link] (graph_handle, attr_handle, attr_value);
string [Link] (node_handle, attr_handle, attr_value);
string [Link] (edge_handle, attr_handle, attr_value);
Getting attribute values
Get value of named attribute of graph/node/edge
string [Link] (graph_handle, attr_name);
string [Link] (node_handle, attr_name);
string [Link] (edge_handle, attr_name);
Get value of attribute of graph/node/edge (using attribute handle)
string [Link] (graph_handle, attr_handle);
string [Link] (node_handle, attr_handle);
string [Link] (edge_handle, attr_handle);
Obtain names from handles
string [Link] (graph_handle);
string [Link] (node_handle);
string [Link] (attr_handle);
Find handles from names
graph_handle [Link] (graph_handle, name);
node_handle [Link] (graph_handle, name);
edge_handle [Link] (tail_node_handle, head_node_handle);
attribute_handle [Link] (graph_handle, name);
attribute_handle [Link] (node_handle, name);
attribute_handle [Link] (edge_handle, name);
Misc graph navigators returning handles
node_handle [Link] (edge_handle);
node_handle [Link] (edge_handle);
graph_handle [Link] (graph_handle);
graph_handle [Link] (edge_handle);
graph_handle [Link] (node_handle);
graph_handle [Link] (graph_handle);
Obtain handles of proto node/edge for setting default attribute values
node_handle [Link] (graph_handle);
edge_handle [Link] (graph_handle);
Iterators
Iteration termination tests
bool [Link] (graph_handle);
bool [Link] (node_handle);
bool [Link] (edge_handle);
bool [Link] (attr_handle);
Iterate over subgraphs of a graph
graph_handle [Link] (graph_handle);
graph_handle [Link] (graph_handle, subgraph_handle);
Iterate over supergraphs of a graph (obscure and rarely useful)
graph_handle [Link] (graph_handle);
graph_handle [Link] (graph_handle, subgraph_handle);
Iterate over edges of a graph
edge_handle [Link] (graph_handle);
edge_handle [Link] (graph_handle, edge_handle);

17 December 2016 2
gv(3python) gv(3python)

Iterate over outedges of a graph


edge_handle [Link] (graph_handle);
edge_handle [Link] (graph_handle, edge_handle);
Iterate over edges of a node
edge_handle [Link] (node_handle);
edge_handle [Link] (node_handle, edge_handle);
Iterate over out-edges of a node
edge_handle [Link] (node_handle);
edge_handle [Link] (node_handle, edge_handle);
Iterate over head nodes reachable from out-edges of a node
node_handle [Link] (node_handle);
node_handle [Link] (node_handle, head_node_handle);
Iterate over in-edges of a graph
edge_handle [Link] (graph_handle);
edge_handle [Link] (node_handle, edge_handle);
Iterate over in-edges of a node
edge_handle [Link] (node_handle);
edge_handle [Link] (graph_handle, edge_handle);
Iterate over tail nodes reachable from in-edges of a node
node_handle [Link] (node_handle);
node_handle [Link] (node_handle, tail_node_handle);
Iterate over nodes of a graph
node_handle [Link] (graph_handle);
node_handle [Link] (graph_handle, node_handle);
Iterate over nodes of an edge
node_handle [Link] (edge_handle);
node_handle [Link] (edge_handle, node_handle);
Iterate over attributes of a graph
attribute_handle [Link] (graph_handle);
attribute_handle [Link] (graph_handle, attr_handle);
Iterate over attributes of an edge
attribute_handle [Link] (edge_handle);
attribute_handle [Link] (edge_handle, attr_handle);
Iterate over attributes of a node
attribute_handle [Link] (node_handle);
attribute_handle [Link] (node_handle, attr_handle);
Remove graph objects
bool [Link] (graph_handle);
bool [Link] (node_handle);
bool [Link] (edge_handle);
Layout
Annotate a graph with layout attributes and values using a specific layout engine
bool [Link] (graph_handle, string engine);
Render
Render a layout into attributes of the graph
bool [Link] (graph_handle);

17 December 2016 3
gv(3python) gv(3python)

Render a layout to stdout


bool [Link] (graph_handle, string format);
Render to an open file
bool [Link] (graph_handle, string format, channel fout);
Render a layout to an unopened file by name
bool [Link] (graph_handle, string format, string filename);
Render to a string result
string [Link] (graph_handle ing, string format);
[Link] (graph_handle, string format, string outdata);
Render to an open channel
bool [Link] (graph_handle, string format, string channelname);
Render a layout to a malloc’ed string, to be free’d by the caller
(deprecated - too easy to leak memory)
(still needed for "eval [gv::renderdata $G tk]" )
string [Link] (graph_handle, string format);
Writing graph back to file
bool [Link] (graph_handle, string filename);
bool [Link] (graph_handle, channel);
Graph transformation tools
bool [Link] (graph_handle);

KEYWORDS
graph, dot, neato, fdp, circo, twopi, python.

17 December 2016 4

You might also like