MCPcopy Index your code
hub / github.com/BrynCooke/graph-api

github.com/BrynCooke/graph-api @graph-api-simplegraph-v0.2.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release graph-api-simplegraph-v0.2.2 ↗ · + Follow
778 symbols 3,124 edges 209 files 203 documented · 26% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

CI Crates.io Lib Crates.io Derive Version Crates.io Test Version Crates.io Benches Version Crates.io SimpleGraph Version Crates.io Petgraph Version

Graph API

GraphApi mascot

An ergonomic API for working with in memory graphs in Rust that provides a flexible and type-safe way to interact with graph data structures.

Check out the graph-api book for more information.

Overview

This library offers a unified interface for working with different types of graphs while maintaining strong type safety and ergonomic usage patterns. It includes features for graph traversal, modification, and custom extensions.

Key Features

  • Type-safe graph operations
  • Flexible vertex and edge traversal
  • Custom graph implementations support
  • Derive macros for extending graph functionality
  • Comprehensive testing utilities including fuzzing support

Example usage

#[derive(Debug, Clone, VertexExt)]
pub enum Vertex {
    Person {
        #[index(hash)]
        name: String,
        #[index(range)]
        age: u64,
        #[index(hash)]
        unique_id: Uuid,
        #[index(range)]
        username: String,
        #[index(full_text)]
        biography: String,
    },
    Project {
        name: String
    },
    Rust,
}

#[derive(Debug, Clone, EdgeExt)]
pub enum Edge {
    Knows { since: i32 },
    Created,
    Language {
        name: String
    },
}

fn main() {
    // Create a new graph
    let mut graph = SimpleGraph::new();

    // Populate the graph
    let person = graph.add_vertex(Vertex::Person {
        name: "Bryn".to_string(),
        age: 45,
        unique_id: Uuid::from_u128(1),
        username: "bryn".to_string(),
        biography: "Did some graph stuff".to_string(),
    });
    let project = graph.add_vertex(Vertex::Project { name: "Graph API".to_string() });
    graph.add_edge(person, project, Edge::Created);

    // Traverse the graph
    let all_vertices = graph.walk().vertices(VertexSearch::scan()).collect::<Vec<_>>();

    // A more complicated traversal
    // For up to two people that Bryn knows find all the people that they know and add
    // their ages to Bryn's age and collect them into a list.
    let complex = graph
        .walk()
        .vertices(VertexIndex::person_by_name("Bryn")) // Start at people named Bryn
        .filter_by_person(|v, _| v.username().ends_with("e")) // Filter by username ending with e
        .push_context(|v, ctx| v.project::<Person<_>>().unwrap().age()) // Stash the age in the context
        .edges(EdgeIndex::knows().direction(Direction::Outgoing)) // Traverse to knows
        .limit(2) // Limit the traversal to two elements
        .head() // Traverse to the head of the edge (the known person) 
        .detour(|v| { // Find the people that this person knows and collect their ages
            v.edges(EdgeIndex::knows().direction(Direction::Outgoing))
                .head()
                .push_context(|v, ctx| v.project::<Person<_>>().unwrap().age())
        })
        .map(|v, ctx| **ctx.parent() + *ctx) // Add the ages collected during the traversal 
        .collect::<Vec<_>>();
}

Documentation

Head over to the graph-api book.

License

Apache 2.0

Contributing

Contributions are welcome! Please check out our contribution guidelines for details on how to get started.

Extension points exported contracts — how you extend this code

Walker (Interface)
A trait that defines the basic behavior of a graph walker. The `Walker` trait is the foundation for traversing and expl [25 …
graph-api-lib/src/walker/mod.rs
WalkerBuilderPrintIdExt (Interface)
Extension trait for the WalkerBuilder to add the print_id method [2 implementers]
graph-api-lib/examples/custom_step.rs
VertexWalker (Interface)
A trait that defines the basic behavior of a vertex walker, which is a specialized type of graph walker that focuses on [15 …
graph-api-lib/src/walker/mod.rs
EdgeWalker (Interface)
Trait for walking over edges in a graph. This trait provides methods for working with edges in a graph, including filte [10 …
graph-api-lib/src/walker/mod.rs
Element (Interface)
An element in a graph. This is either an edge or a vertex. [5 implementers]
graph-api-lib/src/element.rs
Index (Interface)
An Index is a fast lookup mechanism for graph elements. Indexes allow for efficient querying of graph elements based on [3 …
graph-api-lib/src/index.rs

Core symbols most depended-on inside this repo

walk
called by 260
graph-api-lib/src/graph.rs
vertices
called by 163
graph-api-lib/src/walker/steps/vertices.rs
edges
called by 161
graph-api-lib/src/walker/steps/edges.rs
map
called by 140
graph-api-lib/src/walker/steps/map.rs
new
called by 132
graph-api-lib/src/walker/builder.rs
vertices_by_id
called by 107
graph-api-lib/src/walker/steps/vertices_by_id.rs
populate_graph
called by 95
graph-api-test/src/lib.rs
clone
called by 84
graph-api-lib/src/search/edge.rs

Shape

Function 317
Method 301
Class 83
Enum 49
Interface 28

Languages

Rust100%

Modules by API surface

graph-api-derive/src/render.rs33 symbols
graph-api-simplegraph/src/graph/mod.rs32 symbols
graph-api-lib/src/petgraph/mod.rs26 symbols
graph-api-simplegraph/src/tombstone_vec.rs23 symbols
graph-api-simplegraph/src/graph/label.rs22 symbols
graph-api-lib/src/walker/builder.rs20 symbols
graph-api-lib/src/walker/steps/context.rs19 symbols
graph-api-lib/src/walker/mod.rs19 symbols
graph-api-lib/src/graph.rs16 symbols
graph-api-test/src/steps/edges.rs12 symbols
graph-api-test/src/steps/boxed.rs12 symbols
graph-api-simplegraph/src/id.rs12 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add graph-api \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page