Scientific Computing

networkx

Maps out how anything, people, cities, molecules, connects to anything else, and finds the patterns hiding in the tangle.

Install it: pip install networkx

What does it do?

NetworkX represents relationships as networks, dots connected by lines, and lets you analyze them: who’s the most influential person in a social network, what’s the fastest route through a map, which webpage is most central to the internet’s link structure. It’s the digital equivalent of a detective’s corkboard covered in photos and string, except NetworkX can instantly calculate which photo has the most strings connecting to it. It comes with dozens of ready-made algorithms for finding shortest paths, detecting clusters of tightly connected nodes, and measuring how central each point in the network is. It doesn’t just store the network, it lets you interrogate it mathematically.

See it in action

This builds a small map of who is connected to whom, then finds the shortest way to get from one person to another and measures how well-connected each person is.

import networkx as nx

G = nx.Graph()
G.add_edge("Alice", "Bob")
G.add_edge("Bob", "Carol")
G.add_edge("Alice", "Carol")

print(nx.shortest_path(G, "Alice", "Carol"))
print(nx.degree_centrality(G))

Why would a non-developer care?

Anything built around relationships, friend networks, recommendation systems, supply chains, disease spread, transportation systems, is understood far better once modeled as a network, and NetworkX makes that modeling and analysis accessible without a PhD in graph theory.

Real-world examples

Researchers have used network analysis techniques like those NetworkX implements to study how diseases spread through contact networks, and social media companies use similar graph thinking to figure out who to show you in people you may know. It’s also used in academic research on citation networks, mapping which scientific papers reference which others. Airlines and logistics companies use graph-based tools to optimize routes across networks of cities and hubs.

Who uses it

Researchers in social science, biology, and network analysis, plus data scientists modeling relationships like recommendation systems or supply chains.

How it compares to alternatives

NetworkX is easier to learn and more widely used for general graph analysis in Python than more specialized alternatives like igraph or graph-tool, though those competitors are often significantly faster on very large networks since NetworkX prioritizes ease of use over raw performance.

Fun fact

NetworkX’s algorithms are general enough that the exact same code used to analyze a social media friend network can, with no changes, analyze the structure of a power grid or a protein interaction network.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries