
Chris Parmer
2026-11-14
NetworkX demo
Network and graph analysis in Python, with Dash and Plotly
TL;DR
- NetworkX is Python's standard library for graphs, meaning things connected to other things, such as substations, companies, proteins, internet providers and airports. Aric Hagberg, Dan Schult and Pieter Swart started it at Los Alamos National Laboratory, and its release log goes back to June 2005.
- It has hundreds of algorithms for paths, flows, centrality, communities, trees and matching, and works on graphs you build from pandas tables in a few lines.
- This demo runs five of them on public networks from energy, finance, life sciences, telecom and aviation, then puts two of them in a Dash app that recomputes when you take parts of the network out.
- Version 3.7 (September 21, 2026) adds Leiden community detection, subgraph matching with VF2++ and faster strongly connected components, and needs Python 3.12.

What is NetworkX?
Many questions domain experts ask are about connections rather than rows. A grid planner wants to know how much power can cross a border, and a compliance analyst which entities roll up to a bank. A biologist asks which proteins work together around a drug target, and a network engineer or an airline planner asks which single node the rest of the network depends on. Each of those is a graph of nodes and edges, and the answer is a graph algorithm.
NetworkX gives you those algorithms in plain Python. Nodes can be any hashable value, such as a bus ID, a legal entity identifier or a gene name, and edges carry whatever attributes you like, such as capacity, ownership type or flight counts. It reads edge lists from pandas and files like GraphML, converts to SciPy sparse matrices, and can hand work to faster backends such as nx-cugraph without code changes. That makes it a good fit for Dash apps about resilience, ownership, supply chains, biological pathways and routing, where a callback reruns an algorithm whenever someone changes the network.
The examples below show five of those questions on public data, each in a different field. For the other packages we use in Dash apps, see our guide to Python packages for data.
The data: five public networks, from 351 airports to 170,075 legal entities
Network
Field
Source
Nodes and edges
European transmission grid
Energy
PyPSA-Eur prebuilt network from OpenStreetMap, v0.8
7,017 buses, 9,011 lines, links and transformers
Corporate ownership
Finance
GLEIF relationship records, November 14, 2026
170,075 legal entities, 127,547 direct-parent links
Human protein interactions
Life sciences
STRING v12.0, combined score 900 or more
12,323 proteins, 100,856 links
Internet transit
Telecom
CAIDA AS relationships, November 2026
81,330 networks, 171,391 provider-to-customer links
U.S. airline routes
Aviation
BTS On-Time Performance, August 2026
351 airports, 5,582 routes flown 8 or more times
All five arrive as edge lists, so loading is the same each time: read the table with pandas and pass it to nx.from_pandas_edgelist. nx.describe(G) prints a quick summary of what you built, and in 3.7 it includes the density.
The quickest look at a network is how many links each node has. In four of the five, most nodes have one or two links and a few hubs have hundreds or thousands, while no bus in the grid has more than 11.

Five things you can do with NetworkX
1. Energy: find the bottleneck between two countries with a minimum cut
A minimum cut separates two sides of a network by removing the edges with the smallest total capacity, and that total is also the most that can flow between them. To cut between two groups of nodes rather than two single nodes, connect each group to a virtual source or sink with edges that have no capacity, which NetworkX treats as unlimited.

H = G.copy()for n, country in G.nodes(data="country"):if country in {"ES", "PT"}: H.add_edge("src", n) # no capacity attribute = unlimitedif country == "FR": H.add_edge(n, "sink")mva, (iberia, rest) = nx.minimum_cut(H, "src", "sink")
The cut between Iberia and France runs through only five links. These are thermal ratings from OpenStreetMap, so what operators allow across a border is lower.
2. Finance: rebuild corporate groups from legal entity identifiers
A Legal Entity Identifier (LEI) is the 20-character ID regulators require for parties to financial transactions, and GLEIF, the foundation that runs the system, publishes who owns whom. Each "directly consolidated by" record is an edge from a subsidiary to its parent, so the ancestors of each top parent are its group.

own = nx.from_pandas_edgelist(direct, "Relationship.StartNode.NodeID", "Relationship.EndNode.NodeID", create_using=nx.DiGraph)loops = [c for c in nx.strongly_connected_components(own) if len(c) > 1] # ownership should have nonegroups = {t: nx.ancestors(own, t) for t in own if own.out_degree(t) == 0}
Ownership shouldn't have cycles, so strongly_connected_components doubles as a data quality check, and it found a few entities that list each other as parents. Walking each chain to the top is also a way to check the ultimate parent each entity reports.
3. Life sciences: find protein modules around a drug target with Leiden
Proteins that work together form densely linked modules, so community detection on an interaction network shows what a drug target sits next to. NetworkX already had Louvain, and 3.7 adds Leiden, which refines each community so it stays connected.

H = nx.convert_node_labels_to_integers(ppi, ordering="sorted", label_attribute="name") # repeatable resultsfound = nx.community.leiden_communities(H, metric="modularity", resolution=10, seed=42) # new in 3.7
KRAS lands with its RAS siblings and the RAF kinases they activate, and GLP1R with peptide hormones such as glucagon. Relabel string node names to integers first, as above, because Python hashes strings differently in each process and the same seed can otherwise give different communities.
4. Telecom: find each network's single point of failure with a dominator tree
Internet providers sell transit to customers, which sell it on, so provider-to-customer links form a hierarchy. If every path from a network up to the top runs through one provider, that provider dominates it, and immediate_dominators finds it for all 81,330 networks at once.

