Python graphlib Module
Example
Topologically sort a simple dependency chain:
import graphlib
ts = graphlib.TopologicalSorter()
ts.add("Emil")
ts.add("Tobias", "Emil")
ts.add("Linus", "Tobias")
print(list(ts.static_order()))
Try it Yourself »
Definition and Usage
The graphlib module provides utilities for working with graphs, including a topological sorter.
Use it to resolve dependency orders where items depend on other items being processed first.
Members
Member | Description |
---|---|
TopologicalSorter | Class to perform topological sorts of directed acyclic graphs. |
CycleError | Exception raised when a cycle is detected in the graph. |