Note

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

networkx.readwrite.gml.parse_gml

parse_gml(lines, label='label', destringizer=None)[source]

Parse GML graph from a string or iterable.

Parameters
linesstring or iterable of strings

Data in GML format.

labelstring, optional

If not None, the parsed nodes will be renamed according to node attributes indicated by label. Default value: ‘label’.

destringizercallable, optional

A destringizer that recovers values stored as strings in GML. If it cannot convert a string to a value, a ValueError is raised. Default value : None.

Returns
GNetworkX graph

The parsed graph.

Raises
NetworkXError

If the input cannot be parsed.

See also

write_gml, read_gml

Notes

This stores nested GML attributes as dictionaries in the NetworkX graph, node, and edge attribute structures.

GML files are stored using a 7-bit ASCII encoding with any extended ASCII characters (iso8859-1) appearing as HTML character entities. 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 url.

See the module docstring networkx.readwrite.gml for more details.