Graph Analysis
v1.0.0Analyze graphs and networks using Python NetworkX — centrality, shortest paths, community detection, and visualization.
Security Scan
OpenClaw
Benign
high confidencePurpose & Capability
Name/description (graph analysis with NetworkX) lines up with the instructions: building graphs, metrics, paths, community detection, visualization. Required tools (python3, pip) in the metadata are reasonable for this purpose.
Instruction Scope
Instructions tell the agent to read user-provided CSV/JSON files and save PNGs — this is expected for a data-analysis skill. The SKILL.md does not instruct reading system credentials or unrelated paths. It does recommend installing packages and inferring source/target columns from user data, so users should be aware the agent will access files the user supplies.
Install Mechanism
This is an instruction-only skill (no install spec), but the README tells operators to run `pip install networkx matplotlib numpy --break-system-packages`. Installing from PyPI is normal for Python tools, but `--break-system-packages` can alter system Python environments and is risky — prefer using a virtual environment. No downloads from arbitrary URLs or archive extraction are present.
Credentials
No environment variables, credentials, or config paths are requested. The skill does not ask for unrelated secrets or broad access tokens.
Persistence & Privilege
Skill is not forced always-on and does not request elevated agent-level persistence or modify other skills. Autonomous invocation is allowed (platform default) but not combined with any broad privileges here.
Assessment
This skill is essentially a how-to for doing graph analysis with NetworkX and appears coherent. Before installing/running: 1) run the pip installs inside a virtualenv or conda environment instead of using `--break-system-packages`; 2) verify the louvain/community function you need is available in your NetworkX version (some setups require an extra community package); 3) be mindful that the skill's examples read user CSV/JSON files and write PNGs — only provide data you want analyzed or shared; 4) the skill metadata declares files (scripts/*) that are not present in the package — that mismatch is benign but worth confirming the repo/source you obtained; 5) if you will run this in an environment with sensitive system data, sandbox the execution and review any concrete code before granting file access.Like a lobster shell, security has layers — review code before you run it.
Runtime requirements
🕸️ Clawdis
latest
Graph Analysis Skill
Analyze graphs and networks using Python and NetworkX. Supports building graphs from data, running graph algorithms, and generating visualizations.
Setup
Before first use, install dependencies:
pip install networkx matplotlib numpy --break-system-packages
Capabilities
1. Build a Graph
Create graphs from edge lists, adjacency matrices, CSV files, or JSON data.
From an edge list (CSV or inline):
import networkx as nx
# From a CSV file with columns: source, target, weight (optional)
import csv
G = nx.Graph()
with open("edges.csv") as f:
reader = csv.DictReader(f)
for row in reader:
weight = float(row.get("weight", 1.0))
G.add_edge(row["source"], row["target"], weight=weight)
From inline data:
import networkx as nx
G = nx.Graph()
G.add_edges_from([("A", "B"), ("B", "C"), ("A", "C"), ("C", "D")])
Directed graph:
G = nx.DiGraph()
G.add_edges_from([("A", "B"), ("B", "C")])
2. Graph Metrics
Run these to answer questions about graph structure:
import networkx as nx
# Basic stats
print(f"Nodes: {G.number_of_nodes()}")
print(f"Edges: {G.number_of_edges()}")
print(f"Density: {nx.density(G):.4f}")
print(f"Connected: {nx.is_connected(G)}")
# Centrality measures
degree_cent = nx.degree_centrality(G)
betweenness = nx.betweenness_centrality(G)
closeness = nx.closeness_centrality(G)
pagerank = nx.pagerank(G)
# Find most important nodes
top_by_degree = sorted(degree_cent.items(), key=lambda x: x[1], reverse=True)[:10]
top_by_betweenness = sorted(betweenness.items(), key=lambda x: x[1], reverse=True)[:10]
top_by_pagerank = sorted(pagerank.items(), key=lambda x: x[1], reverse=True)[:10]
print("Top nodes by degree centrality:", top_by_degree)
print("Top nodes by betweenness:", top_by_betweenness)
print("Top nodes by PageRank:", top_by_pagerank)
3. Shortest Paths
# Shortest path between two nodes
path = nx.shortest_path(G, source="A", target="D")
length = nx.shortest_path_length(G, source="A", target="D")
print(f"Path: {' -> '.join(path)} (length: {length})")
# Weighted shortest path
path_w = nx.shortest_path(G, source="A", target="D", weight="weight")
# All pairs shortest path lengths
all_lengths = dict(nx.all_pairs_shortest_path_length(G))
4. Community Detection
from networkx.algorithms.community import greedy_modularity_communities, louvain_communities
# Greedy modularity
communities_greedy = list(greedy_modularity_communities(G))
print(f"Found {len(communities_greedy)} communities (greedy)")
# Louvain (better for large graphs)
communities_louvain = list(louvain_communities(G))
print(f"Found {len(communities_louvain)} communities (Louvain)")
# Print community membership
for i, comm in enumerate(communities_louvain):
print(f" Community {i}: {sorted(comm)}")
5. Visualization
Save graph visualizations as PNG images:
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import networkx as nx
fig, ax = plt.subplots(figsize=(12, 8))
# Layout options: spring_layout, circular_layout, kamada_kawai_layout, shell_layout
pos = nx.spring_layout(G, seed=42)
# Size nodes by degree
node_sizes = [300 * G.degree(n) for n in G.nodes()]
# Color nodes by community (if communities were computed)
nx.draw(
G, pos, ax=ax,
with_labels=True,
node_size=node_sizes,
node_color="steelblue",
edge_color="#cccccc",
font_size=8,
font_weight="bold",
width=0.8,
)
ax.set_title("Graph Visualization")
plt.tight_layout()
plt.savefig("graph.png", dpi=150)
plt.close()
print("Saved graph.png")
Color by community:
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import networkx as nx
from networkx.algorithms.community import louvain_communities
communities = list(louvain_communities(G))
color_map = {}
for i, comm in enumerate(communities):
for node in comm:
color_map[node] = i
node_colors = [color_map[n] for n in G.nodes()]
pos = nx.spring_layout(G, seed=42)
fig, ax = plt.subplots(figsize=(12, 8))
nx.draw(
G, pos, ax=ax,
with_labels=True,
node_color=node_colors,
cmap=plt.cm.Set3,
node_size=500,
edge_color="#cccccc",
font_size=8,
)
ax.set_title("Communities")
plt.tight_layout()
plt.savefig("communities.png", dpi=150)
plt.close()
print("Saved communities.png")
6. Graph Generators (for testing or simulation)
import networkx as nx
# Common test graphs
G = nx.karate_club_graph() # Classic social network (34 nodes)
G = nx.barabasi_albert_graph(100, 3) # Scale-free network
G = nx.erdos_renyi_graph(50, 0.1) # Random graph
G = nx.watts_strogatz_graph(30, 4, 0.3) # Small-world network
When to Use This Skill
Use this skill when the user asks to:
- Analyze relationships, connections, or networks in data
- Find important/central/influential nodes in a network
- Detect communities or clusters in a graph
- Find shortest paths between entities
- Visualize a network or relationship diagram
- Build a graph from CSV, JSON, or other structured data
- Run graph algorithms (PageRank, centrality, clustering coefficient, etc.)
Notes
- For large graphs (>10,000 nodes), prefer
louvain_communitiesovergreedy_modularity_communities - Always use
matplotlib.use("Agg")before importing pyplot (no display server) - Save visualizations as PNG files and show them to the user
- When reading user data, infer source/target columns from context — common patterns include: from/to, source/target, node1/node2, parent/child
Comments
Loading comments...
