networkx – Marketing & SEO skill for AI agents
Creates, analyzes, and visualizes complex networks and graphs in Python with NetworkX. Use when working with network/graph data structures, computing graph algorithms (shortest paths, centrality, clustering), detecting communities, generating synthetic networks (random, scale-free, small-world), reading/writing graph f
Install the networkx skill with one command
Pick the tool you use, copy the command and paste it in your terminal. The skill lands in that tool's skills folder and is ready in your next session.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/networkx-404e1.tgz | tar xz -C ~/.claude/skills
Call it in Claude Code: /networkx – then describe the task you want done.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/networkx-404e1.tgz | tar xz -C ~/.codex/skills
Call it in Codex: $networkx – then describe the task you want done.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/networkx-404e1.tgz | tar xz -C ~/.hermes/skills
Call it in Hermes Agent: /networkx – then describe the task you want done.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/networkx-404e1.tgz | tar xz -C ~/.deepcode/skills
Call it in DeepSeek: /networkx – then describe the task you want done.
SKILL.md content
NetworkX
Overview
NetworkX is a Python package for creating, manipulating, and analyzing complex networks and graphs. Use this skill when working with network or graph data structures, including social networks, biological networks, transportation systems, citation networks, knowledge graphs, or any system involving relationships between entities.
This skill targets tested NetworkX 3.7 (Python >=3.12, excluding 3.14.1). Several pre-3.0 APIs (nx.info, nx.write_gpickle, nx.read_shp) and the 3.4-era nx.random_tree no longer exist — current replacements are used throughout this skill.
Review sources, executed examples, optional-dependency limits, and reproducibility notes are in [references/review.md](references/review.md). Reference snippets are API patterns: supply the stated graph type and input files; they are not one sequential script.
When to Use This Skill
Invoke this skill when tasks involve:
- Creating graphs: Building network structures from data, adding nodes and edges with attributes
- Graph analysis: Computing centrality measures, finding shortest paths, detecting communities, measuring clustering
- Graph algorithms: Running standard algorithms like Dijkstra's, PageRank, minimum spanning trees, maximum flow
- Network generation: Creating synthetic networks (random, scale-free, small-world models) for testing or simulation
- Graph I/O: Reading from or writing to various formats (edge lists, GraphML, JSON, CSV, adjacency matrices)
- Visualization: Drawing and customizing network visualizations with matplotlib or interactive libraries
- Network comparison: Checking isomorphism, computing graph metrics, analyzing structural properties
Core Capabilities
1. Graph Creation and Manipulation
NetworkX supports four main graph types:
- Graph: Undirected graphs with single edges
- DiGraph: Directed graphs with one-way connections
- MultiGraph: Undirected graphs allowing multiple edges between nodes
- MultiDiGraph: Directed graphs with multiple edges
Create graphs by:
import networkx as nx
# Create empty graph
G = nx.Graph()
# Add nodes (can be any hashable type)
G.add_node(1)
G.add_nodes_from([2, 3, 4])
G.add_node("protein_A", type='enzyme', weight=1.5)
# Add edges
G.add_edge(1, 2)
G.add_edges_from([(1, 3), (2, 4)])
G.add_edge(1, 4, weight=0.8, relation='interacts')Reference: See references/graph-basics.md for comprehensive guidance on creating, modifying, examining, and managing graph structures, including working with attributes and subgraphs.
2. Graph Algorithms
NetworkX provides extensive algorithms for network analysis:
Shortest Paths:
For weighted paths and betweenness, weights represent distances/costs: larger values
make a route less favorable. Similarity, correlation, or interaction strength needs an
explicit scientifically justified conversion before use as distance. Validate the chosen
attribute on every edge and use strictly positive distances for weighted betweenness.
# Same distance model for route and length
G = nx.Graph()
G.add_weighted_edges_from([(1, 2, 1), (2, 5, 1), (1, 5, 5)], weight='distance')
path = nx.shortest_path(G, source=1, target=5, weight='distance')
length = nx.shortest_path_length(G, source=1, target=5, weight='distance')
assert path == [1, 2, 5] and length == 2Centrality Measures:
# Degree centrality
degree_cent = nx.degree_centrality(G)
# Betweenness centrality
betweenness = nx.betweenness_centrality(G)
# PageRank
pagerank = nx.pagerank(G)Community Detection:
from networkx.algorithms import community
# Specify weight=None for unweighted topology
communities = community.greedy_modularity_communities(G, weight=None)Connectivity:
# Check connectivity
is_connected = nx.is_connected(G)
# Find connected components
components = list(nx.connected_components(G))Reference: See references/algorithms.md for worked API patterns for common algorithms including shortest paths, centrality measures, clustering, community detection, flows, matching, tree algorithms, and graph traversal.
3. Graph Generators
Create synthetic networks for testing, simulation, or modeling:
Classic Graphs:
# Complete graph
G = nx.complete_graph(n=10)
# Cycle graph
G = nx.cycle_graph(n=20)
# Known graphs
G = nx.karate_club_graph()
G = nx.petersen_graph()Random Networks:
# Erdős-Rényi random graph
G = nx.erdos_renyi_graph(n=100, p=0.1, seed=42)
# Barabási-Albert scale-free network
G = nx.barabasi_albert_graph(n=100, m=3, seed=42)
# Watts-Strogatz small-world network
G = nx.watts_strogatz_graph(n=100, k=6, p=0.1, seed=42)Structured Networks:
# Grid graph
G = nx.grid_2d_graph(m=5, n=7)
# Random tree (random_tree was removed in NetworkX 3.4)
G = nx.random_labeled_tree(100, seed=42)Reference: See references/generators.md for representative graph generators including classic, random, lattice, bipartite, and specialized network models with detailed parameters and use cases.
4. Reading and Writing Graphs
NetworkX supports numerous file formats and data sources:
File Formats:
# Edge list
G = nx.read_edgelist('graph.edgelist')
nx.write_edgelist(G, 'graph.edgelist')
# GraphML (supported scalar attributes; node IDs read as strings by default)
G = nx.read_graphml('graph.graphml')
nx.write_graphml(G, 'graph.graphml')
# GML
G = nx.read_gml('graph.gml')
nx.write_gml(G, 'graph.gml')
# JSON (node-link format; edge list is stored under the "edges" key
# since NetworkX 3.6 — older files may use "links", see references/io.md)
data = nx.node_link_data(G, edges="edges")
G = nx.node_link_graph(data, edges="edges")Pandas Integration:
import pandas as pd
# From DataFrame
df = pd.DataFrame({'source': [1, 2, 3], 'target': [2, 3, 4], 'weight': [0.5, 1.0, 0.75]})
G = nx.from_pandas_edgelist(df, 'source', 'target', edge_attr='weight')
# To DataFrame
df = nx.to_pandas_edgelist(G)Matrix Formats:
import numpy as np
# Simple-graph adjacency: preserve node ordering, direction and zero weights
nodes = list(G)
A = nx.to_numpy_array(G, nodelist=nodes, nonedge=np.nan)
H = nx.from_numpy_array(A, nodelist=nodes, create_using=type(G), nonedge=np.nan)
# Sparse adjacency sums parallel-edge weights; save labels separately
A = nx.to_scipy_sparse_array(G, nodelist=nodes)
H = nx.from_scipy_sparse_array(A, create_using=type(G))
H = nx.relabel_nodes(H, dict(enumerate(nodes)))Reference: See references/io.md for complete documentation on all I/O formats including CSV, SQL databases, Cytoscape, DOT, and guidance on format selection for different use cases.
5. Visualization
Create clear and informative network visualizations:
Basic Visualization:
import matplotlib.pyplot as plt
# Simple draw
nx.draw(G, with_labels=True)
plt.show()
# With layout
pos = nx.spring_layout(G, seed=42)
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500)
plt.show()Customization:
# Color by degree
node_colors = [G.degree(n) for n in G.nodes()]
nx.draw(G, node_color=node_colors, cmap=plt.cm.viridis)
# Size by centrality
centrality = nx.betweenness_centrality(G)
node_sizes = [3000 * centrality[n] for n in G.nodes()]
nx.draw(G, node_size=node_sizes)
# Edge weights
edge_widths = [3 * G[u][v].get('weight', 1) for u, v in G.edges()]
nx.draw(G, width=edge_widths)Layout Algorithms:
# Spring layout (force-directed)
pos = nx.spring_layout(G, seed=42)
# Circular layout
pos = nx.circular_layout(G)
# Kamada-Kawai layout
pos = nx.kamada_kawai_layout(G)
# Spectral layout
pos = nx.spectral_layout(G)Publication Quality:
fig, ax = plt.subplots(figsize=(12, 8))
pos = nx.spring_layout(G, seed=42)
nx.draw(G, pos=pos, ax=ax, node_color='lightblue', node_size=500,
edge_color='gray', with_labels=True, font_size=10)
plt.title('Network Visualization', fontsize=16)
plt.axis('off')
plt.tight_layout()
plt.savefig('network.png', dpi=300, bbox_inches='tight')
plt.savefig('network.pdf', bbox_inches='tight') # Vector formatReference: See references/visualization.md for extensive documentation on visualization techniques including layout algorithms, customization options, interactive visualizations with Plotly and PyVis, 3D networks, and publication-quality figure creation.
Working with NetworkX
Installation
Ensure NetworkX is installed:
# Check if installed
import networkx as nx
print(nx.__version__)
# Install if needed (via bash)
# uv pip install "networkx==3.7"
# uv pip install "networkx[default]==3.7" # With optional dependenciesCommon Workflow Pattern
Most NetworkX tasks follow this pattern:
1. Create or Load Graph: choose direction, parallel-edge and self-loop rules before importing. Keep an explicit node table so isolates
… (full content is in the download package)
Related skills
- reverse-engineer-marketing – When the user wants to reverse engineer how another company grew and copy what worked…
- customer-success-manager – Monitors customer health, predicts churn risk, and identifies expansion opportunities…
- revops – When the user wants help with revenue operations, lead lifecycle management, or…
- nwb-conversion – Converts neuroscience acquisition data to Neurodata Without Borders files with NeuroConv…
- deal-desk – Use when reviewing a specific inbound deal before close — when sales has asked for a…
- sales-enablement – When the user wants to create sales collateral, pitch decks, one-pagers, objection…
- hunt-session – Hunt Session Management vulnerabilities — session fixation (no regeneration on login)…
- seo-audit – When the user wants to audit, review, or diagnose SEO issues on their site. Also use…