networkx

NetworkX

NetworkX (NX) is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

https://networkx.lanl.gov/

Using

Just write in Python

>>> import networkx as nx
>>> G=nx.Graph()
>>> G.add_edge(1,2)
>>> G.add_node(42)
>>> print(sorted(G.nodes()))
[1, 2, 42]
>>> print(sorted(G.edges()))
[(1, 2)]

Functions

LCF_graph(n, shift_list, repeats[, create_using]) Return the cubic graph specified in LCF notation.
LFR_benchmark_graph(n, tau1, tau2, mu[, ...]) Returns the LFR benchmark graph for testing community-finding algorithms.
adamic_adar_index(G[, ebunch]) Compute the Adamic-Adar index of all node pairs in ebunch.
add_cycle(G, nodes, **attr) Add a cycle to the Graph G.
add_path(G, nodes, **attr) Add a path to the Graph G.
add_star(G, nodes, **attr) Add a star to Graph G.
adj_matrix(G[, nodelist, weight]) Return adjacency matrix of G.
adjacency_data(G[, attrs]) Return data in adjacency format that is suitable for JSON serialization and use in Javascript documents.
adjacency_graph(data[, directed, ...]) Return graph from adjacency data format.
adjacency_matrix(G[, nodelist, weight]) Return adjacency matrix of G.
adjacency_spectrum(G[, weight]) Return eigenvalues of the adjacency matrix of G.
algebraic_connectivity(G[, weight, ...]) Return the algebraic connectivity of an undirected graph.
all_neighbors(graph, node) Returns all of the neighbors of a node in the graph.
all_node_cuts(G[, k, flow_func]) Returns all minimum k cutsets of an undirected graph G.
all_pairs_bellman_ford_path(G[, cutoff, weight]) Compute shortest paths between all nodes in a weighted graph.
all_pairs_bellman_ford_path_length(G[, ...]) Compute shortest path lengths between all nodes in a weighted graph.
all_pairs_dijkstra_path(G[, cutoff, weight]) Compute shortest paths between all nodes in a weighted graph.
all_pairs_dijkstra_path_length(G[, cutoff, ...]) Compute shortest path lengths between all nodes in a weighted graph.
all_pairs_node_connectivity(G[, nbunch, ...]) Compute node connectivity between all pairs of nodes of G.
all_pairs_shortest_path(G[, cutoff]) Compute shortest paths between all nodes.
all_pairs_shortest_path_length(G[, cutoff]) Computes the shortest path lengths between all nodes in G.
all_shortest_paths(G, source, target[, weight]) Compute all shortest paths in the graph.
all_simple_paths(G, source, target[, cutoff]) Generate all simple paths in the graph G from source to target.
ancestors(G, source) Return all nodes having a path to source in G.
antichains(G) Generates antichains from a DAG.
approximate_current_flow_betweenness_centrality(G) Compute the approximate current-flow betweenness centrality for nodes.
articulation_points(G) Return a generator of articulation points, or cut vertices, of a graph.
astar_path(G, source, target[, heuristic, ...]) Return a list of nodes in a shortest path between source and target using the A* (“A-star”) algorithm.
astar_path_length(G, source, target[, ...]) Return the length of the shortest path between source and target using the A* (“A-star”) algorithm.
asyn_lpa_communities(G[, weight]) Returns communities in G as detected by asynchronous label propagation.
attr_matrix(G[, edge_attr, node_attr, ...]) Returns a NumPy matrix using attributes from G.
attr_sparse_matrix(G[, edge_attr, ...]) Returns a SciPy sparse matrix using attributes from G.
attracting_component_subgraphs(G[, copy]) Generates a list of attracting component subgraphs from G.
attracting_components(G) Generates a list of attracting components in G.
attribute_assortativity_coefficient(G, attribute) Compute assortativity for node attributes.
attribute_mixing_dict(G, attribute[, nodes, ...]) Return dictionary representation of mixing matrix for attribute.
attribute_mixing_matrix(G, attribute[, ...]) Return mixing matrix for attribute.
authority_matrix(G[, nodelist]) Return the HITS authority matrix.
average_clustering(G[, nodes, weight, ...]) Compute the average clustering coefficient for the graph G.
average_degree_connectivity(G[, source, ...]) Compute the average degree connectivity of graph.
average_neighbor_degree(G[, source, target, ...]) Returns the average degree of the neighborhood of each node.
average_node_connectivity(G[, flow_func]) Returns the average connectivity of a graph G.
average_shortest_path_length(G[, weight]) Return the average shortest path length.
balanced_tree(r, h[, create_using]) Return the perfectly balanced r-ary tree of height h.
barabasi_albert_graph(n, m[, seed]) Returns a random graph according to the Barabási–Albert preferential attachment model.
barbell_graph(m1, m2[, create_using]) Return the Barbell Graph: two complete graphs connected by a path.
bellman_ford(G, source[, weight]) DEPRECATED: Has been replaced by function bellman_ford_predecessor_and_distance().
bellman_ford_path(G, source, target[, weight]) Returns the shortest path from source to target in a weighted graph G.
bellman_ford_path_length(G, source, target) Returns the shortest path length from source to target in a weighted graph.
bellman_ford_predecessor_and_distance(G, source) Compute shortest path lengths and predecessors on shortest paths in weighted graphs.
betweenness_centrality(G[, k, normalized, ...]) Compute the shortest-path betweenness centrality for nodes.
betweenness_centrality_source(G[, ...])
betweenness_centrality_subset(G, sources, ...) Compute betweenness centrality for a subset of nodes.
bfs_edges(G, source[, reverse]) Produce edges in a breadth-first-search starting at source.
bfs_predecessors(G, source) Returns an iterator of predecessors in breadth-first-search from source.
bfs_successors(G, source) Returns an iterator of successors in breadth-first-search from source.
bfs_tree(G, source[, reverse]) Return an oriented tree constructed from of a breadth-first-search starting at source.
biconnected_component_edges(G) Return a generator of lists of edges, one list for each biconnected component of the input graph.
biconnected_component_subgraphs(G[, copy]) Return a generator of graphs, one graph for each biconnected component of the input graph.
biconnected_components(G) Return a generator of sets of nodes, one set for each biconnected
bidirectional_dijkstra(G, source, target[, ...]) Dijkstra’s algorithm for shortest paths using bidirectional search.
bidirectional_shortest_path(G, source, target) Return a list of nodes in a shortest path between source and target.
binomial_graph(n, p[, seed, directed]) Returns a G_{n,p} random graph, also known as an Erdős-Rényi graph or a binomial graph.
blockmodel(G, partition[, multigraph]) Returns a reduced graph constructed using the generalized block modeling technique.
boundary_expansion(G, S) Returns the boundary expansion of the set S.
bull_graph([create_using]) Return the Bull graph.
capacity_scaling(G[, demand, capacity, ...]) Find a minimum cost flow satisfying all demands in digraph G.
cartesian_product(G, H) Return the Cartesian product of G and H.
caveman_graph(l, k) Returns a caveman graph of l cliques of size k.
center(G[, e]) Return the center of the graph G.
chordal_cycle_graph(p[, create_using]) Return the chordal cycle graph on p nodes.
chordal_graph_cliques(G) Returns the set of maximal cliques of a chordal graph.
chordal_graph_treewidth(G) Returns the treewidth of the chordal graph G.
chvatal_graph([create_using]) Return the Chvátal graph.
circulant_graph(n, offsets[, create_using]) Generates the circulant graph Ci_n(x_1, x_2, ..., x_m) with n vertices.
circular_ladder_graph(n[, create_using]) Return the circular ladder graph CL_n of length n.
circular_layout(G[, scale, center, dim]) Position nodes on a circle.
cliques_containing_node(G[, nodes, cliques]) Returns a list of cliques containing the given node.
closeness_centrality(G[, u, distance, ...]) Compute closeness centrality for nodes.
closeness_vitality(G[, node, weight, ...]) Returns the closeness vitality for nodes in the graph.
clustering(G[, nodes, weight]) Compute the clustering coefficient for nodes.
cn_soundarajan_hopcroft(G[, ebunch, community]) Count the number of common neighbors of all node pairs in ebunch using community information.
common_neighbors(G, u, v) Return the common neighbors of two nodes in a graph.
communicability(G) Return communicability between all pairs of nodes in G.
communicability_betweenness_centrality(G[, ...]) Return subgraph communicability for all pairs of nodes in G.
communicability_exp(G) Return communicability between all pairs of nodes in G.
complement(G[, name]) Return the graph complement of G.
complete_bipartite_graph(n1, n2[, create_using]) Return the complete bipartite graph K_{n_1,n_2}.
complete_graph(n[, create_using]) Return the complete graph K_n with n nodes.
complete_multipartite_graph(*block_sizes) Returns the complete multipartite graph with the specified block sizes.
compose(G, H[, name]) Return a new graph of G composed with H.
compose_all(graphs[, name]) Return the composition of all graphs.
condensation(G[, scc]) Returns the condensation of G.
conductance(G, S[, T, weight]) Returns the conductance of two sets of nodes.
configuration_model(deg_sequence[, ...]) Return a random graph with the given degree sequence.
connected_caveman_graph(l, k) Returns a connected caveman graph of l cliques of size k.
connected_component_subgraphs(G[, copy]) Generate connected components as subgraphs.
connected_components(G) Generate connected components.
connected_double_edge_swap(G[, nswap, ...]) Attempts the specified number of double-edge swaps in the graph G.
connected_watts_strogatz_graph(n, k, p[, ...]) Returns a connected Watts–Strogatz small-world graph.
contracted_edge(G, edge[, self_loops]) Returns the graph that results from contracting the specified edge.
contracted_nodes(G, u, v[, self_loops]) Returns the graph that results from contracting u and v.
convert_node_labels_to_integers(G[, ...]) Return a copy of the graph G with the nodes relabeled using consecutive integers.
core_number(G) Return the core number for each vertex.
cost_of_flow(G, flowDict[, weight]) Compute the cost of the flow given by flowDict on graph G.
could_be_isomorphic(G1, G2) Returns False if graphs are definitely not isomorphic.
coverage(*args, **kw) Returns the coverage of a partition.
create_empty_copy(G[, with_data]) Return a copy of the graph G with all of the edges removed.
cubical_graph([create_using]) Return the 3-regular Platonic Cubical graph.
current_flow_betweenness_centrality(G[, ...]) Compute current-flow betweenness centrality for nodes.
current_flow_betweenness_centrality_subset(G, ...) Compute current-flow betweenness centrality for subsets of nodes.
current_flow_closeness_centrality(G[, ...]) Compute current-flow closeness centrality for nodes.
cut_size(G, S[, T, weight]) Returns the size of the cut between two sets of nodes.
cycle_basis(G[, root]) Returns a list of cycles which form a basis for cycles of G.
cycle_graph(n[, create_using]) Return the cycle graph C_n of cyclicly connected nodes.
dag_longest_path(G[, weight, default_weight]) Returns the longest path in a DAG If G has edges with ‘weight’ attribute the edge data are used as weight values.
dag_longest_path_length(G) Returns the longest path length in a DAG
davis_southern_women_graph() Return Davis Southern women social network.
degree(G[, nbunch, weight]) Return degree of single node or of nbunch of nodes.
degree_assortativity_coefficient(G[, x, y, ...]) Compute degree assortativity of graph.
degree_centrality(G) Compute the degree centrality for nodes.
degree_histogram(G) Return a list of the frequency of each degree value.
degree_mixing_dict(G[, x, y, weight, nodes, ...]) Return dictionary representation of mixing matrix for degree.
degree_mixing_matrix(G[, x, y, weight, ...]) Return mixing matrix for attribute.
degree_pearson_correlation_coefficient(G[, ...]) Compute degree assortativity of graph.
degree_sequence_tree(deg_sequence[, ...]) Make a tree for the given degree sequence.
dense_gnm_random_graph(n, m[, seed]) Returns a G_{n,m} random graph.
density(G) Return the density of a graph.
desargues_graph([create_using]) Return the Desargues graph.
descendants(G, source) Return all nodes reachable from source in G.
dfs_edges(G[, source]) Produce edges in a depth-first-search (DFS).
dfs_labeled_edges(G[, source]) Produce edges in a depth-first-search (DFS) labeled by type.
dfs_postorder_nodes(G[, source]) Produce nodes in a depth-first-search post-ordering starting from source.
dfs_predecessors(G[, source]) Return dictionary of predecessors in depth-first-search from source.
dfs_preorder_nodes(G[, source]) Produce nodes in a depth-first-search pre-ordering starting from source.
dfs_successors(G[, source]) Return dictionary of successors in depth-first-search from source.
dfs_tree(G, source) Return oriented tree constructed from a depth-first-search from source.
diameter(G[, e]) Return the diameter of the graph G.
diamond_graph([create_using]) Return the Diamond graph.
difference(G, H) Return a new graph that contains the edges that exist in G but not in H.
dijkstra_path(G, source, target[, weight]) Returns the shortest weighted path from source to target in G.
dijkstra_path_length(G, source, target[, weight]) Returns the shortest weighted path length in G from source to target.
dijkstra_predecessor_and_distance(G, source) Compute weighted shortest path length and predecessors.
directed_configuration_model(...[, ...]) Return a directed_random graph with the given degree sequences.
directed_havel_hakimi_graph(in_deg_sequence, ...) Return a directed graph with the given degree sequences.
directed_laplacian_matrix(G[, nodelist, ...]) Return the directed Laplacian matrix of G.
directed_modularity_matrix(G[, nodelist, weight]) Return the directed modularity matrix of G.
disjoint_union(G, H) Return the disjoint union of graphs G and H.
disjoint_union_all(graphs) Return the disjoint union of all graphs.
dispersion(G[, u, v, normalized, alpha, b, c]) Calculate dispersion between u and v in G.
dodecahedral_graph([create_using]) Return the Platonic Dodecahedral graph.
dominance_frontiers(G, start) Returns the dominance frontiers of all nodes of a directed graph.
dominating_set(G[, start_with]) Finds a dominating set for the graph G.
dorogovtsev_goltsev_mendes_graph(n[, ...]) Return the hierarchically constructed Dorogovtsev-Goltsev-Mendes graph.
double_edge_swap(G[, nswap, max_tries]) Swap two edges in the graph while keeping the node degrees fixed.
draw(G[, pos, ax, hold]) Draw the graph G with Matplotlib.
draw_circular(G, **kwargs) Draw the graph G with a circular layout.
draw_networkx(G[, pos, arrows, with_labels]) Draw the graph G using Matplotlib.
draw_networkx_edge_labels(G, pos[, ...]) Draw edge labels.
draw_networkx_edges(G, pos[, edgelist, ...]) Draw the edges of the graph G.
draw_networkx_labels(G, pos[, labels, ...]) Draw node labels on the graph G.
draw_networkx_nodes(G, pos[, nodelist, ...]) Draw the nodes of the graph G.
draw_random(G, **kwargs) Draw the graph G with a random layout.
draw_shell(G, **kwargs) Draw networkx graph with shell layout.
draw_spectral(G, **kwargs) Draw the graph G with a spectral layout.
draw_spring(G, **kwargs) Draw the graph G with a spring layout.
duplication_divergence_graph(n, p[, seed]) Returns an undirected graph using the duplication-divergence model.
eccentricity(G[, v, sp]) Return the eccentricity of nodes in G.
edge_betweenness(G[, k, normalized, weight, ...])
edge_betweenness_centrality(G[, k, ...]) Compute betweenness centrality for edges.
edge_betweenness_centrality_subset(G, ...[, ...]) Compute betweenness centrality for edges for a subset of nodes.
edge_boundary(G, nbunch1[, nbunch2, data, ...]) Returns the edge boundary of nbunch1.
edge_connectivity(G[, s, t, flow_func]) Returns the edge connectivity of the graph or digraph G.
edge_current_flow_betweenness_centrality(G) Compute current-flow betweenness centrality for edges.
edge_current_flow_betweenness_centrality_subset(G, ...) Compute current-flow betweenness centrality for edges using subsets of nodes.
edge_dfs(G[, source, orientation]) A directed, depth-first traversal of edges in G, beginning at source.
edge_expansion(G, S[, T, weight]) Returns the edge expansion between two node sets.
edge_load_centrality(G[, cutoff]) Compute edge load.
edges(G[, nbunch]) Return iterator over edges incident to nodes in nbunch.
efficiency(G, u, v) Returns the efficiency of a pair of nodes in a graph.
ego_graph(G, n[, radius, center, ...]) Returns induced subgraph of neighbors centered at node n within a given radius.
eigenvector_centrality(G[, max_iter, tol, ...]) Compute the eigenvector centrality for the graph G.
eigenvector_centrality_numpy(G[, weight, ...]) Compute the eigenvector centrality for the graph G.
empty_graph([n, create_using]) Return the empty graph with n nodes and zero edges.
enumerate_all_cliques(G) Returns all cliques in an undirected graph.
erdos_renyi_graph(n, p[, seed, directed]) Returns a G_{n,p} random graph, also known as an Erdős-Rényi graph or a binomial graph.
estrada_index(G) Return the Estrada index of a the graph G.
eulerian_circuit(G[, source]) Returns an iterator over the edges of an Eulerian circuit in G.
expected_degree_graph(w[, seed, selfloops]) Return a random graph with given expected degrees.
fast_could_be_isomorphic(G1, G2) Returns False if graphs are definitely not isomorphic.
fast_gnp_random_graph(n, p[, seed, directed]) Returns a G_{n,p} random graph, also known as an Erdős-Rényi graph or a binomial graph.
faster_could_be_isomorphic(G1, G2) Returns False if graphs are definitely not isomorphic.
fiedler_vector(G[, weight, normalized, tol, ...]) Return the Fiedler vector of a connected undirected graph.
find_cliques(G) Returns all maximal cliques in an undirected graph.
find_cliques_recursive(G) Returns all maximal cliques in a graph.
find_cores(G) Return the core number for each vertex.
find_cycle(G[, source, orientation]) Returns the edges of a cycle found via a directed, depth-first traversal.
find_induced_nodes(G, s, t[, treewidth_bound]) Returns the set of induced nodes in the path from s to t.
florentine_families_graph() Return Florentine families graph.
flow_hierarchy(G[, weight]) Returns the flow hierarchy of a directed network.
floyd_warshall(G[, weight]) Find all-pairs shortest path lengths using Floyd’s algorithm.
floyd_warshall_numpy(G[, nodelist, weight]) Find all-pairs shortest path lengths using Floyd’s algorithm.
floyd_warshall_predecessor_and_distance(G[, ...]) Find all-pairs shortest path lengths using Floyd’s algorithm.
freeze(G) Modify graph to prevent further change by adding or removing nodes or edges.
from_dict_of_dicts(d[, create_using, ...]) Return a graph from a dictionary of dictionaries.
from_dict_of_lists(d[, create_using]) Return a graph from a dictionary of lists.
from_edgelist(edgelist[, create_using]) Return a graph from a list of edges.
from_numpy_matrix(A[, parallel_edges, ...]) Return a graph from numpy matrix.
from_pandas_dataframe(df, source, target[, ...]) Return a graph from Pandas DataFrame.
from_scipy_sparse_matrix(A[, ...]) Creates a new graph from an adjacency matrix given as a SciPy sparse matrix.
frucht_graph([create_using]) Return the Frucht Graph.
fruchterman_reingold_layout(G[, k, pos, ...]) Position nodes using Fruchterman-Reingold force-directed algorithm.
full_rary_tree(r, n[, create_using]) Creates a full r-ary tree of n vertices.
gaussian_random_partition_graph(n, s, v, ...) Generate a Gaussian random partition graph.
general_random_intersection_graph(n, m, p) Return a random intersection graph with independent probabilities for connections between node and attribute sets.
generate_adjlist(G[, delimiter]) Generate a single line of the graph G in adjacency list format.
generate_edgelist(G[, delimiter, data]) Generate a single line of the graph G in edge list format.
generate_gexf(G[, encoding, prettyprint, ...]) Generate lines of GEXF format representation of G.
generate_gml(G[, stringizer]) Generate a single entry of the graph G in GML format.
generate_graph6(G[, nodes, header]) Generate graph6 format string from a simple undirected graph.
generate_graphml(G[, encoding, prettyprint]) Generate GraphML lines for G
generate_multiline_adjlist(G[, delimiter]) Generate a single line of the graph G in multiline adjacency list format.
generate_pajek(G) Generate lines in Pajek graph format.
generate_sparse6(G[, nodes, header]) Generate sparse6 format string from an undirected graph.
geographical_threshold_graph(n, theta[, ...]) Returns a geographical threshold graph.
get_edge_attributes(G, name) Get edge attributes from graph
get_node_attributes(G, name) Get node attributes from graph
girvan_newman(G[, most_valuable_edge]) Finds communities in a graph using the Girvan–Newman method.
global_efficiency(G) Returns the average global efficiency of the graph.
global_parameters(b, c) Return global parameters for a given intersection array.
global_reaching_centrality(G[, weight, ...]) Returns the global reaching centrality of a directed graph.
gn_graph(n[, kernel, create_using, seed]) Return the growing network (GN) digraph with n nodes.
gnc_graph(n[, create_using, seed]) Return the growing network with copying (GNC) digraph with n nodes.
gnm_random_graph(n, m[, seed, directed]) Returns a G_{n,m} random graph.
gnp_random_graph(n, p[, seed, directed]) Returns a G_{n,p} random graph, also known as an Erdős-Rényi graph or a binomial graph.
gnr_graph(n, p[, create_using, seed]) Return the growing network with redirection (GNR) digraph with n nodes and redirection probability p.
goldberg_radzik(G, source[, weight]) Compute shortest path lengths and predecessors on shortest paths in weighted graphs.
google_matrix(G[, alpha, personalization, ...]) Return the Google matrix of the graph.
graph_clique_number(G[, cliques]) Returns the clique number of the graph.
graph_number_of_cliques(G[, cliques]) Returns the number of maximal cliques in the graph.
greedy_color(G[, strategy, interchange]) Color a graph using various strategies of greedy graph coloring.
grid_2d_graph(m, n[, periodic, create_using]) Return the 2d grid graph of mxn nodes
grid_graph(dim[, periodic]) Return the n-dimensional grid graph.
harmonic_centrality(G[, distance]) Compute harmonic centrality for nodes.
has_path(G, source, target) Return True if G has a path from source to target.
havel_hakimi_graph(deg_sequence[, create_using]) Return a simple graph with given degree sequence constructed using the Havel-Hakimi algorithm.
heawood_graph([create_using]) Return the Heawood graph, a (3,6) cage.
hits(G[, max_iter, tol, nstart, normalized]) Return HITS hubs and authorities values for nodes.
hits_numpy(G[, normalized]) Return HITS hubs and authorities values for nodes.
hits_scipy(G[, max_iter, tol, normalized]) Return HITS hubs and authorities values for nodes.
house_graph([create_using]) Return the House graph (square with triangle on top).
house_x_graph([create_using]) Return the House graph with a cross inside the house square.
hub_matrix(G[, nodelist]) Return the HITS hub matrix.
hypercube_graph(n) Return the n-dimensional hypercube.
icosahedral_graph([create_using]) Return the Platonic Icosahedral graph.
identified_nodes(G, u, v[, self_loops]) Returns the graph that results from contracting u and v.
immediate_dominators(G, start) Returns the immediate dominators of all nodes of a directed graph.
in_degree_centrality(G) Compute the in-degree centrality for nodes.
incidence_matrix(G[, nodelist, edgelist, ...]) Return incidence matrix of G.
info(G[, n]) Print short summary of information for the graph G or the node n.
information_centrality(G[, weight, dtype, ...]) Compute current-flow closeness centrality for nodes.
intersection(G, H) Return a new graph that contains only the edges that exist in both G and H.
intersection_all(graphs) Return a new graph that contains only the edges that exist in all graphs.
intersection_array(G) Returns the intersection array of a distance-regular graph.
is_aperiodic(G) Return True if G is aperiodic.
is_arborescence(G) Returns True if G is an arborescence.
is_attracting_component(G) Returns True if G consists of a single attracting component.
is_biconnected(G) Return True if the graph is biconnected, False otherwise.
is_bipartite(G) Returns True if graph G is bipartite, False if not.
is_branching(G) Returns True if G is a branching.
is_chordal(G) Checks whether G is a chordal graph.
is_connected(G) Return True if the graph is connected, false otherwise.
is_digraphical(in_sequence, out_sequence) Returns True if some directed graph can realize the in- and out-degree sequences.
is_directed(G) Return True if graph is directed.
is_directed_acyclic_graph(G) Return True if the graph G is a directed acyclic graph (DAG) or False if not.
is_distance_regular(G) Returns True if the graph is distance regular, False otherwise.
is_dominating_set(G, nbunch) Checks if nbunch is a dominating set for G.
is_empty(G) Returns True if G has no edges.
is_eulerian(G) Returns True if and only if G is Eulerian.
is_forest(G) Returns True if G is a forest.
is_frozen(G) Return True if graph is frozen.
is_graphical(sequence[, method]) Returns True if sequence is a valid degree sequence.
is_isolate(G, n) Determines whether a node is an isolate.
is_isomorphic(G1, G2[, node_match, edge_match]) Returns True if the graphs G1 and G2 are isomorphic and False otherwise.
is_kl_connected(G, k, l[, low_memory]) Returns True if and only if G is locally (k, l)-connected.
is_matching(G, matching) Decides whether the given set or dictionary represents a valid matching in G.
is_maximal_matching(G, matching) Decides whether the given set or dictionary represents a valid maximal matching in G.
is_multigraphical(sequence) Returns True if some multigraph can realize the sequence.
is_negatively_weighted(G[, edge, weight]) Returns True if G has negatively weighted edges.
is_pseudographical(sequence) Returns True if some pseudograph can realize the sequence.
is_semiconnected(G) Return True if the graph is semiconnected, False otherwise.
is_simple_path(G, nodes) Returns True if and only if the given nodes form a simple path in G.
is_strongly_connected(G) Test directed graph for strong connectivity.
is_strongly_regular(G) Returns True if and only if the given graph is strongly regular.
is_tree(G) Returns True if G is a tree.
is_valid_degree_sequence(sequence[, method]) Returns True if sequence is a valid degree sequence.
is_valid_degree_sequence_erdos_gallai(...) Returns True if deg_sequence can be realized by a simple graph.
is_valid_degree_sequence_havel_hakimi(...) Returns True if deg_sequence can be realized by a simple graph.
is_valid_joint_degree(joint_degrees) Checks whether the given joint degree dictionary is realizable as a simple graph.
is_weakly_connected(G) Test directed graph for weak connectivity.
is_weighted(G[, edge, weight]) Returns True if G has weighted edges.
isolates(G) Iterator over isolates in the graph.
jaccard_coefficient(G[, ebunch]) Compute the Jaccard coefficient of all node pairs in ebunch.
jit_data(G[, indent]) Return data in JIT JSON format.
jit_graph(data) Read a graph from JIT JSON.
johnson(G[, weight]) Uses Johnson’s Algorithm to compute shortest paths.
joint_degree_graph(joint_degrees[, seed]) Generates a random simple graph with the given joint degree dictionary.
k_clique_communities(G, k[, cliques]) Find k-clique communities in graph using the percolation method.
k_components(G[, flow_func]) Returns the k-component structure of a graph G.
k_core(G[, k, core_number]) Return the k-core of G.
k_corona(G, k[, core_number]) Return the k-corona of G.
k_crust(G[, k, core_number]) Return the k-crust of G.
k_nearest_neighbors(G[, source, target, ...]) Compute the average degree connectivity of graph.
k_random_intersection_graph(n, m, k) Return a intersection graph with randomly chosen attribute sets for each node that are of equal size (k).
k_shell(G[, k, core_number]) Return the k-shell of G.
karate_club_graph() Return Zachary’s Karate Club graph.
katz_centrality(G[, alpha, beta, max_iter, ...]) Compute the Katz centrality for the nodes of the graph G.
katz_centrality_numpy(G[, alpha, beta, ...]) Compute the Katz centrality for the graph G.
kernighan_lin_bisection(G[, partition, ...]) Partition a graph into two blocks using the Kernighan–Lin algorithm.
kl_connected_subgraph(G, k, l[, low_memory, ...]) Returns the maximum locally (k, l)-connected subgraph of G.
kosaraju_strongly_connected_components(G[, ...]) Generate nodes in strongly connected components of graph.
krackhardt_kite_graph([create_using]) Return the Krackhardt Kite Social Network.
ladder_graph(n[, create_using]) Return the Ladder graph of length n.
laplacian_matrix(G[, nodelist, weight]) Return the Laplacian matrix of G.
laplacian_spectrum(G[, weight]) Return eigenvalues of the Laplacian of G
lexicographic_product(G, H) Return the lexicographic product of G and H.
lexicographical_topological_sort(G[, key]) Return a generator of nodes in lexicographically topologically sorted order.
line_graph(G[, create_using]) Returns the line graph of the graph or digraph G.
load_centrality(G[, v, cutoff, normalized, ...]) Compute load centrality for nodes.
local_efficiency(G) Returns the average local efficiency of the graph.
local_reaching_centrality(G, v[, paths, ...]) Returns the local reaching centrality of a node in a directed graph.
lollipop_graph(m, n[, create_using]) Return the Lollipop Graph; K_m connected to P_n.
make_clique_bipartite(G[, fpos, ...]) Returns the bipartite clique graph corresponding to G.
make_max_clique_graph(G[, create_using]) Returns the maximal clique graph of the given graph.
make_small_graph(graph_description[, ...]) Return the small graph described by graph_description.
margulis_gabber_galil_graph(n[, create_using]) Return the Margulis-Gabber-Galil undirected MultiGraph on n^2 nodes.
max_flow_min_cost(G, s, t[, capacity, weight]) Return a maximum (s, t)-flow of minimum cost.
max_weight_matching(G[, maxcardinality, weight]) Compute a maximum-weighted matching of G.
maximal_independent_set(G[, nodes]) Return a random maximal independent set guaranteed to contain a given set of nodes.
maximal_matching(G) Find a maximal cardinality matching in the graph.
maximum_branching(G[, attr, default]) Returns a maximum branching from G.
maximum_flow(G, s, t[, capacity, flow_func]) Find a maximum single-commodity flow.
maximum_flow_value(G, s, t[, capacity, ...]) Find the value of maximum single-commodity flow.
maximum_spanning_arborescence(G[, attr, default]) Returns a maximum spanning arborescence from G.
maximum_spanning_edges(G[, algorithm, ...]) Generate edges in a maximum spanning forest of an undirected weighted graph.
maximum_spanning_tree(G[, weight, algorithm]) Returns a maximum spanning tree or forest on an undirected graph G.
min_cost_flow(G[, demand, capacity, weight]) Return a minimum cost flow satisfying all demands in digraph G.
min_cost_flow_cost(G[, demand, capacity, weight]) Find the cost of a minimum cost flow satisfying all demands in digraph G.
minimum_branching(G[, attr, default]) Returns a minimum branching from G.
minimum_cut(G, s, t[, capacity, flow_func]) Compute the value and the node partition of a minimum (s, t)-cut.
minimum_cut_value(G, s, t[, capacity, flow_func]) Compute the value of a minimum (s, t)-cut.
minimum_edge_cut(G[, s, t, flow_func]) Returns a set of edges of minimum cardinality that disconnects G.
minimum_node_cut(G[, s, t, flow_func]) Returns a set of nodes of minimum cardinality that disconnects G.
minimum_spanning_arborescence(G[, attr, default]) Returns a minimum spanning arborescence from G.
minimum_spanning_edges(G[, algorithm, ...]) Generate edges in a minimum spanning forest of an undirected weighted graph.
minimum_spanning_tree(G[, weight, algorithm]) Returns a minimum spanning tree or forest on an undirected graph G.
mixing_dict(xy[, normalized]) Return a dictionary representation of mixing matrix.
mixing_expansion(G, S[, T, weight]) Returns the mixing expansion between two node sets.
modularity_matrix(G[, nodelist, weight]) Return the modularity matrix of G.
modularity_spectrum(G) Return eigenvalues of the modularity matrix of G.
moebius_kantor_graph([create_using]) Return the Moebius-Kantor graph.
multi_source_dijkstra(G, sources[, target, ...]) Find shortest weighted paths and lengths from a given set of source nodes.
multi_source_dijkstra_path(G, sources[, ...]) Find shortest weighted paths in G from a given set of source nodes.
multi_source_dijkstra_path_length(G, sources) Find shortest weighted path lengths in G from a given set of source nodes.
navigable_small_world_graph(n[, p, q, r, ...]) Return a navigable small-world graph.
negative_edge_cycle(G[, weight]) Return True if there exists a negative edge cycle anywhere in G.
neighbors(G, n) Return a list of nodes connected to node n.
network_simplex(G[, demand, capacity, weight]) Find a minimum cost flow satisfying all demands in digraph G.
newman_watts_strogatz_graph(n, k, p[, seed]) Return a Newman–Watts–Strogatz small-world graph.
node_attribute_xy(G, attribute[, nodes]) Return iterator of node-attribute pairs for all edges in G.
node_boundary(G, nbunch1[, nbunch2]) Returns the node boundary of nbunch1.
node_clique_number(G[, nodes, cliques]) Returns the size of the largest maximal clique containing each given node.
node_connected_component(G, n) Return the nodes in the component of graph containing node n.
node_connectivity(G[, s, t, flow_func]) Returns node connectivity for a graph or digraph G.
node_degree_xy(G[, x, y, weight, nodes]) Generate node degree-degree pairs for edges in G.
node_expansion(G, S) Returns the node expansion of the set S.
node_link_data(G[, attrs]) Return data in node-link format that is suitable for JSON serialization and use in Javascript documents.
node_link_graph(data[, directed, ...]) Return graph from node-link data format.
nodes(G) Return an iterator over the graph nodes.
non_edges(graph) Returns the non-existent edges in the graph.
non_neighbors(graph, node) Returns the non-neighbors of the node in the graph.
nonisomorphic_trees(order[, create]) Returns a list of nonisomporphic trees
normalized_cut_size(G, S[, T, weight]) Returns the normalized size of the cut between two sets of nodes.
normalized_laplacian_matrix(G[, nodelist, ...]) Return the normalized Laplacian matrix of G.
null_graph([create_using]) Return the Null graph with no nodes or edges.
number_attracting_components(G) Returns the number of attracting components in G.
number_connected_components(G) Return the number of connected components.
number_of_cliques(G[, nodes, cliques]) Returns the number of maximal cliques for each node.
number_of_edges(G) Return the number of edges in the graph.
number_of_isolates(G) Returns the number of isolates in the graph.
number_of_nodes(G) Return the number of nodes in the graph.
number_of_nonisomorphic_trees(order) Returns the number of nonisomorphic trees
number_strongly_connected_components(G) Return number of strongly connected components in graph.
number_weakly_connected_components(G) Return the number of weakly connected components in G.
numeric_assortativity_coefficient(G, attribute) Compute assortativity for numerical node attributes.
numeric_mixing_matrix(G, attribute[, nodes, ...]) Return numeric mixing matrix for attribute.
octahedral_graph([create_using]) Return the Platonic Octahedral graph.
out_degree_centrality(G) Compute the out-degree centrality for nodes.
overall_reciprocity(G) Compute the reciprocity for the whole graph.
pagerank(G[, alpha, personalization, ...]) Return the PageRank of the nodes in the graph.
pagerank_numpy(G[, alpha, personalization, ...]) Return the PageRank of the nodes in the graph.
pagerank_scipy(G[, alpha, personalization, ...]) Return the PageRank of the nodes in the graph.
pappus_graph() Return the Pappus graph.
parse_adjlist(lines[, comments, delimiter, ...]) Parse lines of a graph adjacency list representation.
parse_edgelist(lines[, comments, delimiter, ...]) Parse lines of an edge list representation of a graph.
parse_gml(lines[, label, destringizer]) Parse GML graph from a string or iterable.
parse_graph6(string) Read a simple undirected graph in graph6 format from string.
parse_graphml(graphml_string[, node_type]) Read graph in GraphML format from string.
parse_leda(lines) Read graph in LEDA format from string or iterable.
parse_multiline_adjlist(lines[, comments, ...]) Parse lines of a multiline adjacency list representation of a graph.
parse_pajek(lines) Parse Pajek format graph from string or iterable.
parse_sparse6(string) Read an undirected graph in sparse6 format from string.
partial_duplication_graph(N, n, p, q[, seed]) Return a random graph using the partial duplication model.
path_graph(n[, create_using]) Return the Path graph P_n of linearly connected nodes.
performance(*args, **kw) Returns the performance of a partition.
periphery(G[, e]) Return the periphery of the graph G.
petersen_graph([create_using]) Return the Petersen graph.
planted_partition_graph(l, k, p_in, p_out[, ...]) Return the planted l-partition graph.
power(G, k) Returns the specified power of a graph.
powerlaw_cluster_graph(n, m, p[, seed]) Holme and Kim algorithm for growing graphs with powerlaw degree distribution and approximate average clustering.
predecessor(G, source[, target, cutoff, ...]) Returns dictionary of predecessors for the path from source to all nodes in G.
preferential_attachment(G[, ebunch]) Compute the preferential attachment score of all node pairs in ebunch.
project(B, nodes[, create_using])
projected_graph(B, nodes[, multigraph]) Returns the projection of B onto one of its node sets.
quotient_graph(G, partition[, ...]) Returns the quotient graph of G under the specified equivalence relation on nodes.
ra_index_soundarajan_hopcroft(G[, ebunch, ...]) Compute the resource allocation index of all node pairs in ebunch using community information.
radius(G[, e]) Return the radius of the graph G.
random_clustered_graph(joint_degree_sequence) Generate a random graph with the given joint independent edge degree and triangle degree sequence.
random_degree_sequence_graph(sequence[, ...]) Return a simple random graph with the given degree sequence.
random_geometric_graph(n, radius[, dim, ...]) Returns a random geometric graph in the unit cube.
random_k_out_graph(n, k, alpha[, ...]) Returns a random k-out graph with preferential attachment.
random_kernel_graph(n, kernel_integral[, ...]) Return an random graph based on the specified kernel.
random_layout(G[, center, dim]) Position nodes uniformly at random in the unit square.
random_lobster(n, p1, p2[, seed]) Returns a random lobster graph.
random_partition_graph(sizes, p_in, p_out[, ...]) Return the random partition graph with a partition of sizes.
random_powerlaw_tree(n[, gamma, seed, tries]) Returns a tree with a power law degree distribution.
random_powerlaw_tree_sequence(n[, gamma, ...]) Returns a degree sequence for a tree with a power law distribution.
random_regular_graph(d, n[, seed]) Returns a random d-regular graph on n nodes.
random_shell_graph(constructor[, seed]) Returns a random shell graph for the constructor given.
read_adjlist(path[, comments, delimiter, ...]) Read graph in adjacency list format from path.
read_edgelist(path[, comments, delimiter, ...]) Read a graph from a list of edges.
read_gexf(path[, node_type, relabel, version]) Read graph in GEXF format from path.
read_gml(path[, label, destringizer]) Read graph in GML format from path.
read_gpickle(path) Read graph object in Python pickle format.
read_graph6(path) Read simple undirected graphs in graph6 format from path.
read_graphml(path[, node_type]) Read graph in GraphML format from path.
read_leda(path[, encoding]) Read graph in LEDA format from path.
read_multiline_adjlist(path[, comments, ...]) Read graph in multi-line adjacency list format from path.
read_pajek(path[, encoding]) Read graph in Pajek format from path.
read_shp(path[, simplify, geom_attrs]) Generates a networkx.DiGraph from shapefiles.
read_sparse6(path) Read an undirected graph in sparse6 format from path.
read_weighted_edgelist(path[, comments, ...]) Read a graph as list of edges with numeric weights.
read_yaml(path) Read graph in YAML format from path.
reciprocity(G[, nodes]) Compute the reciprocity in a directed graph.
recursive_simple_cycles(G) Find simple cycles (elementary circuits) of a directed graph.
relabel_gexf_graph(G) Relabel graph using “label” node keyword for node label.
relabel_nodes(G, mapping[, copy]) Relabel the nodes of the graph G.
relaxed_caveman_graph(l, k, p[, seed]) Return a relaxed caveman graph.
rescale_layout(pos[, scale]) Return scaled position array to (-scale, scale) in all axes.
resource_allocation_index(G[, ebunch]) Compute the resource allocation index of all node pairs in ebunch.
reverse(G[, copy]) Return the reverse directed graph of G.
rich_club_coefficient(G[, normalized, Q]) Returns the rich-club coefficient of the graph G.
ring_of_cliques(num_cliques, clique_size) Defines a “ring of cliques” graph.
s_metric(G[, normalized]) Return the s-metric of graph.
scale_free_graph(n[, alpha, beta, gamma, ...]) Returns a scale-free directed graph.
sedgewick_maze_graph([create_using]) Return a small maze with a cycle.
set_edge_attributes(G, name, values) Sets edge attributes from a given value or dictionary of values.
set_node_attributes(G, name, values) Sets node attributes from a given value or dictionary of values.
shell_layout(G[, nlist, scale, center, dim]) Position nodes in concentric circles.
shortest_path(G[, source, target, weight]) Compute shortest paths in the graph.
shortest_path_length(G[, source, target, weight]) Compute shortest path lengths in the graph.
shortest_simple_paths(G, source, target[, ...]) Generate all simple paths in the graph G from source to target, starting from shortest ones.
simple_cycles(G) Find simple cycles (elementary circuits) of a directed graph.
single_source_bellman_ford(G, source[, ...]) Compute shortest paths and lengths in a weighted graph G.
single_source_bellman_ford_path(G, source[, ...]) Compute shortest path between source and all other reachable nodes for a weighted graph.
single_source_bellman_ford_path_length(G, source) Compute the shortest path length between source and all other reachable nodes for a weighted graph.
single_source_dijkstra(G, source[, target, ...]) Find shortest weighted paths and lengths from a source node.
single_source_dijkstra_path(G, source[, ...]) Find shortest weighted paths in G from a source node.
single_source_dijkstra_path_length(G, source) Find shortest weighted path lengths in G from a source node.
single_source_shortest_path(G, source[, cutoff]) Compute shortest path between source and all other nodes reachable from source.
single_source_shortest_path_length(G, source) Compute the shortest path lengths from source to all reachable nodes.
spectral_layout(G[, weight, scale, center, dim]) Position nodes using the eigenvectors of the graph Laplacian.
spectral_ordering(G[, weight, normalized, ...]) Compute the spectral_ordering of a graph.
spring_layout(G[, k, pos, fixed, ...]) Position nodes using Fruchterman-Reingold force-directed algorithm.
square_clustering(G[, nodes]) Compute the squares clustering coefficient for nodes.
star_graph(n[, create_using]) Return the star graph
stochastic_graph(G[, copy, weight]) Returns a right-stochastic representation of directed graph G.
stoer_wagner(G[, weight, heap]) Returns the weighted minimum edge cut using the Stoer-Wagner algorithm.
strong_product(G, H) Return the strong product of G and H.
strongly_connected_component_subgraphs(G[, copy]) Generate strongly connected components as subgraphs.
strongly_connected_components(G) Generate nodes in strongly connected components of graph.
strongly_connected_components_recursive(G) Generate nodes in strongly connected components of graph.
subgraph(G, nbunch) Return the subgraph induced on nodes in nbunch.
subgraph_centrality(G) Return subgraph centrality for each node in G.
subgraph_centrality_exp(G) Return the subgraph centrality for each node of G.
symmetric_difference(G, H) Return new graph with edges that exist in either G or H but not both.
tensor_product(G, H) Return the tensor product of G and H.
test([verbosity, doctest, numpy]) Run NetworkX tests.
tetrahedral_graph([create_using]) Return the 3-regular Platonic Tetrahedral graph.
to_dict_of_dicts(G[, nodelist, edge_data]) Return adjacency representation of graph as a dictionary of dictionaries.
to_dict_of_lists(G[, nodelist]) Return adjacency representation of graph as a dictionary of lists.
to_edgelist(G[, nodelist]) Return a list of edges in the graph.
to_networkx_graph(data[, create_using, ...]) Make a NetworkX graph from a known data structure.
to_numpy_matrix(G[, nodelist, dtype, order, ...]) Return the graph adjacency matrix as a NumPy matrix.
to_numpy_recarray(G[, nodelist, dtype, order]) Return the graph adjacency matrix as a NumPy recarray.
to_pandas_dataframe(G[, nodelist, dtype, ...]) Return the graph adjacency matrix as a Pandas DataFrame.
to_scipy_sparse_matrix(G[, nodelist, dtype, ...]) Return the graph adjacency matrix as a SciPy sparse matrix.
topological_sort(G) Return a generator of nodes in topologically sorted order.
transitive_closure(G) Returns transitive closure of a directed graph
transitivity(G) Compute graph transitivity, the fraction of all possible triangles present in G.
tree_data(G, root[, attrs]) Return data in tree format that is suitable for JSON serialization and use in Javascript documents.
tree_graph(data[, attrs]) Return graph from tree data format.
triad_graph(triad_name) Returns the triad graph with the given name.
triadic_census(G) Determines the triadic census of a directed graph.
triangles(G[, nodes]) Compute the number of triangles.
trivial_graph([create_using]) Return the Trivial graph with one node (with label 0) and no edges.
truncated_cube_graph([create_using]) Return the skeleton of the truncated cube.
truncated_tetrahedron_graph([create_using]) Return the skeleton of the truncated Platonic tetrahedron.
tutte_graph([create_using]) Return the Tutte graph.
uniform_random_intersection_graph(n, m, p[, ...]) Return a uniform random intersection graph.
union(G, H[, rename, name]) Return the union of graphs G and H.
union_all(graphs[, rename, name]) Return the union of all graphs.
volume(G, S[, weight]) Returns the volume of a set of nodes.
voronoi_cells(G, center_nodes[, weight]) Returns the Voronoi cells centered at center_nodes with respect to the shortest-path distance metric.
watts_strogatz_graph(n, k, p[, seed]) Return a Watts–Strogatz small-world graph.
waxman_graph(n[, alpha, beta, L, domain, metric]) Return a Waxman random graph.
weakly_connected_component_subgraphs(G[, copy]) Generate weakly connected components as subgraphs.
weakly_connected_components(G) Generate weakly connected components of G.
wheel_graph(n[, create_using]) Return the wheel graph
wiener_index(G[, weight]) Returns the Wiener index of the given graph.
within_inter_cluster(G[, ebunch, delta, ...]) Compute the ratio of within- and inter-cluster common neighbors of all node pairs in ebunch.
write_adjlist(G, path[, comments, ...]) Write graph G in single-line adjacency-list format to path.
write_edgelist(G, path[, comments, ...]) Write graph as a list of edges.
write_gexf(G, path[, encoding, prettyprint, ...]) Write G in GEXF format to path.
write_gml(G, path[, stringizer]) Write a graph G in GML format to the file or file handle path.
write_gpickle(G, path[, protocol]) Write graph in Python pickle format.
write_graph6(G, path[, nodes, header]) Write a simple undirected graph to path in graph6 format.
write_graphml(G, path[, encoding, ...]) Write G in GraphML XML format to path
write_multiline_adjlist(G, path[, ...]) Write the graph G in multiline adjacency list format to path
write_pajek(G, path[, encoding]) Write graph in Pajek format to path.
write_shp(G, outdir) Writes a networkx.DiGraph to two shapefiles, edges and nodes.
write_sparse6(G, path[, nodes, header]) Write graph G to given path in sparse6 format.
write_weighted_edgelist(G, path[, comments, ...]) Write graph G as a list of edges with numeric weights.
write_yaml(G, path[, encoding]) Write graph G in YAML format to path.

