petgraph
Petgraph provides fast, flexible graph data structures and algorithms in Rust. Supporting both directed and undirected graphs with arbitrary node and edge data. It comes with:
-
Multiple Graph Types: Graph, StableGraph, GraphMap, and MatrixGraph to suit various use cases.
-
Algorithms Included & Extensible: For tasks like path-finding, minimum spanning trees, graph isomorphisms, and more - with traits exposed for implementing custom algorithms.
-
Graph Visualization support: Export/import graphs to/from DOT format for visualization with Graphviz.
Supports Rust 1.64 and later. This will only change on major releases.
Example
For more examples, see the documentation on docs.rs.
use UnGraph;
use ;
use FromElements;
use ;
use NodeIndexable;
Documentation
Crate features
petgraph is built with these features enabled by default:
graphmap
enableGraphMap
.stable_graph
enableStableGraph
.matrix_graph
enableMatrixGraph
.
Optionally, the following features can be enabled:
serde-1
enable serialization forGraph, StableGraph, GraphMap
using serde 1.0. Requires Rust version as required by serde.rayon
enable parallel iterators for the underlying data inGraphMap
. Requires Rust version as required by rayon.dot_parser
enable parsing graph from DOT/Graphviz strings and files.
Getting Help
First, see if the answer to your question can be found in the API documentation. If the answer is not there, feel free to ask your question on the discussions page. We would be happy to try to answer your question. If you find a bug, or have a feature request, please open an issue.
Contributing
🦕 Thanks for your help improving the project! We are so happy to have you! We have a contributing guide to help you get started.
Logo
The mascot is named "Sir Paul Rustory Graphosaurus" (close friends call him Paul). The logo has been created by the talented Aren.
License
Dual-licensed to be compatible with the Rust project.
Licensed under the Apache License, Version 2.0 or the MIT license, at your option. This file may not be copied, modified, or distributed except according to those terms.