Note

This documentation was generated on Apr 14, 2026 for package release 1.3.1.

NetworkX-Temporal

PyPI version Documentation Status Downloads Downloads License

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.

Note

The slice() method by default creates a snapshot for unique time value in the temporal graph. It internally stores views of the original graph, so no data is copied unless otherwise specified.

Plot snapshots

We may visualize the resulting temporal graph using the draw() function:

>>> tx.draw(TG, layout="kamada_kawai", figsize=(8, 2))
Temporal graph plot

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:

>>> 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>