networkx
ScienceGraph algorithms
What is networkx?
NetworkX is the standard Python library for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks. It supports undirected graphs, directed graphs (digraphs), and multigraphs, and provides a rich set of algorithms for path finding, centrality, community detection, clustering, and more.
PyRun lets you run NetworkX experiments directly in your browser. Whether you're studying graph theory, modelling a social network, or exploring shortest-path algorithms, NetworkX is available immediately via micropip without any local installation.
Code Example
Build a directed graph and compute shortest paths.
import networkx as nx
G = nx.DiGraph()
G.add_edges_from([
("Alice", "Bob"),
("Alice", "Charlie"),
("Bob", "Diana"),
("Charlie", "Diana"),
("Diana", "Eve"),
])
print("Nodes:", list(G.nodes()))
print("Edges:", list(G.edges()))
print("\nIn-degree (followers):")
for node, deg in G.in_degree():
print(f" {node}: {deg}")
print("\nShortest path Alice → Eve:")
path = nx.shortest_path(G, "Alice", "Eve")
print(" → ".join(path))
print("\nIs DAG?", nx.is_directed_acyclic_graph(G))Why run networkx in PyRun?
- ✦ Zero setup — no pip install, no virtual environment, no Python download
- ✦ Instant results — powered by WebAssembly, runs locally in your browser
- ✦ Share your code — generate a link and anyone can run it instantly
- ✦ Works offline — after first load, PyRun runs without internet
Related Packages
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.