{"id":27027,"library":"graph-lib","title":"graph-lib","description":"A set of diffusion related graph algorithms for Python, including community detection, node ranking, and graph sampling. Current version 0.4.8. Low release cadence.","status":"active","version":"0.4.8","language":"python","source_language":"en","source_url":"https://github.com/MengLiuPurdue/graph_lib","tags":["graph","diffusion","community detection","spectral clustering","networkx"],"install":[{"cmd":"pip install graph-lib","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Core dependency for numerical operations","package":"numpy","optional":false},{"reason":"Graph data structures and algorithms","package":"networkx","optional":false},{"reason":"Sparse matrix operations","package":"scipy","optional":false}],"imports":[{"note":"graphlib is a stdlib module (topological sort) completely different from graph-lib","wrong":"import graphlib","symbol":"graph_lib","correct":"import graph_lib"}],"quickstart":{"code":"import graph_lib\nimport networkx as nx\n\nG = nx.karate_club_graph()\ncommunities = graph_lib.spectral_partitioning(G, k=2)\nprint(communities)","lang":"python","description":"Detect two communities in Zachary's karate club graph using spectral partitioning."},"warnings":[{"fix":"Replace graph_lib.diffusion_map(G) with graph_lib.spectral_embedding(G, n_components=None)","message":"Function 'graph_lib.diffusion_map' has been deprecated in v0.4.0. Use 'graph_lib.spectral_embedding' instead.","severity":"deprecated","affected_versions":">=0.4.0"},{"fix":"Use 'import graph_lib' or 'from graph_lib import ...'","message":"The package imports as 'graph_lib' (underscore), not 'graphlib'. Importing 'graphlib' silently imports Python's stdlib module which does not raise an error but gives wrong results.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure node labels are integers, e.g., G = nx.convert_node_labels_to_integers(G)","message":"Graph algorithms expect node labels to be integers. Non-integer labels may cause silent type errors in internal matrix construction.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"pip install graph-lib and then import graph_lib (with underscore).","cause":"Trying to import as 'graphlib' which is a stdlib module. The correct import uses underscore: 'graph_lib'.","error":"ModuleNotFoundError: No module named 'graphlib'"},{"fix":"Relabel nodes to integers: G = nx.convert_node_labels_to_integers(G)","cause":"Passing non-integer node labels that cause internal conversion errors.","error":"TypeError: unsupported operand type(s) for +: 'int' and 'list'"},{"fix":"Use graph_lib.spectral_embedding(G, n_components=None) instead.","cause":"diffusion_map was removed/deprecated in newer versions. Use spectral_embedding instead.","error":"AttributeError: module 'graph_lib' has no attribute 'diffusion_map'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}