networkxlisted
Install: claude install-skill SenolIsci/mykg
# NetworkX Skill — Create and Manipulate Networks
NetworkX (v3.6+) is the standard Python library for graph analysis. This skill covers everything from basic graph creation to advanced algorithms. When in doubt, prefer simple explicit code over clever one-liners — graphs are complex enough on their own.
**References:**
- [algorithms.md](references/algorithms.md) — Algorithm reference by category (centrality, community, flow, etc.)
- [io.md](references/io.md) — File I/O and format conversion reference
---
## 1. Choosing a Graph Class
Pick the right class first — it cannot easily be changed after construction.
```python
import networkx as nx
G = nx.Graph() # undirected, no parallel edges
DG = nx.DiGraph() # directed, no parallel edges
MG = nx.MultiGraph() # undirected + parallel edges allowed
MD = nx.MultiDiGraph() # directed + parallel edges allowed
```
| Need | Class |
|---|---|
| Social networks, protein interactions | `Graph` |
| Web graphs, citation networks, DAGs | `DiGraph` |
| Transport networks (multiple routes) | `MultiGraph` |
| Dependency graphs with typed edges | `MultiDiGraph` |
Convert between types:
```python
DG = G.to_directed() # Graph → DiGraph (each edge becomes two arcs)
G2 = DG.to_undirected() # DiGraph → Graph
```
---
## 2. Building Graphs
### Add Nodes
Any hashable Python object is a valid node: int, str, tuple, frozenset.
```python
G.add_node(1)
G.add_node("Alice", age=30, role="engineer") # node with attributes