Registry / devops / graphlib

graphlib

JSON →
library0.9.5pypypi✓ verified 79d ago

A Python library providing a simple Graph API for directed graphs. Current version 0.9.5, released periodically with minimal breaking changes.

pip install graphlib
INSTALL
IMPORT
SIG · GRAPHLIB
G
graphlib
devopspythonv0.9.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TopologicalSorter
from graphlib import TopologicalSorter
from graphlib import Graph
CycleError
from graphlib import CycleError
GenericAlias
from graphlib import GenericAlias

Create a directed graph, add edges, topologically sort, and detect cycles.

from graphlib import Graph g = Graph() g.add_edge('A', 'B') g.add_edge('B', 'C') # Perform topological sort order = list(g.topological_sort()) print(order) # Output: ['A', 'B', 'C'] (or similar) # Check if graph has cycle print(g.has_cycle()) # Output: False
Debug
Known issues
breakingIn version 0.9.0, the Graph class constructor changed: graphlib no longer accepts a list of edges as argument; use add_edge() instead.
fix
Replace Graph([('A','B')]) with g = Graph(); g.add_edge('A','B').
affects: >=0.9.0
gotchaThe library does not support multiple edges between same nodes; adding duplicate edge silently succeeds but only one edge is stored.
fix
Use a custom check before add_edge if you need to avoid duplicates: if not g.has_edge('A','B'): g.add_edge('A','B').
affects: all
deprecatedThe method 'topological_sort' returns a generator, not a list. Some code incorrectly wraps it with list() twice, causing error or empty result.
fix
Ensure you iterate once: order = list(g.topological_sort()).
affects: >=0.9.0
Upgrade
Version history
0.9.5latest on PyPI · released Jun 12, 2014
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
20
Resources
graphlib — pip install graphlib · libregistry