trilium_alchemy.ext.helpers#

Defines more specific classes to assist in the development of extensions.

A common note structure is to create “system” notes which hold templates, scripts, etc. This module provides automation of such a system, with a BaseSystem class to hold various types of notes.

The root system BaseRootSystem additionally holds themes and a built-in stylesheet which hides the “Create child note” button in the UI for subclass-managed notes (Mixin.leaf is False).

If a note hierarchy is defined under a BaseRoot subclass, a BaseRootSystem is automatically added.

For a complete example of a note hierarchy using these classes, see trilium-alchemy/example/event-tracker and its documentation at Event tracker.

A brief example is shown here:

# define a widget
class MyWidget(Widget): 
    content_file = "assets/myWidget.js"

# define a system note
class System(BaseRootSystem):
    widgets = [MyWidget]

# define a root note
# use @children or @child to add child notes
class MyRoot(BaseRoot):
    system = System

Class index#

Canonical

Template

Defines a template.

WorkspaceTemplate

Defines a workspace template.

Workspace

Defines a workspace.

AppCss

Defines a CSS note with label #appCss.

Theme

Defines a theme.

Widget

Defines a widget.

FrontendScript

Defines a frontend script.

BackendScript

Defines a backend script.

BaseSystem

Base class for a “system” note, a collection of various types of infrastructure notes.

BaseRootSystem

Base class for a root “system” note, additionally containing themes and adding a built-in BaseSystem subclass.

BaseRoot

Base class for a hierarchy root note.

Symbols#

class trilium_alchemy.ext.helpers.Template#

Bases:

trilium_alchemy.ext.helpers.BaseTemplate

Aliases:

trilium_alchemy.Template
trilium_alchemy.ext.Template

Defines a template.

Added by decorators:

  • #template

singleton#

True

Inherited from: trilium_alchemy.ext.helpers.BaseTemplate

Templates should have exactly one instance, allowing them to be targets of declarative relations

icon: str | None#

None

Inherited from: trilium_alchemy.core.declarative.IconMixin

If provided, defines value of #iconClass label.

classmethod instance(*args, **kwargs)#

Inherited from: trilium_alchemy.ext.helpers.BaseTemplate

Create new note with ~template relation to this note, passing through constructor args.

Example:

# define a task template (not shown: instantiation in hierarchy)
@label_def("priority", value_type="number")
class Task(Template): # or WorkspaceTemplate
    icon = "bx bx-task"

# create a new note with ~template=Task
task = Task.instance(title="Buy cookies")

# equivalent to:
task = Note(title="Buy cookies", template=Task)
class trilium_alchemy.ext.helpers.WorkspaceTemplate#

Bases:

trilium_alchemy.ext.helpers.BaseTemplate

Aliases:

trilium_alchemy.WorkspaceTemplate
trilium_alchemy.ext.WorkspaceTemplate

Defines a workspace template.

Added by decorators:

  • #workspaceTemplate

singleton#

True

Inherited from: trilium_alchemy.ext.helpers.BaseTemplate

Templates should have exactly one instance, allowing them to be targets of declarative relations

icon: str | None#

None

Inherited from: trilium_alchemy.core.declarative.IconMixin

If provided, defines value of #iconClass label.

classmethod instance(*args, **kwargs)#

Inherited from: trilium_alchemy.ext.helpers.BaseTemplate

Create new note with ~template relation to this note, passing through constructor args.

Example:

# define a task template (not shown: instantiation in hierarchy)
@label_def("priority", value_type="number")
class Task(Template): # or WorkspaceTemplate
    icon = "bx bx-task"

# create a new note with ~template=Task
task = Task.instance(title="Buy cookies")

# equivalent to:
task = Note(title="Buy cookies", template=Task)
class trilium_alchemy.ext.helpers.Workspace#

Bases:

trilium_alchemy.core.note.Note
trilium_alchemy.core.declarative.IconMixin

Aliases:

trilium_alchemy.Workspace
trilium_alchemy.ext.Workspace

Defines a workspace.

Added by decorators:

  • #workspace

singleton#

True

system: BaseSystem#

None

icon: str | None#

None

Inherited from: trilium_alchemy.core.declarative.IconMixin

If provided, defines value of #iconClass label.

class trilium_alchemy.ext.helpers.AppCss#

Bases:

trilium_alchemy.ext.types.CssNote

Aliases:

trilium_alchemy.AppCss
trilium_alchemy.ext.AppCss

Defines a CSS note with label #appCss.

Use Note.content_file to set content from file.

Added by decorators:

  • #appCss

singleton#

True

mime#

"text/css"

Inherited from: trilium_alchemy.ext.types.CssNote

icon#

"bx bxs-file-css"

Inherited from: trilium_alchemy.ext.types.CssNote

note_type#

"code"

Inherited from: trilium_alchemy.ext.types.CodeNote

class trilium_alchemy.ext.helpers.Theme#

Bases:

trilium_alchemy.ext.types.CssNote

Aliases:

trilium_alchemy.Theme
trilium_alchemy.ext.Theme

Defines a theme.

Use Note.content_file to set content from file.

Adds label: #appTheme=Theme.theme_name

  • If None, defaults to class name

