NetworkX
Graph analysis and network algorithms library for Python — create, manipulate, and analyze graphs and networks. NetworkX features: Graph/DiGraph/MultiGraph for graph types, nx.add_nodes_from()/add_edges_from() with attributes, shortest path (nx.shortest_path, nx.dijkstra_path), centrality measures (betweenness, PageRank, eigenvector), community detection (nx.community), connected components, clustering coefficient, graph generators (nx.barabasi_albert_graph), graph I/O (GraphML, GML, edgelist, GEXF), drawing with matplotlib, and algorithm library (BFS, DFS, topological sort, minimum spanning tree, max flow). Standard Python graph library for knowledge graph analysis, dependency graphs, social network analysis, and workflow DAG management.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Local computation — no network calls during analysis. GraphML/GEXF file loading could process untrusted graph files — validate file source. No code execution from graph data. No security concerns for standard use.
⚡ Reliability
Best When
Graph algorithm applications (shortest path, centrality, community detection, topological sort) on medium-scale graphs (up to ~500K nodes) — NetworkX provides 100+ graph algorithms with a clean Pythonic API and rich attribute support.
Avoid When
Your graph has millions of nodes (use graph-tool or cuGraph), you need GNNs (use PyG/DGL), or need real-time streaming graph updates.
Use Cases
- • Agent knowledge graph traversal — G = nx.DiGraph(); G.add_edges_from([(entity1, entity2, {'relation': 'is_a'})]); path = nx.shortest_path(G, source='concept_a', target='concept_b'); subgraph = G.subgraph(nx.single_source_shortest_path_length(G, 'root', cutoff=2)) — traverse knowledge graph relationships; agent reasoning system finds conceptual paths and extracts neighborhood subgraphs
- • Agent dependency resolution — G = nx.DiGraph(); G.add_edges_from(package_deps); order = list(nx.topological_sort(G)); if nx.is_directed_acyclic_graph(G) else raise_cycle_error() — topological sort for package install order; agent build system resolves dependency graph for correct installation sequence; detects circular dependencies
- • Agent social network analysis — G = nx.from_pandas_edgelist(df, 'user', 'friend'); centrality = nx.betweenness_centrality(G); pagerank = nx.pagerank(G); communities = list(nx.community.greedy_modularity_communities(G)) — analyze social graph; agent identifies influencers, community structure, and bridge nodes for viral campaign targeting
- • Agent workflow DAG — G = nx.DiGraph(); G.add_node('task_a', func=fn_a, inputs=[]); G.add_edge('task_a', 'task_b'); levels = list(nx.topological_generations(G)); for level in levels: [run_parallel(G.nodes[n]) for n in level] — workflow execution engine using DAG; agent orchestrates parallel task execution respecting dependencies with topological level batching
- • Agent route optimization — G = nx.DiGraph(); for u, v, weight in edges: G.add_edge(u, v, weight=weight); path = nx.dijkstra_path(G, source, target, weight='weight'); length = nx.dijkstra_path_length(G, source, target) — weighted shortest path on road/network graph; agent delivery route planner finds optimal path accounting for edge weights
Not For
- • Large-scale graphs (millions of nodes) — NetworkX is pure Python and slow for graphs >1M nodes; use graph-tool or cuGraph for large-scale graph analytics
- • Graph neural networks — NetworkX is classical graph algorithms; for GNNs use PyTorch Geometric or DGL
- • Streaming/dynamic graphs — NetworkX is in-memory static; for dynamic graph analytics use raphtory or other streaming frameworks
Interface
Authentication
No auth — local graph library.
Pricing
NetworkX is BSD licensed. Free for all use.
Agent Metadata
Known Gotchas
- ⚠ nx.shortest_path raises NetworkXNoPath not returning None — nx.shortest_path(G, source, target) raises NetworkXNoPath if no path exists; agent code must use try/except: try: path = nx.shortest_path(G, s, t) except nx.NetworkXNoPath: handle_disconnected(); not checking causes uncaught exception in agent routing code
- ⚠ Nodes can be any hashable — G.add_node(42); G.add_node('hello'); G.add_node(('tuple', 1)); agent code mixing int and string node IDs creates separate nodes (1 != '1'); normalize node IDs to consistent type before building graph to avoid silent duplicate nodes
- ⚠ G.nodes and G.edges return views not lists — G.nodes returns NodeView, not list; agent code doing len(G.nodes) works but G.nodes[0] fails; for indexing: list(G.nodes)[0]; for attribute access: G.nodes[node_id]['attribute'] using node ID as key not integer index
- ⚠ DiGraph vs Graph matters for algorithms — nx.shortest_path on undirected Graph ignores direction; nx.betweenness_centrality on DiGraph considers direction; agent code building directed social/dependency graph must use nx.DiGraph() not nx.Graph() or algorithms give wrong results
- ⚠ Betweenness centrality is O(n*m) expensive — nx.betweenness_centrality(G) on 10K node graph takes 10+ seconds; agent code calling centrality on every iteration must cache results or use nx.betweenness_centrality(G, k=1000) for approximate computation with k sample nodes
- ⚠ topological_sort raises on cycles — nx.topological_sort(G) raises NetworkXUnfeasible for graphs with cycles; agent dependency resolution must check nx.is_directed_acyclic_graph(G) first or catch exception; cycles = list(nx.simple_cycles(G)) identifies which nodes form cycles for error reporting
Alternatives
Full Evaluation Report
Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for NetworkX.
AI-powered analysis · PDF + markdown · Delivered within 30 minutes
Package Brief
Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.
Delivered within 10 minutes
Score Monitoring
Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.
Continuous monitoring
Scores are editorial opinions as of 2026-03-06.