A lightweight, encrypted graph database built with Rust.
Rusted Graphs is a small, embeddable graph database written in Rust. It stores all graph data — collections, nodes, and edges — in encrypted form and exposes a simple, ergonomic API for creating collections, inserting nodes, updating and querying them.
pip install rusted_graphs_python
npm install rusted_graphs_js
import rusted_graphs_python as rgp
# Initialize the database
rgp.init()
const rg = require("rusted_graphs_js");
// Initialize the database
rg.init();
Collections are containers for your graph data. Each collection holds nodes and edges independently.
collectionName = "people"
rgp.create_collection(collectionName)
let collectionName = "people";
rg.createCollection(collectionName);
rgp.delete_collection(collectionName)
rg.deleteCollection(collectionName);
Removes all nodes and edges from a collection without deleting the collection itself.
rgp.clear_collection(collectionName)
rg.clearCollection(collectionName);
View all collections and their contents.
rgp.lookup()
rg.lookup();
Nodes represent entities in your graph. Each node requires a unique label identifier.
rgp.add_nodes(collectionName, [
{"label": "p1", "type": "people"},
{"label": "p2", "type": "people"}
])
rg.addNodes(collectionName, [
{ label: "p1", type: "people" },
{ label: "p2", type: "people" },
]);
Updates merge new properties with existing ones.
rgp.update_node(collectionName, "p2", {
"label": "p2",
"type": "people",
"isUpdated": True
})
rg.updateNode(collectionName, "p2", {
label: "p2",
type: "people",
isUpdated: true,
});
rgp.remove_nodes(collectionName, ["p1"])
rg.removeNodes(collectionName, ["p1"]);
Edges represent relationships between nodes. Use node labels to define connections.
rgp.add_edges(collectionName, [
{
"from": "p1",
"to": "p2",
"data": {"label": "colleague", "timeInYears": 3}
}
])
rg.addEdges(collectionName, [
{
from: "p1",
to: "p2",
data: { label: "colleague", timeInYears: 3 },
},
]);
rgp.remove_edge(collectionName, "p1", "p2")
rg.removeEdge(collectionName, "p1", "p2");
Query nodes using MongoDB-style conditional expressions. Queries are written as strings with operator functions.
Eq(path, value) - Equal toNe(path, value) - Not equal toLt(path, value) - Less thanLte(path, value) - Less than or equal toGt(path, value) - Greater thanGte(path, value) - Greater than or equal toIn(path, [value1, value2, ...]) - Value in arrayQueries use dot notation to access nested properties. Use data. prefix to query node data fields.
Find nodes where age is greater than 30:
matched_nodes = rgp.query_node(collectionName, "Gt(data.age, 30)")
print(matched_nodes[0])
matched_nodes = rg.queryNode(collectionName, "Gt(data.age, 30)");
console.log(matched_nodes[0]);
Find nodes with specific type:
matched_nodes = rgp.query_node(collectionName, "Eq(type, 'people')")
matched_nodes = rg.queryNode(collectionName, "Eq(type, 'people')");
Find nodes with name in a list:
matched_nodes = rgp.query_node(collectionName, "In(data.name, ['Alice', 'Bob', 'Charlie'])")
matched_nodes = rg.queryNode(
collectionName,
"In(data.name, ['Alice', 'Bob', 'Charlie'])"
);
Combine conditions using And and Or operators.
Find nodes where age > 30 AND type is ‘people’:
matched_nodes = rgp.query_node(
collectionName,
"And(Gt(data.age, 30), Eq(type, 'people'))"
)
matched_nodes = rg.queryNode(
collectionName,
"And(Gt(data.age, 30), Eq(type, 'people'))"
);
Find nodes where age < 25 OR age > 60:
matched_nodes = rgp.query_node(
collectionName,
"Or(Lt(data.age, 25), Gt(data.age, 60))"
)
matched_nodes = rg.queryNode(
collectionName,
"Or(Lt(data.age, 25), Gt(data.age, 60))"
);
Access nested object properties using dot notation.
# Query nested property: data.address.city
matched_nodes = rgp.query_node(collectionName, "Eq(data.address.city, 'New York')")
// Query nested property: data.address.city
matched_nodes = rg.queryNode(
collectionName,
"Eq(data.address.city, 'New York')"
);
Access array elements by index.
# Query first element of tags array
matched_nodes = rgp.query_node(collectionName, "Eq(data.tags.0, 'important')")
// Query first element of tags array
matched_nodes = rg.queryNode(collectionName, "Eq(data.tags.0, 'important')");
Load nodes and edges from JSON files for efficient bulk imports.
nodes.json:
[
{
"label": "person1",
"type": "people",
"data": { "age": 35, "name": "Alice" }
},
{ "label": "person2", "type": "people", "data": { "age": 28, "name": "Bob" } }
]
edges.json:
[
{
"from": "person1",
"to": "person2",
"data": { "label": "friend", "since": 2020 }
}
]
rgp.add_nodes_from_file(collectionName, "/path/to/nodes.json")
rgp.add_edges_from_file(collectionName, "/path/to/edges.json")
rg.addNodesFromFile(collectionName, "./path/to/nodes.json");
rg.addEdgesFromFile(collectionName, "./path/to/edges.json");
import rusted_graphs_python as rgp
from pprint import pprint
# Initialize
rgp.init()
collectionName = "social_network"
# Create collection
rgp.create_collection(collectionName)
# Add nodes
rgp.add_nodes(collectionName, [
{"label": "alice", "type": "person", "data": {"age": 32, "city": "NYC"}},
{"label": "bob", "type": "person", "data": {"age": 28, "city": "LA"}},
{"label": "charlie", "type": "person", "data": {"age": 35, "city": "NYC"}}
])
# Add edges
rgp.add_edges(collectionName, [
{"from": "alice", "to": "bob", "data": {"relationship": "friend"}},
{"from": "alice", "to": "charlie", "data": {"relationship": "colleague"}}
])
# Query nodes older than 30
older_people = rgp.query_node(collectionName, "Gt(data.age, 30)")
pprint(older_people)
# Query people in NYC
nyc_people = rgp.query_node(collectionName, "Eq(data.city, 'NYC')")
pprint(nyc_people)
const rg = require("rusted_graphs_js");
// Initialize
rg.init();
let collectionName = "social_network";
// Create collection
rg.createCollection(collectionName);
// Add nodes
rg.addNodes(collectionName, [
{ label: "alice", type: "person", data: { age: 32, city: "NYC" } },
{ label: "bob", type: "person", data: { age: 28, city: "LA" } },
{ label: "charlie", type: "person", data: { age: 35, city: "NYC" } },
]);
// Add edges
rg.addEdges(collectionName, [
{ from: "alice", to: "bob", data: { relationship: "friend" } },
{ from: "alice", to: "charlie", data: { relationship: "colleague" } },
]);
// Query nodes older than 30
let olderPeople = rg.queryNode(collectionName, "Gt(data.age, 30)");
console.log(olderPeople);
// Query people in NYC
let nycPeople = rg.queryNode(collectionName, "Eq(data.city, 'NYC')");
console.log(nycPeople);
data property