Classes

DiGraph([data]) Base class for directed graphs.
Graph([data]) Base class for undirected graphs.
GraphMLReader([node_type]) Read a GraphML document.
GraphMLWriter([graph, encoding, ...])
MultiDiGraph([data]) A directed graph class that can store multiedges.
MultiGraph([data]) An undirected graph class that can store multiedges.
OrderedDiGraph([data])
OrderedGraph([data])
OrderedMultiDiGraph([data])
OrderedMultiGraph([data])

Exceptions

NetworkXAlgorithmError Exception for unexpected termination of algorithms.
NetworkXError Exception for a serious error in NetworkX
NetworkXException Base class for exceptions in NetworkX.
NetworkXNoCycle Exception for algorithms that should return a cycle when running on graphs where such a cycle does not exist.
NetworkXNoPath Exception for algorithms that should return a path when running on graphs where such a path does not exist.
NetworkXNotImplemented Exception raised by algorithms not implemented for a type of graph.
NetworkXPointlessConcept Harary, F.
NetworkXTreewidthBoundExceeded Exception raised when a treewidth bound has been provided and it has
NetworkXUnbounded Exception raised by algorithms trying to solve a maximization or a minimization problem instance that is unbounded.
NetworkXUnfeasible Exception raised by algorithms trying to solve a problem instance that has no feasible solution.
NodeNotFound Exception raised if requested node is not present in the graph