generate_gexf(G, encoding='utf-8', prettyprint=True, version='1.2draft')[source]#

Generate lines of GEXF format representation of G.

“GEXF (Graph Exchange XML Format) is a language for describing complex networks structures, their associated data and dynamics” [1].

A NetworkX graph
encodingstring (optional, default: ‘utf-8’)
Encoding for text data.
prettyprintbool (optional, default: True)
If True use line breaks and indenting in output XML.
versionstring (default: 1.2draft)
Version of GEFX File Format (see
Supported values: “1.1draft”, “1.2draft”


This implementation does not support mixed graphs (directed and undirected edges together).

The node id attribute is set to be the string of the node label. If you want to specify an id use set it as node data, e.g. node[‘a’][‘id’]=1 to set the id of node ‘a’ to 1.



GEXF File Format,


>>> G = nx.path_graph(4)
>>> linefeed = chr(10)  # linefeed=
>>> s = linefeed.join(nx.generate_gexf(G))
>>> for line in nx.generate_gexf(G):  
...     print(line)