Graphina is a graph data science library for Rust. It provides common data structures and algorithms for analyzing real-world networks, such as social, transportation, and biological networks.
Compared to other Rust graph libraries like petgraph and rustworkx, Graphina aims to provide a more high-level API and a wide range of ready-to-use algorithms for network analysis and graph mining tasks. Graphina aims to be as feature-rich as NetworkX but with the speed and performance benefits of Rust.
Additionally, the PyGraphina Python library allows using Graphina from Python. Check out the pygraphina directory for more details.
Graphina consists of two main parts: a core library and extensions. The core library provides the basic data structures and algorithms for working with graphs. The extensions are modules outside the core library that contain more advanced algorithms for specific tasks like community detection, link prediction, and calculating node and edge centrality scores.
Extensions are independent of each other but depend on the core library.
To use an extension, you must enable it in your Cargo.toml file as a feature (see Installation section below).
| Module | Feature or Algorithm | Notes |
|---|---|---|
| Types |
|
Base types (graph, node, and edge) that Graphina supports |
| Error Handling |
|
Error handling utilities for Graphina |
| Builders |
|
Ergonomic graph construction utilities |
| IO |
|
I/O routines for reading and writing graph data |
| Serialization |
|
Multiple serialization formats for interoperability |
| Generators |
|
Graph generators for random and structured graphs |
| Paths |
|
Shortest paths algorithms |
| Validation |
|
Graph property validation utilities |
| Module | Feature/Algorithm | Notes |
|---|---|---|
| Centrality |
|
Centrality and influence measures |
| Metrics |
|
Graph-level and node-level metrics |
| MST |
|
Minimum spanning tree algorithms |
| Traversal |
|
Graph traversal algorithms |
| Subgraphs |
|
Subgraph operations and filtering |
| Links |
|
Link prediction algorithms |
| Community |
|
Community detection and clustering algorithms |
| Approximation |
|
Approximation algorithms for NP-hard problems |
| Parallel |
|
Parallel implementations of popular graph algorithms |
cargo add graphinaOr add this to your Cargo.toml:
[dependencies]
graphina = "0.4.0-alpha.4"Or enable all features with:
[dependencies]
graphina = { version = "0.4.0-alpha.4", features = ["centrality", "community", "approximation", "mst", "traversal", "subgraphs", "parallel", "links", "metrics"] }Note
Graphina requires Rust 1.85 or later.
Graphina compiles for the wasm32-unknown-unknown target with all features enabled and needs no extra configuration.
Note
In Wasm build, the parallel algorithms run sequentially because the target has no threads, and the file-based IO and serialization functions
return an error at runtime because the target has no filesystem.
See the documentation and docs.rs/graphina for detailed examples and API references.
use graphina::core::types::Graph;
fn main() {
// Create a new undirected graph
let mut graph = Graph::new();
// Add nodes and edges to the graph
let n0 = graph.add_node(1);
let n1 = graph.add_node(1);
let n2 = graph.add_node(2);
let n3 = graph.add_node(3);
graph.add_edge(n0, n1, 1.0);
graph.add_edge(n1, n2, 1.0);
graph.add_edge(n2, n3, 1.0);
// Get the neighbors of node 1
for neighbor in graph.neighbors(n1) {
println!("Node 1 has neighbor: {}", neighbor.index());
}
}use graphina::core::builders::UndirectedGraphBuilder;
// Use graph builder API to create an undirected graph
let g = UndirectedGraphBuilder::<i32, f64>::undirected()
.with_capacity(4, 3)
.add_node(1)
.add_node(2)
.add_node(3)
.add_edge(0, 1, 1.0)
.add_edge(1, 2, 2.0)
.build()
.unwrap();use graphina::core::generators::{erdos_renyi_graph, barabasi_albert_graph};
use graphina::core::types::Undirected;
// Use 68 for the seed to generate reproducible random graphs
let er = erdos_renyi_graph::<Undirected>(100, 0.2, 68).unwrap();
let ba = barabasi_albert_graph::<Undirected>(1000, 3, 68).unwrap();See CONTRIBUTING.md for details on how to make a contribution.
The mascot is named "Graphina the Dinosaur". As the name implies, she's a dinosaur, however, she herself thinks she's a dragon.
The logo was created using GIMP, ComfyUI, and a Flux Schnell v2 model.
Graphina is licensed under either of these:
- MIT License (LICENSE-MIT)
- Apache License, Version 2.0 (LICENSE-APACHE)
PyGraphina is licensed under the MIT License (LICENSE).