gv(3python) gv(3python)

# [NAME](#NAME)

gv\_python - graph manipulation in python

# [SYNOPSIS](#SYNOPSIS)

#!/usr/bin/python  
import gv

# [USAGE](#USAGE)

# [INTRODUCTION](#INTRODUCTION)

**gv\_python** is a dynamically loaded extension for **python** that provides access to the graph facilities of **graphviz.**

# [COMMANDS](#COMMANDS)

[**New graphs**](#New)

[New empty graph](#New~2)

*graph\_handle* **gv.graph** *(name);*  
*graph\_handle* **gv.digraph** *(name);*  
*graph\_handle* **gv.strictgraph** *(name);*  
*graph\_handle* **gv.strictdigraph** *(name);*

[New graph from a dot-syntax string or file](#New~3)

*graph\_handle* **gv.readstring** *(string);*  
*graph\_handle* **gv.read** *(string filename);*  
*graph\_handle* **gv.read** *(channel);*

[Add new subgraph to existing graph](#Add)

*graph\_handle* **gv.graph** *(graph\_handle, name);*

[**New nodes**](#New~4)

[Add new node to existing graph](#Add~2)

*node\_handle* **gv.node** *(graph\_handle, name);*

[**New edges**](#New~5)

[Add new edge between existing nodes](#Add~3)

*edge\_handle* **gv.edge** *(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](#Add~4)

*edge\_handle* **gv.edge** *(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](#Add~5)

*edge\_handle* **gv.edge** *(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](#Add~6)

*edge\_handle* **gv.edge** *(graph\_handle, tail\_name, head\_name);*

[**Setting attribute values**](#Setting)

[Set value of named attribute of graph/node/edge - creating attribute if necessary](#Set)

*string* **gv.setv** *(graph\_handle, attr\_name, attr\_value);*  
*string* **gv.setv** *(node\_handle, attr\_name, attr\_value);*  
*string* **gv.setv** *(edge\_handle, attr\_name, attr\_value);*

[Set value of existing attribute of graph/node/edge (using attribute handle)](#Set~2)

*string* **gv.setv** *(graph\_handle, attr\_handle, attr\_value);*  
*string* **gv.setv** *(node\_handle, attr\_handle, attr\_value);*  
*string* **gv.setv** *(edge\_handle, attr\_handle, attr\_value);*

[**Getting attribute values**](#Getting)

[Get value of named attribute of graph/node/edge](#Get)

*string* **gv.getv** *(graph\_handle, attr\_name);*  
*string* **gv.getv** *(node\_handle, attr\_name);*  
*string* **gv.getv** *(edge\_handle, attr\_name);*

[Get value of attribute of graph/node/edge (using attribute handle)](#Get~2)

*string* **gv.getv** *(graph\_handle, attr\_handle);*  
*string* **gv.getv** *(node\_handle, attr\_handle);*  
*string* **gv.getv** *(edge\_handle, attr\_handle);*

[**Obtain names from handles**](#Obtain)

*string* **gv.nameof** *(graph\_handle);*  
*string* **gv.nameof** *(node\_handle);*  
*string* **gv.nameof** *(attr\_handle);*

[**Find handles from names**](#Find)

*graph\_handle* **gv.findsubg** *(graph\_handle, name);*  
*node\_handle* **gv.findnode** *(graph\_handle, name);*  
*edge\_handle* **gv.findedge** *(tail\_node\_handle, head\_node\_handle);*  
*attribute\_handle* **gv.findattr** *(graph\_handle, name);*  
*attribute\_handle* **gv.findattr** *(node\_handle, name);*  
*attribute\_handle* **gv.findattr** *(edge\_handle, name);*

[**Misc graph navigators returning handles**](#Misc)

*node\_handle* **gv.headof** *(edge\_handle);*  
*node\_handle* **gv.tailof** *(edge\_handle);*  
*graph\_handle* **gv.graphof** *(graph\_handle);*  
*graph\_handle* **gv.graphof** *(edge\_handle);*  
*graph\_handle* **gv.graphof** *(node\_handle);*  
*graph\_handle* **gv.rootof** *(graph\_handle);*

[**Obtain handles of proto node/edge for setting default attribute values**](#Obtain~2)

*node\_handle* **gv.protonode** *(graph\_handle);*  
*edge\_handle* **gv.protoedge** *(graph\_handle);*

[**Iterators**](#Iterators)

[Iteration termination tests](#Iteration)

*bool* **gv.ok** *(graph\_handle);*  
*bool* **gv.ok** *(node\_handle);*  
*bool* **gv.ok** *(edge\_handle);*  
*bool* **gv.ok** *(attr\_handle);*

[Iterate over subgraphs of a graph](#Iterate)

*graph\_handle* **gv.firstsubg** *(graph\_handle);*  
*graph\_handle* **gv.nextsubg** *(graph\_handle, subgraph\_handle);*

[Iterate over supergraphs of a graph (obscure and rarely useful)](#Iterate~2)

*graph\_handle* **gv.firstsupg** *(graph\_handle);*  
*graph\_handle* **gv.nextsupg** *(graph\_handle, subgraph\_handle);*

[Iterate over edges of a graph](#Iterate~3)

*edge\_handle* **gv.firstedge** *(graph\_handle);*  
*edge\_handle* **gv.nextedge** *(graph\_handle, edge\_handle);*

[Iterate over outedges of a graph](#Iterate~4)

*edge\_handle* **gv.firstout** *(graph\_handle);*  
*edge\_handle* **gv.nextout** *(graph\_handle, edge\_handle);*

[Iterate over edges of a node](#Iterate~5)

*edge\_handle* **gv.firstedge** *(node\_handle);*  
*edge\_handle* **gv.nextedge** *(node\_handle, edge\_handle);*

[Iterate over out-edges of a node](#Iterate~6)

*edge\_handle* **gv.firstout** *(node\_handle);*  
*edge\_handle* **gv.nextout** *(node\_handle, edge\_handle);*

[Iterate over head nodes reachable from out-edges of a node](#Iterate~7)

*node\_handle* **gv.firsthead** *(node\_handle);*  
*node\_handle* **gv.nexthead** *(node\_handle, head\_node\_handle);*

[Iterate over in-edges of a graph](#Iterate~8)

*edge\_handle* **gv.firstin** *(graph\_handle);*  
*edge\_handle* **gv.nextin** *(node\_handle, edge\_handle);*

[Iterate over in-edges of a node](#Iterate~9)

*edge\_handle* **gv.firstin** *(node\_handle);*  
*edge\_handle* **gv.nextin** *(graph\_handle, edge\_handle);*

[Iterate over tail nodes reachable from in-edges of a node](#Iterate~10)

*node\_handle* **gv.firsttail** *(node\_handle);*  
*node\_handle* **gv.nexttail** *(node\_handle, tail\_node\_handle);*

[Iterate over nodes of a graph](#Iterate~11)

*node\_handle* **gv.firstnode** *(graph\_handle);*  
*node\_handle* **gv.nextnode** *(graph\_handle, node\_handle);*

[Iterate over nodes of an edge](#Iterate~12)

*node\_handle* **gv.firstnode** *(edge\_handle);*  
*node\_handle* **gv.nextnode** *(edge\_handle, node\_handle);*

[Iterate over attributes of a graph](#Iterate~13)

*attribute\_handle* **gv.firstattr** *(graph\_handle);*  
*attribute\_handle* **gv.nextattr** *(graph\_handle, attr\_handle);*

[Iterate over attributes of an edge](#Iterate~14)

*attribute\_handle* **gv.firstattr** *(edge\_handle);*  
*attribute\_handle* **gv.nextattr** *(edge\_handle, attr\_handle);*

[Iterate over attributes of a node](#Iterate~15)

*attribute\_handle* **gv.firstattr** *(node\_handle);*  
*attribute\_handle* **gv.nextattr** *(node\_handle, attr\_handle);*

[**Remove graph objects**](#Remove)

*bool* **gv.rm** *(graph\_handle);*  
*bool* **gv.rm** *(node\_handle);*  
*bool* **gv.rm** *(edge\_handle);*

[**Layout**](#Layout)

[Annotate a graph with layout attributes and values using a specific layout engine](#Annotate)

*bool* **gv.layout** *(graph\_handle, string engine);*

[**Render**](#Render)

[Render a layout into attributes of the graph](#Render~2)

*bool* **gv.render** *(graph\_handle);*

[Render a layout to stdout](#Render~3)

*bool* **gv.render** *(graph\_handle, string format);*

[Render to an open file](#Render~4)

*bool* **gv.render** *(graph\_handle, string format, channel fout);*

[Render a layout to an unopened file by name](#Render~5)

*bool* **gv.render** *(graph\_handle, string format, string filename);*

[Render to a string result](#Render~6)

*string* **gv.renderresult** *(graph\_handle ing, string format);*  
**gv.renderresult** *(graph\_handle, string format, string outdata);*

[Render to an open channel](#Render~7)

*bool* **gv.renderchannel** *(graph\_handle, string format, string channelname);*

[Render a layout to a malloc'ed string, to be free'd by the caller](#Render~8)

(deprecated - too easy to leak memory)

(still needed for "eval \[gv::renderdata $G tk]" )

*string* **gv.renderdata** *(graph\_handle, string format);*

[Writing graph back to file](#Writing)

*bool* **gv.write** *(graph\_handle, string filename);*  
*bool* **gv.write** *(graph\_handle, channel);*

[Graph transformation tools](#Graph)

*bool* **gv.tred** *(graph\_handle);*

# [KEYWORDS](#KEYWORDS)

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

1788172566

---

Document: gv(3python) from graphviz 15.1.1-r1 (Chainguard OS)
Source: https://gitlab.com/graphviz/graphviz