singleton#

True

theme_name: str#

None

Name of theme, or None to use class name

mime#

"text/css"

Inherited from: trilium_alchemy.ext.types.CssNote

icon#

"bx bxs-file-css"

Inherited from: trilium_alchemy.ext.types.CssNote

note_type#

"code"

Inherited from: trilium_alchemy.ext.types.CodeNote

class trilium_alchemy.ext.helpers.Widget#

Bases:

trilium_alchemy.ext.types.JsFrontendNote

Aliases:

trilium_alchemy.Widget
trilium_alchemy.ext.Widget

Defines a widget.

Added by decorators:

  • #widget

singleton#

True

mime#

"application/javascript;env=frontend"

Inherited from: trilium_alchemy.ext.types.JsFrontendNote

icon#

"bx bxl-javascript"

Inherited from: trilium_alchemy.ext.types.JsFrontendNote

note_type#

"code"

Inherited from: trilium_alchemy.ext.types.CodeNote

class trilium_alchemy.ext.helpers.FrontendScript#

Bases:

trilium_alchemy.ext.types.JsFrontendNote
trilium_alchemy.ext.helpers.ScriptMixin

Aliases:

trilium_alchemy.FrontendScript
trilium_alchemy.ext.FrontendScript

Defines a frontend script.

Example:

class MyFunction(FrontendScript):
    content_file = 'assets/myFunction.js'

@children(MyFunction)
class MyWidget(Widget): pass
singleton#

True

mime#

"application/javascript;env=frontend"

Inherited from: trilium_alchemy.ext.types.JsFrontendNote

icon#

"bx bxl-javascript"

Inherited from: trilium_alchemy.ext.types.JsFrontendNote

note_type#

"code"

Inherited from: trilium_alchemy.ext.types.CodeNote

class trilium_alchemy.ext.helpers.BackendScript#

Bases:

trilium_alchemy.ext.types.JsBackendNote
trilium_alchemy.ext.helpers.ScriptMixin

Aliases:

trilium_alchemy.BackendScript
trilium_alchemy.ext.BackendScript

Defines a backend script.

Example:

class UpdateSomeOtherAttribute(BackendScript):
    content_file = 'assets/updateSomeOtherAttribute.js'

@relation('runOnAttributeCreation', UpdateSomeOtherAttribute)
@relation('runOnAttributeChange', UpdateSomeOtherAttribute)
class MyTemplate(Template): pass
singleton#

True

mime#

"application/javascript;env=backend"

Inherited from: trilium_alchemy.ext.types.JsBackendNote

icon#

"bx bxl-javascript"

Inherited from: trilium_alchemy.ext.types.JsBackendNote

note_type#

"code"

Inherited from: trilium_alchemy.ext.types.CodeNote

class trilium_alchemy.ext.helpers.BaseSystem#

Bases:

trilium_alchemy.core.note.Note

Aliases:

trilium_alchemy.BaseSystem
trilium_alchemy.ext.BaseSystem

Base class for a “system” note, a collection of various types of infrastructure notes.

Added by decorators:

  • #archived

  • #iconClass=bx bx-bracket

templates: list[Type[Template]]#

None

List of Template subclasses.

workspace_templates: list[Type[WorkspaceTemplate]]#

None

List of WorkspaceTemplate subclasses.

stylesheets: list[Type[AppCss]]#

None

List of AppCss subclasses.

widgets: list[Type[Widget]]#

None

List of Widget subclasses.

scripts: list[Type[FrontendScript | BackendScript]]#

None

List of FrontendScript or BackendScript subclasses.

class trilium_alchemy.ext.helpers.BaseRootSystem#

Bases:

trilium_alchemy.ext.helpers.BaseSystem

Aliases:

trilium_alchemy.BaseRootSystem
trilium_alchemy.ext.BaseRootSystem

Base class for a root “system” note, additionally containing themes and adding a built-in BaseSystem subclass.

Added by decorators:

  • #archived

  • #iconClass=bx bx-bracket

themes: list[Type[Theme]]#

None

List of Theme subclasses

templates: list[Type[Template]]#

None

Inherited from: trilium_alchemy.ext.helpers.BaseSystem

List of Template subclasses.

workspace_templates: list[Type[WorkspaceTemplate]]#

None

Inherited from: trilium_alchemy.ext.helpers.BaseSystem

List of WorkspaceTemplate subclasses.

stylesheets: list[Type[AppCss]]#

None

Inherited from: trilium_alchemy.ext.helpers.BaseSystem

List of AppCss subclasses.

widgets: list[Type[Widget]]#

None

Inherited from: trilium_alchemy.ext.helpers.BaseSystem

List of Widget subclasses.

scripts: list[Type[FrontendScript | BackendScript]]#

None

Inherited from: trilium_alchemy.ext.helpers.BaseSystem

List of FrontendScript or BackendScript subclasses.

class trilium_alchemy.ext.helpers.BaseRoot#

Bases:

trilium_alchemy.core.note.Note

Aliases:

trilium_alchemy.BaseRoot
trilium_alchemy.ext.BaseRoot

Base class for a hierarchy root note.

title#

"root"

system: Type[BaseRootSystem]#

BaseRootSystem