skm_tools.persistence ===================== .. py:module:: skm_tools.persistence .. autoapi-nested-parse:: Save networks to disk and load them again. This module only reads and writes files; it keeps no state between calls. Attributes ---------- .. autoapisummary:: skm_tools.persistence.FORMATS Functions --------- .. autoapisummary:: skm_tools.persistence.save_graph skm_tools.persistence.load_graph Module Contents --------------- .. py:data:: FORMATS :value: ('pickle', 'json') .. py:function:: save_graph(g, path, format='pickle') Save a network to a file. :param g: Network to save. :type g: networkx.Graph :param path: File to write (overwritten if it exists). :type path: str or pathlib.Path :param format: - ``"pickle"`` (default): fastest, keeps everything (graph type, attribute types), but Python-only, and unsafe to load from untrusted sources. - ``"json"``: portable and safe, keeps list attributes; tuples and sets become lists (see :func:`skm_tools.serialize.graph_to_dict`, also for its limits). On the full CKN (26k nodes, 899k edges), pickle took 2 s to save, 2 s to load and 101 MB; JSON 15 s, 6 s and 193 MB. For other network tools (e.g. Cytoscape), see :mod:`skm_tools.cytoscape_utils`, or networkx's own writers. :type format: {"pickle", "json"} .. py:function:: load_graph(path, format='pickle') Load a network saved with :func:`save_graph`. :param path: File to read. :type path: str or pathlib.Path :param format: Format the file was saved in. Only load pickle files you trust: unpickling can run arbitrary code. :type format: {"pickle", "json"} :returns: The network, of the type it was saved as. :rtype: networkx.Graph