ModuleDescriptor Protocol¶
ModuleDescriptor is the plugin contract that every module must satisfy. It is a typing.Protocol, so no inheritance is required — any class with the right attributes and methods qualifies.
What a Module Must Provide¶
| Attribute / Method | Type | Description |
|---|---|---|
module_id |
str |
Unique snake_case identifier, e.g. "outline" |
display_name |
str |
Human-readable label shown in menus and tabs |
document_label_singular |
str |
Label used by the host for one module-owned document |
document_label_plural |
str |
Label used by the host for many documents |
graph_types |
tuple[GraphType, ...] |
Domain types provided by this module |
primary_graph_type |
str |
Canonical graph type name for new documents |
configure(settings) |
None |
Apply runtime settings from modules.yaml |
supports_graph_type(type_name) |
bool |
Return whether the module can render a graph type |
create_widget(graph_service, parent) |
QWidget |
Factory for the module's root UI widget |
create_document(graph_service, workspace_id, name) |
Graph |
Create a new module-owned graph |
list_documents(graph_service, workspace_id) |
list[Graph] |
List module-owned graphs in a workspace |
Minimal Example¶
from knowledge_platform.modules.base import ModuleDescriptor
from knowledge_platform.domain.graph_type import GraphType
from knowledge_platform.services.interfaces import IGraphService
from PySide6.QtWidgets import QWidget, QLabel
class MyGraphType(GraphType):
type_name = "my_type"
node_schemas = {}
edge_schemas = {}
class MyModule:
module_id = "my_module"
display_name = "My Module"
document_label_singular = "My Document"
document_label_plural = "My Documents"
graph_types = (MyGraphType(),)
primary_graph_type = "my_type"
def configure(self, settings) -> None:
pass
def supports_graph_type(self, type_name: str) -> bool:
return type_name == "my_type"
def create_widget(
self,
graph_service: IGraphService,
parent: QWidget | None = None,
) -> QWidget:
return QLabel("Hello from MyModule!", parent)
def create_document(self, graph_service, workspace_id, name):
return graph_service.create_graph(workspace_id, "my_type", name)
def list_documents(self, graph_service, workspace_id):
return [g for g in graph_service.list_graphs(workspace_id) if g.type_name == "my_type"]
Registration¶
At startup, modules are usually loaded through ModuleLoader from modules.yaml. The loader then registers each module descriptor with ModuleRegistry and each provided graph type with TypeRegistry.
from knowledge_platform.modules.loader import ModuleLoader
loader = ModuleLoader()
loader.register_into(type_registry, module_registry)
API Reference¶
knowledge_platform.modules.base.ModuleDescriptor ¶
Bases: Protocol
Protocol defining the contract for all platform modules (plugins).
A module encapsulates:
- One or more :class:
~knowledge_platform.domain.graph_type.GraphTypedefinitions. - A factory for the module's primary UI widget.
- Module-specific document lifecycle hooks used by the host UI.
Attributes:
| Name | Type | Description |
|---|---|---|
module_id |
str
|
Unique snake_case identifier (e.g. |
display_name |
str
|
Human-readable label shown in menus/tabs. |
document_label_singular |
str
|
Human-readable label for one document. |
document_label_plural |
str
|
Human-readable label for many documents. |
graph_types |
tuple[GraphType, ...]
|
Graph types provided by this module. |
primary_graph_type |
str
|
The canonical graph type name for this module. |
Source code in src/knowledge_platform/modules/base.py
Functions¶
configure ¶
create_document ¶
create_widget ¶
Construct and return the module's primary UI widget.
The platform calls this method once per module activation. The returned widget is embedded directly in the main window's content area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_service
|
IGraphService
|
Application service for all graph operations. |
required |
parent
|
'QWidget | None'
|
Optional Qt parent widget. |
None
|
Returns:
| Type | Description |
|---|---|
'QWidget'
|
The module's root :class: |