{"id":45039,"library":"graphlib","title":"graphlib","description":"A Python library providing a simple Graph API for directed graphs. Current version 0.9.5, released periodically with minimal breaking changes.","status":"active","version":"0.9.5","language":"python","source_language":"en","source_url":"https://github.com/bruth/graphlib/","tags":["graph","directed","topological-sort","cycle-detection"],"install":[{"cmd":"pip install graphlib","lang":"bash","label":"Latest from PyPI"}],"dependencies":[],"imports":[{"wrong":"from graphlib import Graph","symbol":"TopologicalSorter","correct":"from graphlib import TopologicalSorter"},{"symbol":"CycleError","correct":"from graphlib import CycleError"},{"symbol":"GenericAlias","correct":"from graphlib import GenericAlias"}],"quickstart":{"code":"from graphlib import Graph\n\ng = Graph()\ng.add_edge('A', 'B')\ng.add_edge('B', 'C')\n# Perform topological sort\norder = list(g.topological_sort())\nprint(order)  # Output: ['A', 'B', 'C'] (or similar)\n# Check if graph has cycle\nprint(g.has_cycle())  # Output: False","lang":"python","description":"Create a directed graph, add edges, topologically sort, and detect cycles."},"warnings":[{"fix":"Replace Graph([('A','B')]) with g = Graph(); g.add_edge('A','B').","message":"In version 0.9.0, the Graph class constructor changed: graphlib no longer accepts a list of edges as argument; use add_edge() instead.","severity":"breaking","affected_versions":">=0.9.0"},{"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').","message":"The library does not support multiple edges between same nodes; adding duplicate edge silently succeeds but only one edge is stored.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure you iterate once: order = list(g.topological_sort()).","message":"The method 'topological_sort' returns a generator, not a list. Some code incorrectly wraps it with list() twice, causing error or empty result.","severity":"deprecated","affected_versions":">=0.9.0"}],"env_vars":null,"search_vec":"'0.9.5':15 'api':9 'break':20 'chang':21 'current':13 'cycl':28 'cycle-detect':27 'detect':29 'direct':11,23 'graph':8,12,22 'graphlib':1 'librari':4 'minim':19 'period':17 'provid':5 'python':3 'releas':16 'simpl':7 'sort':26 'topolog':25 'topological-sort':24 'version':14","created_at":"2026-06-07T12:53:04.785709+00:00","updated_at":"2026-06-07T12:53:04.785709+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/bruth/graphlib/","github":"https://github.com/bruth/graphlib/","docs":null,"changelog":null,"pypi":null,"npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":null}}