#

Note

This documents the development version of NetworkX. Documentation for the current release can be found here.

#

GML

Read graphs in GML format.

“GML, the Graph Modelling Language, is our proposal for a portable file format for graphs. GML’s key features are portability, simple syntax, extensibility and flexibility. A GML file consists of a hierarchical key-value lists. Graphs can be annotated with arbitrary data structures. The idea for a common file format was born at the GD’95; this proposal is the outcome of many discussions. GML is the standard file format in the Graphlet graph editor system. It has been overtaken and adapted by several other systems for drawing graphs.”

GML files are stored using a 7-bit ASCII encoding with any extended ASCII characters (iso8859-1) appearing as HTML character entities. You will need to give some thought into how the exported data should interact with different languages and even different Python versions. Re-importing from gml is also a concern.

Without specifying a stringizer/destringizer, the code is capable of handling int/float/str/dict/list data as required by the GML specification. For other data types, you need to explicitly supply a stringizer/destringizer.

For additional documentation on the GML file format, please see the GML website.

Several example graphs in GML format may be found on Mark Newman’s Network data page.

read_gml(path[, label, destringizer])

Read graph in GML format from path.

write_gml(G, path[, stringizer])

Write a graph G in GML format to the file or file handle path.

parse_gml(lines[, label, destringizer])

Parse GML graph from a string or iterable.

generate_gml(G[, stringizer])

Generate a single entry of the graph G in GML format.

literal_destringizer(rep)

Convert a Python literal to the value it represents.

literal_stringizer(value)

Convert a value to a Python literal in GML representation.