networkx.readwrite.gpickle.write_gpickle

write_gpickle(G, path, protocol=5)[source]

Write graph in Python pickle format.

Pickles are a serialized byte stream of a Python object [1]. This format will preserve Python objects used as nodes or edges.

Parameters
Ggraph

A NetworkX graph

pathfile or string

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

protocolinteger

Pickling protocol to use. Default value: pickle.HIGHEST_PROTOCOL.

References

1

https://docs.python.org/3/library/pickle.html

Deprecated since version 2.6.

Examples

>>> G = nx.path_graph(4)
>>> nx.write_gpickle(G, "test.gpickle")