pydoc > graphlib

📛 NAME

graphlib

🚀 Quick Reference

Use CaseCommandDescription
🔧 Create a sorterts = TopologicalSorter()Initialize with optional graph dict
➕ Add node with dependenciests.add(node, dep1, dep2)Both node and predecessors must be hashable
✅ Prepare graphts.prepare()Finalize; raises CycleError if cycles exist
📋 Get ready nodests.get_ready()Returns tuple of nodes with no unresolved predecessors
✔️ Mark donets.done(node)Unblocks successors of processed nodes
🔄 Static order (no prepare/done)list(ts.static_order())Iterable of nodes in topological order; raises CycleError
🔍 Check progressts.is_active()Returns True if more nodes can be processed
⚠️ Catch cycle errortry: ... except CycleError as e: ...Access cycle via e.args[1]

📚 MODULE REFERENCE

https://docs.python.org/3.10/library/graphlib.html

The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.

🏛️ CLASSES

builtins.ValueError(builtins.Exception)CycleError
builtins.objectTopologicalSorter

⚠️ class CycleError(builtins.ValueError)

Subclass of ValueError raised by TopologicalSorter.prepare if cycles exist in the working graph.

If multiple cycles exist, only one undefined choice among them will be reported and included in the exception. The detected cycle can be accessed via the second element in the *args attribute of the exception instance and consists in a list of nodes, such that each node is, in the graph, an immediate predecessor of the next node in the list. In the reported list, the first and the last node will be the same, to make it clear that it is cyclic.

Method resolution order: CycleError → builtins.ValueError → builtins.Exception → builtins.BaseException → builtins.object

Data descriptors defined here:

Methods inherited from builtins.ValueError:

Methods inherited from builtins.BaseException:

Data descriptors inherited from builtins.BaseException:

🔀 class TopologicalSorter(builtins.object)

TopologicalSorter(graph=None)

Provides functionality to topologically sort a graph of hashable nodes.

Methods defined here:

Data descriptors defined here:

📦 DATA

__all__ = ['TopologicalSorter', 'CycleError']

📁 FILE

/usr/lib/python3.10/graphlib.py

graphlib
📛 NAME 🚀 Quick Reference 📚 MODULE REFERENCE 🏛️ CLASSES
⚠️ class CycleError(builtins.ValueError) 🔀 class TopologicalSorter(builtins.object)
📦 DATA 📁 FILE

Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 18:06 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^