Note
This documentation was generated on Apr 14, 2026 for package release 1.3.1.
NetworkX-Temporal
NetworkX-Temporal extends the NetworkX library to dynamic graphs, i.e., temporal network data.
This package provides new TemporalGraph classes, which inherit
NetworkX’s graph classes
and implement additional functions to manipulate temporal data within. Among others, it provides
ways to slice() a graph into snapshots and
transform or convert it
to other libraries and formats.
Install
The package supports Python 3.7+ and is readily available from PyPI:
$ pip install networkx-temporal
Additional support for plotting graphs may be optionally installed with:
$ pip install 'networkx-temporal[draw]'
Quick start
The following is a quick example of the package in action, covering its basic functionality. More examples are accessible via the sidebar and also available as a Jupyter notebook (open on Colab).
Build and slice temporal graph
Create a directed TemporalGraph object and
slice() it into a number of snapshots:
>>> import networkx_temporal as tx
>>>
>>> TG = tx.temporal_graph() # TG = tx.TemporalMultiGraph()
>>>
>>> TG.add_edge("a", "b", time=0)
>>> TG.add_edge("c", "b", time=1)
>>> TG.add_edge("d", "c", time=2)
>>> TG.add_edge("d", "e", time=2)
>>> TG.add_edge("a", "c", time=2)
>>> TG.add_edge("f", "e", time=3)
>>> TG.add_edge("f", "a", time=3)
>>> TG.add_edge("f", "b", time=3)
>>>
>>> TG = TG.slice(attr="time")
>>>
>>> print(TG)
TemporalMultiGraph (t=4) with 6 nodes and 8 edges
The attr parameter optionally defines the attribute name to use for slicing the temporal graph,
while the number of snapshots to be created may likewise be specified with the bins parameter:
>>> TG.slice(attr="time", bins=2)
TemporalMultiGraph (t=2) with 6 nodes and 8 edges
Note that the total number of nodes may vary, while the total number of edges is preserved.
Plot snapshots
We may visualize the resulting temporal graph using the draw() function:
>>> tx.draw(TG, layout="kamada_kawai", figsize=(8, 2))
Save and load data
The write_graph() and read_graph()
functions accept compressed temporal graphs:
>>> TG = tx.read_graph("temporal-graph.graphml.zip")
>>> tx.write_graph(TG, "temporal-graph.graphml.zip")
Both functions support the same extension formats as in the installed NetworkX library version.
Convert and transform graphs
This package allows to transform a TemporalGraph between different
graph representations:
Static graphs: flattened or aggregated version of the temporal graph.
Snapshot-based temporal graphs: a list of node- or edge-level snapshots.
Event-based temporal graphs: a sequence of edge-level events (interactions).
Unrolled temporal graphs: a single graph with time-stamped nodes and edges.
>>> G = TG.to_static() # TG = tx.from_static(G)
>>> STG = TG.to_snapshots() # TG = tx.from_snapshots(SG)
>>> ETG = TG.to_events() # TG = tx.from_events(EG)
>>> UTG = TG.to_unrolled() # TG = tx.from_unrolled(UG)
In addition, both static and temporal graphs may be converted to the following graph formats:
>>> tx.convert(G, "igraph")
<igraph.Graph at 0x7f048ef52c50>
Links
For more information on using this package, please refer to the following sections:
Package reference for details on the classes and functions implemented by each module.
Examples covering some of its main functionalities and most common use cases.
See also
The package’s GitHub repository for the latest updates and issues. Contributions are welcome!
If you have any questions or feedback to share, please also feel free to contact us via e-mail. 📬