Read one historical account consistently
As-of reads answer one question at a valid instant and an optional recorded
horizon. An authenticated GraphReadView shares a fixed commit prefix across
several graph/claim reads and snapshot builds. It does not pin mutable current
records, and it is not a truth certificate. Read Temporal and bitemporal data
before using the source and horizon contracts below.
Choose a historical read
Need |
Operation |
|---|---|
Select one logical entity at a point |
|
Traverse winning historical relationships |
|
Inspect append order or an exact version |
|
Reuse one authenticated horizon |
|
Sample a finite valid-time window |
|
Compute all conclusion intervals over a range |
Explicit interval reasoning (Reason over complete validity ranges), not an as-of lookup |
The as-of entity/traversal APIs select points, not every instant in a window. Enumerating versions is an audit of recorded history, not an already-resolved validity union. Choose the window/range API matching the task rather than passing a window to a point selector.
Pin a view while a newer account is recorded
This standalone example first records Alice working for Acme, opens a view, then
corrects the relationship to Beta. The old view still reads Acme; a fresh read
sees Beta. Qualified Cypher uses the same explicit valid/system timestamps but
opens its own historical query view; simply having a Python view open does not
change unrelated graph.query calls.
Standalone example. Choose the capability-qualified installation tab below.
This view authenticates immutable temporal history, not a mutable current snapshot. Historical Cypher pins its own explicitly selected horizon; available current-snapshot capabilities are not interchangeable.
1python -m pip install "gestaltdb[lmdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='json')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
1python -m pip install "gestaltdb[lmdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='pickle')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
1python -m pip install "gestaltdb[lmdb,msgpack]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='messagepack')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
1python -m pip install "gestaltdb[lmdb,protobuf]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='protobuf')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
1python -m pip install "gestaltdb[leveldb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='leveldb', serializer='json')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
1python -m pip install "gestaltdb[leveldb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='leveldb', serializer='pickle')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
1python -m pip install "gestaltdb[leveldb,msgpack]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='leveldb', serializer='messagepack')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
1python -m pip install "gestaltdb[leveldb,protobuf]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='leveldb', serializer='protobuf')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
1python -m pip install "gestaltdb[rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='pyrex', serializer='json')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
1python -m pip install "gestaltdb[rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='pyrex', serializer='pickle')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
1python -m pip install "gestaltdb[msgpack,rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='pyrex', serializer='messagepack')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
1python -m pip install "gestaltdb[protobuf,rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb.graphdb import Edge, GraphDB, Node
3from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='pyrex', serializer='protobuf')
7 try:
8 first = graph.temporal.commit_versions([
9 NodeVersionWrite.assertion(Node("alice", labels=["Person"]), (0, None)),
10 NodeVersionWrite.assertion(Node("acme", properties={"name": "Acme"}), (0, None)),
11 NodeVersionWrite.assertion(Node("beta", properties={"name": "Beta"}), (0, None)),
12 EdgeVersionWrite.assertion(
13 Edge("job", "alice", "acme", properties={"type": "WORKS_FOR"}), (0, None),
14 ),
15 ])
16 with graph.temporal.open_read_view(
17 graph, manifest=graph.manifest, database_id=graph.database_id, valid_time=5,
18 ) as view:
19 graph.temporal.correct_edge_version(
20 Edge("job", "alice", "beta", properties={"type": "WORKS_FOR"}),
21 supersedes_version_id=first.versions[-1].version_id,
22 )
23 assert view.commit_horizon == first.commit_id
24 assert [row.edge.target for row in view.iter_edges_as_of(source="alice")] == ["acme"]
25 assert graph.temporal.get_edge_as_of("job", valid_time=5).edge.target == "beta"
26 point = view.build_sampler_snapshot(f"{root}/point")
27 assert point.metadata["source_provenance"]["commit_horizon"] == first.commit_id
28 view.verify_source()
29
30 historical = graph.query(
31 "MATCH (p:Person)-[:WORKS_FOR]->(company) "
32 "FOR VALID_TIME AS OF datetime($at) FOR SYSTEM_TIME AS OF datetime($known) "
33 "RETURN company.name AS company",
34 {"at": "1970-01-01T00:00:00.000005Z",
35 "known": first.system_time.to_datetime().isoformat()},
36 )
37 assert historical.records == [{"company": "Acme"}]
38 finally:
39 graph.close()
The integer 5 and the ISO instant ending in .000005Z are the same UTC
microsecond. Cypher qualifiers must evaluate to temporal instants, not bare integer
values. Qualified historical queries are read-only and share their temporal
context across the supported query; see Cypher Queries for exact syntax and
query-wide restrictions. Unqualified queries still read the mutable graph.
What the view authenticates
The view captures a fixed contiguous prefix of fully visible commits and stops
before incomplete publication. Pass system_time=... for a recorded instant
or through_commit=... for an exact prefix; do not supply both. Calls through
the view use this horizon even when newer commits become visible.
ReadViewProvenance binds database UUID, backend/serializer identity, visible
commit markers/digest and default valid instant. Snapshot source verification
checks that binding, not merely a matching database path. Close borrowed scopes
before closing the owning graph; do not use a view after its context exits.
graph.temporal.history() is a narrower read-only capability borrowing store
lifetime. It does not independently pin or authenticate a source, initialize its
identity, repair indexes or grant write authority. A current read view instead
pins mutable records and has different backend-qualified provenance
(Storage Backends). Temporal views are supported across the documented
backends, but this does not make current snapshots equally available on them.
Indexes and failures at the read boundary
Temporal as-of reads require fresh temporal indexes. With deferred writes, rebuild explicitly before opening/using an indexed workflow (Append and revise historical records). Corrupt markers, descriptors or record envelopes fail closed rather than becoming partial successful history. Exhaust historical iterators and discard partial output on failure; stopping early is not successful authenticated completion.
Decoded-commit reuse does not remove live-store integrity checks or provide a hard memory bound. Exact validation, cache and provenance contracts remain in Consistent Read Views. For history-preserving sampling across a window, use Sample historical graph structure; the point materialization above is not a history-window artifact. Recovery and migration belong in Compatibility, Migration, and Recovery.