networkx_temporal.readwrite
Input/Output functions for temporal graphs.
|
Returns a |
|
Writes static or temporal graph to file or binary object. |
Functions
- read_graph(file: str | BufferedReader | BytesIO, format: str | Callable | None = None, **kwargs) TemporalGraph[source]
Returns a
TemporalGraphfrom file or binary object.If
fileis a compressed ZipFile, it must contain one or more graphs named{name}_{t}.{ext}, wheretis their snapshot index andextis the extension format. See:write_graph().Example
Reading a temporal graph from a compressed file:
>>> import networkx_temporal as tx >>> >>> TG = tx.read_graph("snapshots.graphml.zip")
See also
The latest read and write documentation from NetworkX for a list of supported formats.
- Parameters:
file (object) – Binary file-like object or string containing path to ZIP file.
format (str | Callable | None) – Extension format or callable function to read compressed graphs with. If unset, it is inferred from their file extension.
kwargs – Additional arguments to pass to NetworkX reader function.
- Return type:
- write_graph(TG: TemporalGraph | Graph, file: str | BufferedWriter | BytesIO | None = None, format: str | Callable | None = None, makedirs: bool = False, compression: Literal['ZIP_STORED', 'ZIP_DEFLATED', 'ZIP_BZIP2', 'ZIP_LZMA'] | None = None, compresslevel: int | None = None, allowZip64: bool = False, **kwargs) bytes | None[source]
Writes static or temporal graph to file or binary object.
A compressed ZipFile is created in which each graph file refers to a snapshot. Graph files are saved as
{name}_{t}.{ext}, wheretis their snapshot index andextis the extension format.Note that a
'.zip'extension is automatically added to the output file name if not present.Example
Writing a temporal graph to a compressed ZIP file:
>>> import networkx_temporal as tx >>> >>> TG = tx.TemporalGraph() >>> tx.write_graph(TG, "snapshots.graphml.zip")
See also
The latest read and write documentation from NetworkX for a list of supported formats.
- Parameters:
TG (object) – A
TemporalGraphobject.file (object) – Binary file-like object or string containing path to ZIP file. Optional. If
None(default), returns content as bytes.format (str | Callable | None) – Extension format or callable function to write graphs with. If unset and
fileis a string, it is inferred from it. Otherwise, defaults to'graphml'.makedirs (bool) – Whether to create directories to file if they do not exist. Default is
False.compression (str) –
Compression method to use. Optional. The following values are accepted:
'ZIP_STORED': no compression. This is the default.'ZIP_DEFLATED': requires zlib.'ZIP_BZIP2': requires bz2.'ZIP_LZMA': requires lzma.
compresslevel (int | None) –
Level of compression to use. Optional. Default is
None. The following values are accepted, depending on the compression method:When using
'ZIP_STORED'or'ZIP_LZMA', this keyword has no effect.When using
'ZIP_DEFLATED', integers0through9are accepted.When using
'ZIP_BZIP2', integers1through9are accepted.
allowZip64 (bool) – If
True, files with a ZIP64 extension will be created if needed. Otherwise, an exception will be raised when this would be necessary. Default isFalse.kwargs – Additional arguments to pass to NetworkX writer function.
- Return type:
bytes | None