The Property Graph
Use the current property graph for mutable application data: entities, their attributes, and directed relationships. Use Temporal history and service reference when you need immutable historical assertions instead. Ordinary current-graph writes do not automatically record temporal versions.
Nodes, edges, and identity
A node has a stable ID, zero or more native labels, and a property dictionary.
An edge has its own stable ID, a source, a target, and properties. Store its
relationship type in properties["type"]. Labels such as Drug describe
nodes; types such as binds describe edges. Neither requires an ontology.
Model the topology as a directed multigraph \(G=(V,E,s,t)\), where \(s,t:E\to V\) give each edge’s source and target. Distinct edges may have the same endpoints. Edge identity is therefore not just the pair \((u,v)\). Properties and labels attach to the identified entities; they are not implicit extra nodes or relationships.
A basic property graph rendered by GestaltDB. For unfamiliar vocabulary, see Concepts and Terminology; Explore graphs and reasoning offline shows how to make your own figures.
Create, replace, and delete
Standalone runnable example. Install gestaltdb[lmdb]. This uses built-in
JSON, disposable storage and a context manager to close the handle.
Standalone example. Choose the capability-qualified installation tab below.
Ordinary current CRUD uses the chosen backend and codec; this example does not require a graph-wide transaction.
1python -m pip install "gestaltdb[lmdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='lmdb', serializer='json') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
1python -m pip install "gestaltdb[lmdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='lmdb', serializer='pickle') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
1python -m pip install "gestaltdb[lmdb,msgpack]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='lmdb', serializer='messagepack') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
1python -m pip install "gestaltdb[lmdb,protobuf]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='lmdb', serializer='protobuf') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
1python -m pip install "gestaltdb[leveldb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='leveldb', serializer='json') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
1python -m pip install "gestaltdb[leveldb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='leveldb', serializer='pickle') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
1python -m pip install "gestaltdb[leveldb,msgpack]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='leveldb', serializer='messagepack') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
1python -m pip install "gestaltdb[leveldb,protobuf]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='leveldb', serializer='protobuf') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
1python -m pip install "gestaltdb[rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='pyrex', serializer='json') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
1python -m pip install "gestaltdb[rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='pyrex', serializer='pickle') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
1python -m pip install "gestaltdb[msgpack,rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='pyrex', serializer='messagepack') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
1python -m pip install "gestaltdb[protobuf,rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3
4with TemporaryDirectory() as root:
5 with GraphDB.create(f"{root}/graph", backend='pyrex', serializer='protobuf') as graph:
6 graph.put_nodes([
7 Node("drug-1", labels=["Drug"], properties={"name": "Aspirin"}),
8 Node("protein-1", labels=["Protein"], properties={"name": "PTGS1"}),
9 ])
10 graph.put_edge(Edge(
11 "binding-1", "drug-1", "protein-1",
12 properties={"type": "binds", "score": 0.9},
13 ))
14 assert graph.get_node("drug-1").get_id == "drug-1"
15 assert graph.get_edge("binding-1").properties["score"] == 0.9
16 assert graph.neighbors_by_edge_type("drug-1", "binds") == [b"protein-1"]
17
18 # Same ID: replace the current entity, not append a history version.
19 graph.put_node(Node(
20 "drug-1", labels=["Drug"],
21 properties={"name": "Aspirin", "approved": True},
22 ))
23 assert graph.get_node("drug-1").properties["approved"] is True
24
25 # Delete the relationship before its endpoint in this workflow.
26 graph.delete_edge("binding-1")
27 graph.delete_node("protein-1")
28 assert graph.get_edge("binding-1") is None
29 assert graph.get_node("protein-1") is None
put_node and put_edge write complete entities. Include the labels and
properties you want retained when replacing them. Do not interpret replacement
as an implicit property merge or a temporal correction. Use
Cypher Queries for SET/REMOVE and explicit graph-mutation patterns.
For incremental application code, start with get_node / get_edge,
put_node / put_edge, put_nodes / put_edges_bulk and explicit
deletion. For table-shaped input, follow the ingestion workflows in
Runnable API Workflows. Batch APIs do not by themselves promise one transaction
across arbitrary operations; see Storage Backends.
IDs and returned objects
ID-taking graph reads accept
strorbytes. The examples use strings for application identity; key iterators and traversal neighbors return bytes. Decode keys withgraph.key_to_string(key)when comparing them with strings.The entity ID is the
get_idproperty, notnode.idor a callableget_id(). Cypher’sn.idis query syntax, not the Python attribute API.Read node attributes through
node.propertiesand labels throughnode.labels; read edge attributes throughedge.properties.Fetching or modifying a Python object is not a write-through operation. Persist intended changes with the write APIs. Serializer choice determines which property values round-trip (Serializers).
Do not depend on iteration order unless the particular API documents it.
Choose an access path
Goal |
Interface |
Important boundary |
|---|---|---|
Fetch a known entity |
|
No property index is needed for an ID lookup. |
Find a label, type or property cohort |
|
Labels/types are indexed automatically; property indexes are explicit (Property-Graph Filtering and Indexes). |
Traverse a known relationship type |
|
Direction is explicit; traversal neighbors are byte IDs. |
Compose patterns, aggregates or mutations |
|
Follow the supported Cypher subset and atomicity scope (Cypher Queries). |
Repeatedly draw training neighborhoods |
|
A built artifact is immutable; it does not track later graph writes (Graph sampling API and policy reference). |
Next steps
Storage Backends: manifests, backend/codec selection, transactions, snapshots and close/reopen lifecycle.
Property-Graph Filtering and Indexes: explicit indexes and selected cohorts.
Cypher Queries: supported read/write patterns, constraints and procedures.
Temporal history and service reference: immutable history, not ordinary entity replacement.
Compatibility, Migration, and Recovery: compatibility, recovery and legacy migration.