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


write_graphml(G, path, encoding='utf-8', prettyprint=True, infer_numeric_types=False, named_key_ids=False)

Write G in GraphML XML format to path

This function uses the LXML framework and should be faster than the version using the xml library.


A networkx graph

pathfile or string

File or filename to write. Filenames ending in .gz or .bz2 will be compressed.

encodingstring (optional)

Encoding for text data.

prettyprintbool (optional)

If True use line breaks and indenting in output XML.


Determine if numeric types should be generalized. For example, if edges have both int and float ‘weight’ attributes, we infer in GraphML that both are floats.

named_key_idsbool (optional)

If True use as value for key elements’ id attribute.


This implementation does not support mixed graphs (directed and unidirected edges together) hyperedges, nested graphs, or ports.


>>> G = nx.path_graph(4)
>>> nx.write_graphml_lxml(G, "fourpath.graphml")