petgraph-decypher
Cypher-compatible front-end for petgraph:
build, query, and mutate graphs with
openCypher-compatible queries.
This project is independent and is not affiliated with, endorsed by, or sponsored by Neo4j, Inc. Cypher® and Neo4j® are registered trademarks of Neo4j, Inc.
Overview
petgraph-decypher is both:
- A Cypher-driven graph builder (
CREATE/MERGE), and - A query engine for executing read and mutation queries on
petgraph::Graph.
You can start from Cypher or from an existing graph and run Cypher against it.
use build_graph_from_cypher;
let graph = build_graph_from_cypher
.unwrap;
assert_eq!;
assert_eq!;
What works today
| Feature | Status |
|---|---|
Build graphs with CREATE / MERGE |
✅ |
Read queries: MATCH, WHERE, RETURN, OPTIONAL MATCH |
✅ |
Projection features: DISTINCT, ORDER BY, SKIP, LIMIT |
✅ |
Mutation queries: CREATE, MERGE, SET, REMOVE, [DETACH] DELETE |
✅ |
Scalar functions (e.g. size, toString, toUpper, toLower, trim) |
✅ |
| Multiple clauses / semicolon-separated statements | ✅ |
| Multi-label nodes and undirected relationships | ✅ |
| String, integer, float, bool, null, list, map values | ✅ |
Current limitations and planned work
| Capability | Status |
|---|---|
Parameterized queries ($param) |
🚧 planned |
Variable-length paths (*1..3) |
🚧 planned |
| Native subgraph selection as a first-class query output | 🚧 planned |
| End-to-end Cypher subgraph -> petgraph algorithm -> Cypher-style projection helpers | 🚧 planned |
API
// Parse only – returns the HIR-backed query plan
let query = parse_cypher
.unwrap;
// Parse + build graph – executes CREATE/MERGE clauses
let graph = build_graph_from_cypher
.unwrap;
// Read-only query execution via PetgraphCypher trait
use PetgraphCypher;
let result = graph.cypher.unwrap;
// Mutating query execution via PetgraphCypher trait
graph.cypher_mut.unwrap;
Query an existing graph
use Graph;
use ;
let mut graph = new;
let a = graph.add_node;
let b = graph.add_node;
graph.add_edge;
let rows: = graph
.cypher
.unwrap
.collect;
assert_eq!;
Mutate an existing graph
use ;
let mut graph = build_graph_from_cypher.unwrap;
graph.cypher_mut.unwrap;
graph.cypher_mut.unwrap;
Custom node and edge types
build_graph_from_cypher_typed supports domain-specific node and edge weights via
CypherNode and CypherEdge.
For a complete working reference, see:
tests/builder_tests.rs(build_graph_typed_with_custom_types)tests/query_tests.rs(query_match_all_nodes_with_custom_weights)
Showcase direction: Cypher + petgraph algorithms
Today, you can already compose Cypher selection with petgraph algorithms in user code:
- Build/load the graph.
- Use Cypher to select the slice of interest (e.g. nodes/relationships by label/property).
- Run a petgraph algorithm on that selection.
- Map algorithm output back to original node properties.
The examples/indiana_jones.rs example demonstrates the first two steps with read + mutation queries.
Node data
Each petgraph node carries a NodeData value:
NodeData implements CypherNode, and its property map is exposed through
CypherProperties::get.
Edge data
Each petgraph edge carries an EdgeData value:
EdgeData implements CypherEdge, and exposes relationship properties through
CypherProperties::get.
License
Licensed under either of EUPL-1.2, MIT or Apache-2.0 at your option.