Service Interfaces (Protocols)¶
The interfaces module defines the structural contracts that all UI code must program against. Using typing.Protocol with @runtime_checkable means:
- Any object with the right methods satisfies the interface — no inheritance required.
isinstance(obj, IGraphService)works at runtime for defensive checks.mypyenforces correct usage at development time.
IGraphService¶
The primary service contract for all graph operations. UI widgets receive an IGraphService instance and use only the methods defined here.
Graph Lifecycle¶
| Method | Description |
|---|---|
create_graph(workspace_id, type_name, name) |
Create a new graph in a workspace |
get_graph(graph_id) |
Load a graph by ID |
list_graphs(workspace_id) |
Return all graphs in a workspace |
delete_graph(graph_id) |
Permanently delete a graph and all its contents |
Node Operations¶
| Method | Description |
|---|---|
add_node(graph_id, type_name, attributes) |
Validate and add a new node |
update_node(node_id, attributes) |
Merge new attributes into an existing node |
remove_node(graph_id, node_id) |
Delete a node and all incident edges |
Edge Operations¶
| Method | Description |
|---|---|
add_edge(graph_id, source_id, target_id, type_name, attributes) |
Validate and add a directed edge |
remove_edge(graph_id, edge_id) |
Delete an edge |
IWorkspaceService¶
The contract for workspace lifecycle operations.
| Method | Description |
|---|---|
create_workspace(name) |
Create a new workspace |
get_workspace(workspace_id) |
Return a workspace by ID (KeyError if not found) |
list_workspaces() |
Return all known workspaces |
API Reference¶
knowledge_platform.services.interfaces.IGraphService ¶
Bases: Protocol
Contract for all graph-mutation and graph-query operations.
Source code in src/knowledge_platform/services/interfaces.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
Functions¶
add_edge ¶
add_edge(
graph_id: GraphId,
source_id: NodeId,
target_id: NodeId,
type_name: str,
attributes: dict[str, object],
) -> Edge
Create and add a directed edge between two nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
Owning graph. |
required |
source_id
|
NodeId
|
Origin node. |
required |
target_id
|
NodeId
|
Destination node. |
required |
type_name
|
str
|
Edge type registered on the graph's type. |
required |
attributes
|
dict[str, object]
|
Initial attribute payload. |
required |
Returns:
| Type | Description |
|---|---|
Edge
|
The created :class: |
Source code in src/knowledge_platform/services/interfaces.py
add_node ¶
Create and add a node to a graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
Owning graph. |
required |
type_name
|
str
|
Node type registered on the graph's type. |
required |
attributes
|
dict[str, object]
|
Initial attribute payload. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The created :class: |
Source code in src/knowledge_platform/services/interfaces.py
create_graph ¶
Create a new graph in the given workspace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_id
|
WorkspaceId
|
Owning workspace. |
required |
type_name
|
str
|
Registered graph type name. |
required |
name
|
str
|
Human-readable display name. |
required |
Returns:
| Type | Description |
|---|---|
Graph
|
Newly created :class: |
Source code in src/knowledge_platform/services/interfaces.py
delete_graph ¶
Permanently delete a graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
Target identifier. |
required |
get_graph ¶
Retrieve a graph by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
Target identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
The |
Graph
|
class: |
Raises:
| Type | Description |
|---|---|
KeyError
|
If not found. |
Source code in src/knowledge_platform/services/interfaces.py
list_graphs ¶
List all graphs in a workspace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_id
|
WorkspaceId
|
Owning workspace. |
required |
Returns:
| Type | Description |
|---|---|
list[Graph]
|
Possibly empty list of graphs. |
remove_edge ¶
Remove an edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
Owning graph. |
required |
edge_id
|
EdgeId
|
Target edge. |
required |
remove_node ¶
Remove a node and all its incident edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id
|
GraphId
|
Owning graph. |
required |
node_id
|
NodeId
|
Target node. |
required |
update_node ¶
Update attributes on an existing node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
NodeId
|
Target node. |
required |
attributes
|
dict[str, object]
|
Attributes to merge (partial update). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Updated |
Node
|
class: |
Source code in src/knowledge_platform/services/interfaces.py
knowledge_platform.services.interfaces.IWorkspaceService ¶
Bases: Protocol
Contract for workspace lifecycle operations.
Source code in src/knowledge_platform/services/interfaces.py
Functions¶
create_workspace ¶
Create a new local workspace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Display name. |
required |
Returns:
| Type | Description |
|---|---|
Workspace
|
Newly created :class: |
get_workspace ¶
Retrieve a workspace by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace_id
|
WorkspaceId
|
Target identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
The |
Workspace
|
class: |
Raises:
| Type | Description |
|---|---|
KeyError
|
If not found. |