Session
pylpg.session
Session for orchestrating object persistence.
Classes:
| Name | Description |
|---|---|
Session |
Orchestrates saving, deleting, and querying graph objects. |
Session
Session(backend: Backend)
Orchestrates saving, deleting, and querying graph objects.
Use as a context manager to ensure the backend connection is closed.
Methods:
| Name | Description |
|---|---|
delete |
Delete a node, relationship, or a list of both. |
delete_all |
Delete every node and relationship in the database. |
execute_query |
Execute a raw Cypher query. |
prefetch |
Batch-load the subgraph reachable from |
save |
Save a node, relationship, or a list of both. |
Source code in src/pylpg/session.py
delete
delete(item: Node | Relationship | list[Node | Relationship]) -> None
Delete a node, relationship, or a list of both.
Source code in src/pylpg/session.py
delete_all
Delete every node and relationship in the database.
Delegates to the backend so each backend can apply its own
strategy (e.g. FalkorDB drops the graph to clear stale label
indexes that survive a plain MATCH (n) DETACH DELETE n).
Source code in src/pylpg/session.py
execute_query
execute_query(cypher: str, parameters: dict[str, Any] | None = None, resolve_nodes: bool = False) -> list[dict[str, Any]]
Execute a raw Cypher query.
When resolve_nodes is True, any driver node objects in the
results are hydrated into Node instances.
Example
Source code in src/pylpg/session.py
prefetch
prefetch(roots: list[Node]) -> Iterator[None]
Batch-load the subgraph reachable from roots into memory.
Inside the block, traversal reads the snapshot instead of querying:
one query per (relationship type, direction) per level, rather than
one per node per field. Saving or deleting inside the block drops the
snapshot; writes made through raw execute_query do not.
Example
Source code in src/pylpg/session.py
save
save(item: Node | Relationship | list[Node | Relationship]) -> None
Save a node, relationship, or a list of both.
For single items, creates or updates depending on whether the item has already been saved. For lists, delegates to the backend's batch save strategy.