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.

Two named nodes, Aspirin and PTGS1, joined by a directed binds edge with score 0.9.

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

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 str or bytes. The examples use strings for application identity; key iterators and traversal neighbors return bytes. Decode keys with graph.key_to_string(key) when comparing them with strings.

  • The entity ID is the get_id property, not node.id or a callable get_id(). Cypher’s n.id is query syntax, not the Python attribute API.

  • Read node attributes through node.properties and labels through node.labels; read edge attributes through edge.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

Current-graph reads and writes

Goal

Interface

Important boundary

Fetch a known entity

get_node / get_edge

No property index is needed for an ID lookup.

Find a label, type or property cohort

nodes_by_* / edges_by_* and ID/count helpers

Labels/types are indexed automatically; property indexes are explicit (Property-Graph Filtering and Indexes).

Traverse a known relationship type

neighbors_by_edge_type / iter_typed_adjacency

Direction is explicit; traversal neighbors are byte IDs.

Compose patterns, aggregates or mutations

graph.query(...)

Follow the supported Cypher subset and atomicity scope (Cypher Queries).

Repeatedly draw training neighborhoods

SamplerSnapshot / SamplerEngine

A built artifact is immutable; it does not track later graph writes (Graph sampling API and policy reference).

Narrow services and read authority

GraphDB is the convenient integration handle. Applications can pass narrower services instead: graph.nodes and graph.edges own current CRUD; graph.indexes owns index operations; graph.lookup composes decoded lookups; and graph.traversal owns live typed traversal/sampling.

A repository’s reader narrows write authority. It does not automatically pin the underlying data. For consistent multi-step reads, use graph.current_read_view() on a supported backend; its nodes, edges, indexes, lookup and traversal are snapshot-bound readers. See Storage Backends for a complete pinned-read example and backend matrix.

These services borrow the owning store’s lifetime. Do not retain a reader/view after its owning scope closes. Use handle-bound services when sharing a handle’s caches; independently constructed sessions do not synchronize their caches for you. The detailed decomposition is in Components, Interfaces, and Applications.

Next steps