transit.add_edges_from(("TOP", n) for n in list(transit) if transit.in_degree(n) == 0) # one virtual rootidom = nx.immediate_dominators(transit, "TOP")
Each bar counts the networks that reach the top only through that one, ignoring peering. The same idea works for any supply chain or dependency graph with a root.
5. Aviation: measure which hubs the network can't route around
Passengers care whether a trip is nonstop or one stop. A breadth-first search with cutoff=2 counts the airport pairs within one connection, and removing each hub in turn shows how many pairs it holds together.

reach = lambda G: {s: set(d) - {s} for s, d in nx.all_pairs_shortest_path_length(G, cutoff=2)}without = reach(nx.restricted_view(air, ["DEN"], []))
Atlanta has about as many departures as Denver but matters far less to one-stop trips, because other hubs serve most of its destinations.
What's possible
When you build a NetworkX app with a coding agent, these are the capabilities to name, in plain words:
- Build the graph from tables: nx.from_pandas_edgelist, with create_using=nx.DiGraph when direction matters.
- Flows and bottlenecks: minimum_cut and maximum_flow_value, with a capacity attribute on each edge.
- Groups and hierarchies: ancestors, descendants, dag_longest_path_length and strongly_connected_components.
- Communities: community.leiden_communities (new in 3.7) or community.louvain_communities.
- Single points of failure: immediate_dominators from a root, and articulation_points in undirected graphs.
- Paths and reach: shortest_path, all_pairs_shortest_path_length with a cutoff, and restricted_view to hide nodes without copying the graph.
- Importance: pagerank and betweenness_centrality.
Other apps you can build with NetworkX
- Grid contingency screen: take out lines one at a time and rerun minimum_cut between regions.
- Know-your-customer (KYC) ownership explorer: search an LEI and draw its group with ancestors and a tree layout.
- Target discovery browser: pick a gene and show its Leiden module and the nearest drug targets by shortest_path.
- Supplier risk map: a dominator tree over a supply chain to find the suppliers with no alternative.
- Pipeline or water network planner: maximum flow between sources and demand points as valves close.
- Route network planner: reach within one or two connections as routes are added or dropped.
What's new in NetworkX 3.7
Version 3.7 came 10 months after 3.6, with 273 commits from 73 contributors. These are the changes most people will notice:
- Leiden community detection with leiden_communities and leiden_partitions. In 3.6 it existed only as an API for other backends.
- Subgraph matching with VF2++, such as vf2pp_subgraph_is_isomorphic and vf2pp_is_monomorphic, and ISMAGS for directed graphs and multigraphs.
- New functions including antichain_width, random_walk and centroid.
- Speedups in strongly connected components (a rewritten Tarjan algorithm), Edmonds-Karp flows and path reconstruction. In our tests, strongly connected components ran 40% faster.
- pygraphviz wheels that include Graphviz, so graphviz_layout works after a pip install. We used it for the ownership tree.
Before you upgrade, note that 3.7 needs Python 3.12, maximal_independent_set returns a set instead of a list, and Louvain's code was reworked, so the same seed can give slightly different communities than on 3.6. The release notes list everything else.
Demo App: Stress Test
We built a Dash app called Stress Test that takes parts out of two of these networks and recomputes what's left in a callback.

The Grid tab finds the minimum cut between any two groups of countries and lists the links in it. Clicking a pink link takes it out of service and recomputes the cut, which is the question a planner asks about an outage.

Between France and Germany, many of the links in the cut aren't on the border at all, because power can also flow around through neighboring countries.

The Airports tab closes any set of airports and lists the ones that lose the most. Without Denver, small airports from Cody, Wyoming, to Hays, Kansas, lose every one-stop destination, because Denver is their only regular route.
Running NetworkX on Plotly Cloud and Dash Enterprise
What we learned deploying Stress Test applies the same way on Dash Enterprise:
- Build graphs once, at startup. Both networks load from a small Parquet file when the app starts, so callbacks only run algorithms.
- Copy before you change a graph. Each cut works on a copy with outages removed, so two people using the app never see each other's edits.
- Use views to close nodes. nx.restricted_view hides airports without copying the graph, so the recount stays fast.
- Draw edges as one trace. All 9,011 grid links are one Scattergeo trace with None between segments.
If you want the network on a real map with borders and regions, our geopandas demo covers the spatial side.
Prompts to build it yourself
The five charts:
Prompt: With networkx 3.7 and Plotly, using public data: (1) PyPSA-Eur OSM grid, minimum_cut from Spain+Portugal to France and six more borders; (2) GLEIF direct-parent DiGraph, strongly connected components, groups by ancestors, ultimate-parent check; (3) STRING v12 human links score 900+, leiden_communities (modularity, resolution 10) on integer labels; (4) CAIDA provider->customer DiGraph, immediate_dominators from a virtual root; (5) BTS August 2026 routes flown 8+ times, one-stop pairs with each hub removed in turn.
The Stress Test app:
Prompt: Build a Dash app called Stress Test. Grid tab: two country pickers, minimum_cut live, the cut in pink on a Scattergeo map, click a cut link to take it out and recompute. Airports tab: close airports, recompute one-stop pairs live, list who loses the most. Inter, light theme, Plotly purple.