networkx

Create, analyze, and visualize complex networks and graphs in Python with NetworkX. Use when working with network/graph data structures, computing graph algorithms (shortest paths, centrality, clustering), detecting communities, generating synthetic networks (random, scale-free, small-world), reading/writing graph file formats, or drawing network topologies. Common applications include social, biological, transportation, and citation networks.

Install

Hot:5

Download and extract to your skills directory

Copy command and send to AI Agent for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=k-dense-ai-skills-networkx&locale=en&source=copy

NetworkX - Python Library for Complex Network Analysis and Graph Theory

Overview of Skills


NetworkX is a powerful Python library for network analysis that lets you create, manipulate, and analyze complex networks and graph structures. It supports a wide range of applications, from social networks to biological networks.

Use Cases

1. Social Networks and Relationship Analysis


When you need to analyze social media user relationship networks, compute influence metrics, detect communities, or trace spreading paths, NetworkX provides comprehensive graph algorithm support. You can use it to build follower/relationship graphs, compute PageRank rankings, identify key opinion leaders, and detect community structures.

2. Academic and Knowledge Network Analysis


Suitable for academic scenarios such as citation network analysis, paper collaboration network research, and knowledge graph construction. NetworkX can handle citation relationships and author collaboration networks, helping you identify research hotspots and academic influence. It also supports deep analysis by importing data from sources such as Web of Science and DBLP.

3. Infrastructure and Biological Network Modeling


In fields such as transportation network optimization, protein interaction analysis, and neural network research, NetworkX offers a variety of graph generation and analysis tools. You can build transportation route graphs for path planning or analyze functional modules in biological molecular networks, supporting structural analysis and visualization of large-scale networks.

Core Features

1. A Comprehensive Graph Algorithm Library


NetworkX includes 100+ graph algorithms, such as shortest paths (Dijkstra, A*), centrality measures (degree centrality, betweenness centrality, closeness centrality), community detection, connectivity analysis, and maximum flow/minimum cut. Whether you want to compute network efficiency or identify key nodes, you can find corresponding algorithm implementations. It also supports accurate computation for weighted graphs.

2. Flexible Data Import and Export


Supports reading and writing multiple graph data formats, including GraphML, GML, edge lists, JSON, Pandas DataFrames, NumPy matrices, and more. You can easily build graph objects from CSV files, databases, or API data, and export analysis results into various formats for further processing or visualization.

3. Rich Visualization Capabilities


Provides basic visualization features based on matplotlib, supports multiple layout algorithms (force-directed layout, circular layout, hierarchical layout, etc.), and allows customization of node colors and sizes based on node attributes. For interactive needs, it also supports integration with libraries such as Plotly and PyVis to create exploratory network visualizations, suitable for academic publication and data exploration.

Common Questions

How does NetworkX differ from other libraries (such as igraph and graph-tool)?


NetworkX’s strengths are its pure Python implementation, simple and intuitive APIs, and well-developed documentation. This makes it ideal for rapid prototyping and teaching. igraph and graph-tool generally perform better for extremely large-scale networks, but they have a steeper learning curve. If your network size is within the range of up to a million nodes, NetworkX is usually sufficient. For larger scales, you can consider accelerated backends for NetworkX (such as nx-cugraph GPU acceleration).

What size of networks can NetworkX handle?


NetworkX can process networks with hundreds of thousands of nodes and millions of edges, but performance depends on algorithm complexity and your hardware configuration. For ultra-large networks, it’s recommended to use sparse matrix storage, enable approximate algorithms (e.g., setting a sampling parameter k), or use NetworkX 3.x acceleration backends (nx-cugraph, nx-parallel, etc.) to improve performance.

How do I work with graphs that have attributes in NetworkX?


NetworkX natively supports storing attributes on nodes and edges. When adding nodes, you can directly pass an attribute dictionary (e.g., G.add_node(1, type='user', weight=2.5)); edge attributes can also be specified during creation. During analysis, you can access these attributes via G.nodes[data=True] or G.edges[data=True], and use weights in algorithms—for example, weighted shortest paths or weighted centrality measures.