trilium_alchemy.lib.extension_types¶
Defines more specific classes to assist in the development of extensions.
Class index¶
Canonical
Defines a template. |
|
Defines a workspace template. |
|
Defines a CSS note with label |
|
Defines a theme. |
|
Defines a widget. |
|
Defines a frontend script. |
|
Defines a backend script. |
Symbols¶
- class trilium_alchemy.lib.extension_types.BaseTemplateNote(title: str | None = None, note_type: str | None = None, mime: str | None = None, *, attributes: collections.abc.Iterable[BaseAttribute] | None = None, parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None, children: collections.abc.Iterable[Note | Branch] | None = None, content: str | bytes | IO | None = None, attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None, note_id: str | None = None, template: Note | type[Note] | None = None, session: Session | None = None, **kwargs)¶
Initialization:
- Parameters:
- title: str | None = None
Note title
- note_type: str | None = None
Note type, default
text; one of:"text","code","relationMap","search","render","book","mermaid","canvas","file","image"- mime: str | None = None
MIME type, default
text/html; needs to be specified only for note types"text","code","file","image"- parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None
Parent note/branch, or iterable of notes/branches (internally modeled as a
set)- children: collections.abc.Iterable[Note | Branch] | None = None
Iterable of child notes/branches (internally modeled as a
list)- attributes: collections.abc.Iterable[BaseAttribute] | None = None
Iterable of attributes (internally modeled as a
list)- content: str | bytes | IO | None = None
Text/binary content or file handle
- attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None
Iterable of attachments (internally modeled as a
list); items may be anAttachment, apathlib.Path, or a binary file handle with a.name- note_id: str | None = None
noteIdto use, will create if it doesn’t exist- template: Note | type[Note] | None = None
Note to set as target of
~templaterelation- session: Session | None = None
Session, or
Noneto use default- kwargs
Internal only
Bases:
trilium_alchemy.lib.extension_types._BaseTemplateNoteAliases:
trilium_alchemy.BaseTemplateNote
trilium_alchemy.lib.BaseTemplateNoteDefines a template.
Added by decorators:
#template
- idempotent¶
TrueInherited from:
trilium_alchemy.lib.extension_types._BaseTemplateNote
- note_id_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNotenote_idto explicitly assign.
- title_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteTitle to set, or
Noneto use class name.
- note_type_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteNote type to set.
- mime_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteMIME type to set.
- content_: str | bytes | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteContent to set.
- content_file: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteName of file to use as content, relative to module’s location.
Also adds
#originalFilenamelabel.Note
Currently Trilium only shows
#originalFilenameif the note’s type isfile.
- note_id_seed: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSeed from which to generate
note_id.Useful to generate a collision-avoidant id from a human-friendly identifier. Generated as base64-encoded hash of seed.
- note_id_segment: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSegment with which to generate
note_idgiven the parent’snote_id, if nonote_idis otherwise specified.
- singleton: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, enables deterministic calculation ofnote_idbased on the fully qualified class name. This means the same class will always have the samenote_idwhen instantiated.Warning
If you move this class to a different module, it will result in a different
note_idwhich will break any non-declarative relations to it. To enable more portable behavior, setBaseDeclarativeNote.idempotentor assignBaseDeclarativeNote.note_id_seedexplicitly.
- idempotent_segment: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, sets segment name to class name for the purpose ofnote_idcalculation.An explicitly provided
BaseDeclarativeNote.note_id_segmenttakes precedence.
- leaf: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set to
Trueon aBaseDeclarativeNotesubclass, disables setting of child notes declaratively, allowing children to be manually maintained by the user. Otherwise, notes added by the user will be deleted to match the children added declaratively.Should be set on notes intended to hold user notes, e.g. todo lists.
- hide_new_note: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteWhether to hide “new note” button, regardless of whether it would otherwise be hidden.
Can be used to hide “new note” button for e.g.
Templateswhich otherwise would show it.
- icon: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinIf provided, adds
#iconClasslabel unless it is already present.
- property note_id_seed_final: str | None¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteGet the seed from which this note’s id was derived.
Useful for debugging.
- property note_id: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
noteId, orNoneif not created yet.
- property title: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property note_type: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property mime: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for MIME type.
- property is_protected: bool¶
Inherited from:
trilium_alchemy.core.note.NoteProtected state, can only be changed in Trilium UI.
- property date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal created datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal modified datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property utc_date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC created datetime, e.g.
2021-12-31 19:18:11.939Z.
- property utc_date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC modified datetime, e.g.
2021-12-31 19:18:11.939Z.
- property attributes: Attributes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attributes, both owned and inherited.
- Setter:
Sets list of owned attributes, replacing the existing list
- property labels: Labels¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property relations: Relations¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property branches: Branches¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for branches, both parents (
.parents) and children (.children).
- property parents: ParentNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for parent notes.
- Setter:
Sets set of parent notes, replacing the existing set
- property children: ChildNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for child notes.
- Setter:
Sets list of child notes, replacing the existing list
- property content: str | bytes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note content.
- property content_str: str¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for text note content.
- property content_bin: bytes¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for binary note content.
- property blob_id: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
blobId, a digest of the note content.
- property attachments: Attachments¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attachments, modeled as a list.
- Setter:
Sets list of attachments, replacing the existing list. Items may be an
Attachment, apathlib.Path, or a binary file handle with a.name.
- property is_string: bool¶
Inherited from:
trilium_alchemy.core.note.NoteTrueif note as it’s currently configured has text content.Mirrors Trilium’s
src/services/utils.js:isStringNote().
- property paths: list[list[Note]]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a list of ancestor notes.
- property paths_str: list[str]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a string like
A > B > C.
- classmethod new_instance(*args, **kwargs)¶
Inherited from:
trilium_alchemy.lib.extension_types._BaseTemplateNoteCreate new note with
~templaterelation to this note, passing through constructor args.
- get(name: str, default: str | None = None) str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGet value of first label with provided name, or
Noneif no such label exists.
- copy(deep: bool = False) Note¶
Inherited from:
trilium_alchemy.core.note.NoteReturn a copy of this note, including its title, type, MIME, attributes, and content.
If
deepisFalse, child notes are cloned to the returned copy. Otherwise, child notes are recursively deep copied.Note
The returned copy still needs to be placed in the tree hierarchy (added as a child of another note) before
Session.flush()is invoked.
- sync_template(template: Note)¶
Inherited from:
trilium_alchemy.core.note.NoteUpdate this note to match the provided template:
Set note type and MIME
Set content if empty
Recursively deep copy missing child notes, matched by title
- transmute(note_cls: type[NoteT]) NoteT¶
Inherited from:
trilium_alchemy.core.note.NoteChange this note’s base to the provided class and return it.
This is useful for converting a
Noteinstance to a subclass thereof with custom convenience APIs.Note
Has a side effect of committing any changes to this note to Trilium.
- export_zip(dest_file: pathlib.Path, export_format: Literal[html, markdown] = 'html', overwrite: bool = False)¶
Inherited from:
trilium_alchemy.core.note.NoteExport this note subtree to zip file.
- Parameters:
- dest_file: pathlib.Path
Destination .zip file
- export_format: Literal[html, markdown] = 'html'
Format of exported HTML notes
- overwrite: bool = False
Whether to overwrite destination path if it exists
- import_zip(src_file: pathlib.Path) Note¶
Inherited from:
trilium_alchemy.core.note.NoteImport note subtree from zip file, adding the imported root as a child of this note and returning it.
- Parameters:
- src_file: pathlib.Path
Source .zip file
- walk() Generator[Note, None, None]¶
Inherited from:
trilium_alchemy.core.note.NoteYield this note and all children recursively.
Each note will only occur once (clones are skipped).
- flush()¶
Inherited from:
trilium_alchemy.core.note.NoteFlush note along with its owned attributes.
- init(attributes: list[BaseAttribute], children: list[Branch], /)¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCan be overridden to add attributes and/or children during instantiation. Use the following to create attribute/child with deterministic id:
Note
User should not invoke
super().init(). To add attributes and children in an intuitive order, TriliumAlchemy manually traverses aBaseDeclarativeNotesubclass’s MRO and invokes decorator-patched inits followed byBaseDeclarativeMixin.init.- Parameters:
- attributes: list[BaseAttribute]
List of attributes to which user can append using
BaseDeclarativeMixin.create_declarative_labelorBaseDeclarativeMixin.create_declarative_relation- children: list[Branch]
List of children to which user can append using
BaseDeclarativeMixin.create_declarative_child
- create_declarative_label(name: str, value: str = '', inheritable: bool = False) Label¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Labelwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_relation(name: str, target: Note, inheritable: bool = False) Relation¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Relationwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_child(child_cls: type[BaseDeclarativeNote], title: str | None = None, note_type: str | None = None, mime: str | None = None, parents: Iterable[Note | Branch] | Note | Branch | None = None, children: Iterable[Note | Branch] | None = None, attributes: Iterable[BaseAttribute] | None = None, content: str | bytes | IO | None = None, template: Note | type[Note] | None = None, prefix: str = '', expanded: bool | None = None) Branch¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreates a child
BaseDeclarativeNotewith deterministicnote_idand returns aBranch. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the same childnote_idupon every instantiation.If the parent note’s
note_idset, the child note will be assigned one so as to create the samenote_idupon every instantiation.If the child’s
note_idis not fixed, a new note will be created upon every instantiation. This is the case for non-singleton subclasses.Params following
child_clsare passed to theNoteandBranchinitializers.- Parameters:
- child_cls: type[BaseDeclarativeNote]
Class of child to instantiate
- class trilium_alchemy.lib.extension_types.BaseWorkspaceTemplateNote(title: str | None = None, note_type: str | None = None, mime: str | None = None, *, attributes: collections.abc.Iterable[BaseAttribute] | None = None, parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None, children: collections.abc.Iterable[Note | Branch] | None = None, content: str | bytes | IO | None = None, attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None, note_id: str | None = None, template: Note | type[Note] | None = None, session: Session | None = None, **kwargs)¶
Initialization:
- Parameters:
- title: str | None = None
Note title
- note_type: str | None = None
Note type, default
text; one of:"text","code","relationMap","search","render","book","mermaid","canvas","file","image"- mime: str | None = None
MIME type, default
text/html; needs to be specified only for note types"text","code","file","image"- parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None
Parent note/branch, or iterable of notes/branches (internally modeled as a
set)- children: collections.abc.Iterable[Note | Branch] | None = None
Iterable of child notes/branches (internally modeled as a
list)- attributes: collections.abc.Iterable[BaseAttribute] | None = None
Iterable of attributes (internally modeled as a
list)- content: str | bytes | IO | None = None
Text/binary content or file handle
- attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None
Iterable of attachments (internally modeled as a
list); items may be anAttachment, apathlib.Path, or a binary file handle with a.name- note_id: str | None = None
noteIdto use, will create if it doesn’t exist- template: Note | type[Note] | None = None
Note to set as target of
~templaterelation- session: Session | None = None
Session, or
Noneto use default- kwargs
Internal only
Bases:
trilium_alchemy.lib.extension_types._BaseTemplateNoteAliases:
trilium_alchemy.BaseWorkspaceTemplateNote
trilium_alchemy.lib.BaseWorkspaceTemplateNoteDefines a workspace template.
Added by decorators:
#workspaceTemplate
- idempotent¶
TrueInherited from:
trilium_alchemy.lib.extension_types._BaseTemplateNote
- note_id_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNotenote_idto explicitly assign.
- title_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteTitle to set, or
Noneto use class name.
- note_type_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteNote type to set.
- mime_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteMIME type to set.
- content_: str | bytes | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteContent to set.
- content_file: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteName of file to use as content, relative to module’s location.
Also adds
#originalFilenamelabel.Note
Currently Trilium only shows
#originalFilenameif the note’s type isfile.
- note_id_seed: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSeed from which to generate
note_id.Useful to generate a collision-avoidant id from a human-friendly identifier. Generated as base64-encoded hash of seed.
- note_id_segment: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSegment with which to generate
note_idgiven the parent’snote_id, if nonote_idis otherwise specified.
- singleton: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, enables deterministic calculation ofnote_idbased on the fully qualified class name. This means the same class will always have the samenote_idwhen instantiated.Warning
If you move this class to a different module, it will result in a different
note_idwhich will break any non-declarative relations to it. To enable more portable behavior, setBaseDeclarativeNote.idempotentor assignBaseDeclarativeNote.note_id_seedexplicitly.
- idempotent_segment: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, sets segment name to class name for the purpose ofnote_idcalculation.An explicitly provided
BaseDeclarativeNote.note_id_segmenttakes precedence.
- leaf: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set to
Trueon aBaseDeclarativeNotesubclass, disables setting of child notes declaratively, allowing children to be manually maintained by the user. Otherwise, notes added by the user will be deleted to match the children added declaratively.Should be set on notes intended to hold user notes, e.g. todo lists.
- hide_new_note: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteWhether to hide “new note” button, regardless of whether it would otherwise be hidden.
Can be used to hide “new note” button for e.g.
Templateswhich otherwise would show it.
- icon: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinIf provided, adds
#iconClasslabel unless it is already present.
- property note_id_seed_final: str | None¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteGet the seed from which this note’s id was derived.
Useful for debugging.
- property note_id: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
noteId, orNoneif not created yet.
- property title: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property note_type: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property mime: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for MIME type.
- property is_protected: bool¶
Inherited from:
trilium_alchemy.core.note.NoteProtected state, can only be changed in Trilium UI.
- property date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal created datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal modified datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property utc_date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC created datetime, e.g.
2021-12-31 19:18:11.939Z.
- property utc_date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC modified datetime, e.g.
2021-12-31 19:18:11.939Z.
- property attributes: Attributes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attributes, both owned and inherited.
- Setter:
Sets list of owned attributes, replacing the existing list
- property labels: Labels¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property relations: Relations¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property branches: Branches¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for branches, both parents (
.parents) and children (.children).
- property parents: ParentNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for parent notes.
- Setter:
Sets set of parent notes, replacing the existing set
- property children: ChildNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for child notes.
- Setter:
Sets list of child notes, replacing the existing list
- property content: str | bytes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note content.
- property content_str: str¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for text note content.
- property content_bin: bytes¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for binary note content.
- property blob_id: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
blobId, a digest of the note content.
- property attachments: Attachments¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attachments, modeled as a list.
- Setter:
Sets list of attachments, replacing the existing list. Items may be an
Attachment, apathlib.Path, or a binary file handle with a.name.
- property is_string: bool¶
Inherited from:
trilium_alchemy.core.note.NoteTrueif note as it’s currently configured has text content.Mirrors Trilium’s
src/services/utils.js:isStringNote().
- property paths: list[list[Note]]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a list of ancestor notes.
- property paths_str: list[str]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a string like
A > B > C.
- classmethod new_instance(*args, **kwargs)¶
Inherited from:
trilium_alchemy.lib.extension_types._BaseTemplateNoteCreate new note with
~templaterelation to this note, passing through constructor args.
- get(name: str, default: str | None = None) str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGet value of first label with provided name, or
Noneif no such label exists.
- copy(deep: bool = False) Note¶
Inherited from:
trilium_alchemy.core.note.NoteReturn a copy of this note, including its title, type, MIME, attributes, and content.
If
deepisFalse, child notes are cloned to the returned copy. Otherwise, child notes are recursively deep copied.Note
The returned copy still needs to be placed in the tree hierarchy (added as a child of another note) before
Session.flush()is invoked.
- sync_template(template: Note)¶
Inherited from:
trilium_alchemy.core.note.NoteUpdate this note to match the provided template:
Set note type and MIME
Set content if empty
Recursively deep copy missing child notes, matched by title
- transmute(note_cls: type[NoteT]) NoteT¶
Inherited from:
trilium_alchemy.core.note.NoteChange this note’s base to the provided class and return it.
This is useful for converting a
Noteinstance to a subclass thereof with custom convenience APIs.Note
Has a side effect of committing any changes to this note to Trilium.
- export_zip(dest_file: pathlib.Path, export_format: Literal[html, markdown] = 'html', overwrite: bool = False)¶
Inherited from:
trilium_alchemy.core.note.NoteExport this note subtree to zip file.
- Parameters:
- dest_file: pathlib.Path
Destination .zip file
- export_format: Literal[html, markdown] = 'html'
Format of exported HTML notes
- overwrite: bool = False
Whether to overwrite destination path if it exists
- import_zip(src_file: pathlib.Path) Note¶
Inherited from:
trilium_alchemy.core.note.NoteImport note subtree from zip file, adding the imported root as a child of this note and returning it.
- Parameters:
- src_file: pathlib.Path
Source .zip file
- walk() Generator[Note, None, None]¶
Inherited from:
trilium_alchemy.core.note.NoteYield this note and all children recursively.
Each note will only occur once (clones are skipped).
- flush()¶
Inherited from:
trilium_alchemy.core.note.NoteFlush note along with its owned attributes.
- init(attributes: list[BaseAttribute], children: list[Branch], /)¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCan be overridden to add attributes and/or children during instantiation. Use the following to create attribute/child with deterministic id:
Note
User should not invoke
super().init(). To add attributes and children in an intuitive order, TriliumAlchemy manually traverses aBaseDeclarativeNotesubclass’s MRO and invokes decorator-patched inits followed byBaseDeclarativeMixin.init.- Parameters:
- attributes: list[BaseAttribute]
List of attributes to which user can append using
BaseDeclarativeMixin.create_declarative_labelorBaseDeclarativeMixin.create_declarative_relation- children: list[Branch]
List of children to which user can append using
BaseDeclarativeMixin.create_declarative_child
- create_declarative_label(name: str, value: str = '', inheritable: bool = False) Label¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Labelwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_relation(name: str, target: Note, inheritable: bool = False) Relation¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Relationwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_child(child_cls: type[BaseDeclarativeNote], title: str | None = None, note_type: str | None = None, mime: str | None = None, parents: Iterable[Note | Branch] | Note | Branch | None = None, children: Iterable[Note | Branch] | None = None, attributes: Iterable[BaseAttribute] | None = None, content: str | bytes | IO | None = None, template: Note | type[Note] | None = None, prefix: str = '', expanded: bool | None = None) Branch¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreates a child
BaseDeclarativeNotewith deterministicnote_idand returns aBranch. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the same childnote_idupon every instantiation.If the parent note’s
note_idset, the child note will be assigned one so as to create the samenote_idupon every instantiation.If the child’s
note_idis not fixed, a new note will be created upon every instantiation. This is the case for non-singleton subclasses.Params following
child_clsare passed to theNoteandBranchinitializers.- Parameters:
- child_cls: type[BaseDeclarativeNote]
Class of child to instantiate
- class trilium_alchemy.lib.extension_types.BaseAppCssNote(title: str | None = None, note_type: str | None = None, mime: str | None = None, *, attributes: collections.abc.Iterable[BaseAttribute] | None = None, parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None, children: collections.abc.Iterable[Note | Branch] | None = None, content: str | bytes | IO | None = None, attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None, note_id: str | None = None, template: Note | type[Note] | None = None, session: Session | None = None, **kwargs)¶
Initialization:
- Parameters:
- title: str | None = None
Note title
- note_type: str | None = None
Note type, default
text; one of:"text","code","relationMap","search","render","book","mermaid","canvas","file","image"- mime: str | None = None
MIME type, default
text/html; needs to be specified only for note types"text","code","file","image"- parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None
Parent note/branch, or iterable of notes/branches (internally modeled as a
set)- children: collections.abc.Iterable[Note | Branch] | None = None
Iterable of child notes/branches (internally modeled as a
list)- attributes: collections.abc.Iterable[BaseAttribute] | None = None
Iterable of attributes (internally modeled as a
list)- content: str | bytes | IO | None = None
Text/binary content or file handle
- attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None
Iterable of attachments (internally modeled as a
list); items may be anAttachment, apathlib.Path, or a binary file handle with a.name- note_id: str | None = None
noteIdto use, will create if it doesn’t exist- template: Note | type[Note] | None = None
Note to set as target of
~templaterelation- session: Session | None = None
Session, or
Noneto use default- kwargs
Internal only
Bases:
trilium_alchemy.lib.note_types.CssNoteAliases:
trilium_alchemy.BaseAppCssNote
trilium_alchemy.lib.BaseAppCssNoteDefines a CSS note with label
#appCss.Use
BaseDeclarativeNote.content_fileto set content from file.Added by decorators:
#appCss
- singleton¶
True
- mime_¶
"text/css"Inherited from:
trilium_alchemy.lib.note_types.CssNote
- icon¶
"bx bxs-file-css"Inherited from:
trilium_alchemy.lib.note_types.CssNote
- note_type_¶
"code"Inherited from:
trilium_alchemy.lib.note_types.CodeNote
- note_id_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNotenote_idto explicitly assign.
- title_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteTitle to set, or
Noneto use class name.
- content_: str | bytes | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteContent to set.
- content_file: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteName of file to use as content, relative to module’s location.
Also adds
#originalFilenamelabel.Note
Currently Trilium only shows
#originalFilenameif the note’s type isfile.
- note_id_seed: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSeed from which to generate
note_id.Useful to generate a collision-avoidant id from a human-friendly identifier. Generated as base64-encoded hash of seed.
- note_id_segment: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSegment with which to generate
note_idgiven the parent’snote_id, if nonote_idis otherwise specified.
- idempotent: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, enables deterministic calculation ofnote_idbased on the class name.Similar to
BaseDeclarativeNote.singleton, but only the class name (not fully qualified) is used.
- idempotent_segment: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, sets segment name to class name for the purpose ofnote_idcalculation.An explicitly provided
BaseDeclarativeNote.note_id_segmenttakes precedence.
- leaf: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set to
Trueon aBaseDeclarativeNotesubclass, disables setting of child notes declaratively, allowing children to be manually maintained by the user. Otherwise, notes added by the user will be deleted to match the children added declaratively.Should be set on notes intended to hold user notes, e.g. todo lists.
- hide_new_note: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteWhether to hide “new note” button, regardless of whether it would otherwise be hidden.
Can be used to hide “new note” button for e.g.
Templateswhich otherwise would show it.
- property note_id_seed_final: str | None¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteGet the seed from which this note’s id was derived.
Useful for debugging.
- property note_id: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
noteId, orNoneif not created yet.
- property title: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property note_type: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property mime: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for MIME type.
- property is_protected: bool¶
Inherited from:
trilium_alchemy.core.note.NoteProtected state, can only be changed in Trilium UI.
- property date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal created datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal modified datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property utc_date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC created datetime, e.g.
2021-12-31 19:18:11.939Z.
- property utc_date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC modified datetime, e.g.
2021-12-31 19:18:11.939Z.
- property attributes: Attributes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attributes, both owned and inherited.
- Setter:
Sets list of owned attributes, replacing the existing list
- property labels: Labels¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property relations: Relations¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property branches: Branches¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for branches, both parents (
.parents) and children (.children).
- property parents: ParentNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for parent notes.
- Setter:
Sets set of parent notes, replacing the existing set
- property children: ChildNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for child notes.
- Setter:
Sets list of child notes, replacing the existing list
- property content: str | bytes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note content.
- property content_str: str¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for text note content.
- property content_bin: bytes¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for binary note content.
- property blob_id: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
blobId, a digest of the note content.
- property attachments: Attachments¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attachments, modeled as a list.
- Setter:
Sets list of attachments, replacing the existing list. Items may be an
Attachment, apathlib.Path, or a binary file handle with a.name.
- property is_string: bool¶
Inherited from:
trilium_alchemy.core.note.NoteTrueif note as it’s currently configured has text content.Mirrors Trilium’s
src/services/utils.js:isStringNote().
- property paths: list[list[Note]]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a list of ancestor notes.
- property paths_str: list[str]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a string like
A > B > C.
- get(name: str, default: str | None = None) str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGet value of first label with provided name, or
Noneif no such label exists.
- copy(deep: bool = False) Note¶
Inherited from:
trilium_alchemy.core.note.NoteReturn a copy of this note, including its title, type, MIME, attributes, and content.
If
deepisFalse, child notes are cloned to the returned copy. Otherwise, child notes are recursively deep copied.Note
The returned copy still needs to be placed in the tree hierarchy (added as a child of another note) before
Session.flush()is invoked.
- sync_template(template: Note)¶
Inherited from:
trilium_alchemy.core.note.NoteUpdate this note to match the provided template:
Set note type and MIME
Set content if empty
Recursively deep copy missing child notes, matched by title
- transmute(note_cls: type[NoteT]) NoteT¶
Inherited from:
trilium_alchemy.core.note.NoteChange this note’s base to the provided class and return it.
This is useful for converting a
Noteinstance to a subclass thereof with custom convenience APIs.Note
Has a side effect of committing any changes to this note to Trilium.
- export_zip(dest_file: pathlib.Path, export_format: Literal[html, markdown] = 'html', overwrite: bool = False)¶
Inherited from:
trilium_alchemy.core.note.NoteExport this note subtree to zip file.
- Parameters:
- dest_file: pathlib.Path
Destination .zip file
- export_format: Literal[html, markdown] = 'html'
Format of exported HTML notes
- overwrite: bool = False
Whether to overwrite destination path if it exists
- import_zip(src_file: pathlib.Path) Note¶
Inherited from:
trilium_alchemy.core.note.NoteImport note subtree from zip file, adding the imported root as a child of this note and returning it.
- Parameters:
- src_file: pathlib.Path
Source .zip file
- walk() Generator[Note, None, None]¶
Inherited from:
trilium_alchemy.core.note.NoteYield this note and all children recursively.
Each note will only occur once (clones are skipped).
- flush()¶
Inherited from:
trilium_alchemy.core.note.NoteFlush note along with its owned attributes.
- init(attributes: list[BaseAttribute], children: list[Branch], /)¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCan be overridden to add attributes and/or children during instantiation. Use the following to create attribute/child with deterministic id:
Note
User should not invoke
super().init(). To add attributes and children in an intuitive order, TriliumAlchemy manually traverses aBaseDeclarativeNotesubclass’s MRO and invokes decorator-patched inits followed byBaseDeclarativeMixin.init.- Parameters:
- attributes: list[BaseAttribute]
List of attributes to which user can append using
BaseDeclarativeMixin.create_declarative_labelorBaseDeclarativeMixin.create_declarative_relation- children: list[Branch]
List of children to which user can append using
BaseDeclarativeMixin.create_declarative_child
- create_declarative_label(name: str, value: str = '', inheritable: bool = False) Label¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Labelwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_relation(name: str, target: Note, inheritable: bool = False) Relation¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Relationwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_child(child_cls: type[BaseDeclarativeNote], title: str | None = None, note_type: str | None = None, mime: str | None = None, parents: Iterable[Note | Branch] | Note | Branch | None = None, children: Iterable[Note | Branch] | None = None, attributes: Iterable[BaseAttribute] | None = None, content: str | bytes | IO | None = None, template: Note | type[Note] | None = None, prefix: str = '', expanded: bool | None = None) Branch¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreates a child
BaseDeclarativeNotewith deterministicnote_idand returns aBranch. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the same childnote_idupon every instantiation.If the parent note’s
note_idset, the child note will be assigned one so as to create the samenote_idupon every instantiation.If the child’s
note_idis not fixed, a new note will be created upon every instantiation. This is the case for non-singleton subclasses.Params following
child_clsare passed to theNoteandBranchinitializers.- Parameters:
- child_cls: type[BaseDeclarativeNote]
Class of child to instantiate
- class trilium_alchemy.lib.extension_types.BaseThemeNote(title: str | None = None, note_type: str | None = None, mime: str | None = None, *, attributes: collections.abc.Iterable[BaseAttribute] | None = None, parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None, children: collections.abc.Iterable[Note | Branch] | None = None, content: str | bytes | IO | None = None, attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None, note_id: str | None = None, template: Note | type[Note] | None = None, session: Session | None = None, **kwargs)¶
Initialization:
- Parameters:
- title: str | None = None
Note title
- note_type: str | None = None
Note type, default
text; one of:"text","code","relationMap","search","render","book","mermaid","canvas","file","image"- mime: str | None = None
MIME type, default
text/html; needs to be specified only for note types"text","code","file","image"- parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None
Parent note/branch, or iterable of notes/branches (internally modeled as a
set)- children: collections.abc.Iterable[Note | Branch] | None = None
Iterable of child notes/branches (internally modeled as a
list)- attributes: collections.abc.Iterable[BaseAttribute] | None = None
Iterable of attributes (internally modeled as a
list)- content: str | bytes | IO | None = None
Text/binary content or file handle
- attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None
Iterable of attachments (internally modeled as a
list); items may be anAttachment, apathlib.Path, or a binary file handle with a.name- note_id: str | None = None
noteIdto use, will create if it doesn’t exist- template: Note | type[Note] | None = None
Note to set as target of
~templaterelation- session: Session | None = None
Session, or
Noneto use default- kwargs
Internal only
Bases:
trilium_alchemy.lib.note_types.CssNoteAliases:
trilium_alchemy.BaseThemeNote
trilium_alchemy.lib.BaseThemeNoteDefines a theme.
Use
BaseDeclarativeNote.content_fileto set content from file.Adds label:
#appTheme=BaseThemeNote.theme_nameIf
None, defaults to class name
- singleton¶
True
- mime_¶
"text/css"Inherited from:
trilium_alchemy.lib.note_types.CssNote
- icon¶
"bx bxs-file-css"Inherited from:
trilium_alchemy.lib.note_types.CssNote
- note_type_¶
"code"Inherited from:
trilium_alchemy.lib.note_types.CodeNote
- note_id_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNotenote_idto explicitly assign.
- title_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteTitle to set, or
Noneto use class name.
- content_: str | bytes | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteContent to set.
- content_file: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteName of file to use as content, relative to module’s location.
Also adds
#originalFilenamelabel.Note
Currently Trilium only shows
#originalFilenameif the note’s type isfile.
- note_id_seed: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSeed from which to generate
note_id.Useful to generate a collision-avoidant id from a human-friendly identifier. Generated as base64-encoded hash of seed.
- note_id_segment: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSegment with which to generate
note_idgiven the parent’snote_id, if nonote_idis otherwise specified.
- idempotent: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, enables deterministic calculation ofnote_idbased on the class name.Similar to
BaseDeclarativeNote.singleton, but only the class name (not fully qualified) is used.
- idempotent_segment: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, sets segment name to class name for the purpose ofnote_idcalculation.An explicitly provided
BaseDeclarativeNote.note_id_segmenttakes precedence.
- leaf: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set to
Trueon aBaseDeclarativeNotesubclass, disables setting of child notes declaratively, allowing children to be manually maintained by the user. Otherwise, notes added by the user will be deleted to match the children added declaratively.Should be set on notes intended to hold user notes, e.g. todo lists.
- hide_new_note: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteWhether to hide “new note” button, regardless of whether it would otherwise be hidden.
Can be used to hide “new note” button for e.g.
Templateswhich otherwise would show it.
- property note_id_seed_final: str | None¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteGet the seed from which this note’s id was derived.
Useful for debugging.
- property note_id: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
noteId, orNoneif not created yet.
- property title: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property note_type: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property mime: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for MIME type.
- property is_protected: bool¶
Inherited from:
trilium_alchemy.core.note.NoteProtected state, can only be changed in Trilium UI.
- property date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal created datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal modified datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property utc_date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC created datetime, e.g.
2021-12-31 19:18:11.939Z.
- property utc_date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC modified datetime, e.g.
2021-12-31 19:18:11.939Z.
- property attributes: Attributes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attributes, both owned and inherited.
- Setter:
Sets list of owned attributes, replacing the existing list
- property labels: Labels¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property relations: Relations¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property branches: Branches¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for branches, both parents (
.parents) and children (.children).
- property parents: ParentNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for parent notes.
- Setter:
Sets set of parent notes, replacing the existing set
- property children: ChildNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for child notes.
- Setter:
Sets list of child notes, replacing the existing list
- property content: str | bytes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note content.
- property content_str: str¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for text note content.
- property content_bin: bytes¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for binary note content.
- property blob_id: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
blobId, a digest of the note content.
- property attachments: Attachments¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attachments, modeled as a list.
- Setter:
Sets list of attachments, replacing the existing list. Items may be an
Attachment, apathlib.Path, or a binary file handle with a.name.
- property is_string: bool¶
Inherited from:
trilium_alchemy.core.note.NoteTrueif note as it’s currently configured has text content.Mirrors Trilium’s
src/services/utils.js:isStringNote().
- property paths: list[list[Note]]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a list of ancestor notes.
- property paths_str: list[str]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a string like
A > B > C.
- init(attributes: list[BaseAttribute], _: list[Branch])¶
Can be overridden to add attributes and/or children during instantiation. Use the following to create attribute/child with deterministic id:
Note
User should not invoke
super().init(). To add attributes and children in an intuitive order, TriliumAlchemy manually traverses aBaseDeclarativeNotesubclass’s MRO and invokes decorator-patched inits followed byBaseDeclarativeMixin.init.- Parameters:
- attributes: list[BaseAttribute]
List of attributes to which user can append using
BaseDeclarativeMixin.create_declarative_labelorBaseDeclarativeMixin.create_declarative_relation- children
List of children to which user can append using
BaseDeclarativeMixin.create_declarative_child
- get(name: str, default: str | None = None) str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGet value of first label with provided name, or
Noneif no such label exists.
- copy(deep: bool = False) Note¶
Inherited from:
trilium_alchemy.core.note.NoteReturn a copy of this note, including its title, type, MIME, attributes, and content.
If
deepisFalse, child notes are cloned to the returned copy. Otherwise, child notes are recursively deep copied.Note
The returned copy still needs to be placed in the tree hierarchy (added as a child of another note) before
Session.flush()is invoked.
- sync_template(template: Note)¶
Inherited from:
trilium_alchemy.core.note.NoteUpdate this note to match the provided template:
Set note type and MIME
Set content if empty
Recursively deep copy missing child notes, matched by title
- transmute(note_cls: type[NoteT]) NoteT¶
Inherited from:
trilium_alchemy.core.note.NoteChange this note’s base to the provided class and return it.
This is useful for converting a
Noteinstance to a subclass thereof with custom convenience APIs.Note
Has a side effect of committing any changes to this note to Trilium.
- export_zip(dest_file: pathlib.Path, export_format: Literal[html, markdown] = 'html', overwrite: bool = False)¶
Inherited from:
trilium_alchemy.core.note.NoteExport this note subtree to zip file.
- Parameters:
- dest_file: pathlib.Path
Destination .zip file
- export_format: Literal[html, markdown] = 'html'
Format of exported HTML notes
- overwrite: bool = False
Whether to overwrite destination path if it exists
- import_zip(src_file: pathlib.Path) Note¶
Inherited from:
trilium_alchemy.core.note.NoteImport note subtree from zip file, adding the imported root as a child of this note and returning it.
- Parameters:
- src_file: pathlib.Path
Source .zip file
- walk() Generator[Note, None, None]¶
Inherited from:
trilium_alchemy.core.note.NoteYield this note and all children recursively.
Each note will only occur once (clones are skipped).
- flush()¶
Inherited from:
trilium_alchemy.core.note.NoteFlush note along with its owned attributes.
- create_declarative_label(name: str, value: str = '', inheritable: bool = False) Label¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Labelwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_relation(name: str, target: Note, inheritable: bool = False) Relation¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Relationwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_child(child_cls: type[BaseDeclarativeNote], title: str | None = None, note_type: str | None = None, mime: str | None = None, parents: Iterable[Note | Branch] | Note | Branch | None = None, children: Iterable[Note | Branch] | None = None, attributes: Iterable[BaseAttribute] | None = None, content: str | bytes | IO | None = None, template: Note | type[Note] | None = None, prefix: str = '', expanded: bool | None = None) Branch¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreates a child
BaseDeclarativeNotewith deterministicnote_idand returns aBranch. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the same childnote_idupon every instantiation.If the parent note’s
note_idset, the child note will be assigned one so as to create the samenote_idupon every instantiation.If the child’s
note_idis not fixed, a new note will be created upon every instantiation. This is the case for non-singleton subclasses.Params following
child_clsare passed to theNoteandBranchinitializers.- Parameters:
- child_cls: type[BaseDeclarativeNote]
Class of child to instantiate
- class trilium_alchemy.lib.extension_types.BaseWidgetNote(title: str | None = None, note_type: str | None = None, mime: str | None = None, *, attributes: collections.abc.Iterable[BaseAttribute] | None = None, parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None, children: collections.abc.Iterable[Note | Branch] | None = None, content: str | bytes | IO | None = None, attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None, note_id: str | None = None, template: Note | type[Note] | None = None, session: Session | None = None, **kwargs)¶
Initialization:
- Parameters:
- title: str | None = None
Note title
- note_type: str | None = None
Note type, default
text; one of:"text","code","relationMap","search","render","book","mermaid","canvas","file","image"- mime: str | None = None
MIME type, default
text/html; needs to be specified only for note types"text","code","file","image"- parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None
Parent note/branch, or iterable of notes/branches (internally modeled as a
set)- children: collections.abc.Iterable[Note | Branch] | None = None
Iterable of child notes/branches (internally modeled as a
list)- attributes: collections.abc.Iterable[BaseAttribute] | None = None
Iterable of attributes (internally modeled as a
list)- content: str | bytes | IO | None = None
Text/binary content or file handle
- attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None
Iterable of attachments (internally modeled as a
list); items may be anAttachment, apathlib.Path, or a binary file handle with a.name- note_id: str | None = None
noteIdto use, will create if it doesn’t exist- template: Note | type[Note] | None = None
Note to set as target of
~templaterelation- session: Session | None = None
Session, or
Noneto use default- kwargs
Internal only
Bases:
trilium_alchemy.lib.note_types.JsFrontendNoteAliases:
trilium_alchemy.BaseWidgetNote
trilium_alchemy.lib.BaseWidgetNoteDefines a widget.
Added by decorators:
#widget
- singleton¶
True
- mime_¶
"application/javascript;env=frontend"Inherited from:
trilium_alchemy.lib.note_types.JsFrontendNote
- icon¶
"bx bxl-javascript"Inherited from:
trilium_alchemy.lib.note_types.JsFrontendNote
- note_type_¶
"code"Inherited from:
trilium_alchemy.lib.note_types.CodeNote
- note_id_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNotenote_idto explicitly assign.
- title_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteTitle to set, or
Noneto use class name.
- content_: str | bytes | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteContent to set.
- content_file: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteName of file to use as content, relative to module’s location.
Also adds
#originalFilenamelabel.Note
Currently Trilium only shows
#originalFilenameif the note’s type isfile.
- note_id_seed: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSeed from which to generate
note_id.Useful to generate a collision-avoidant id from a human-friendly identifier. Generated as base64-encoded hash of seed.
- note_id_segment: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSegment with which to generate
note_idgiven the parent’snote_id, if nonote_idis otherwise specified.
- idempotent: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, enables deterministic calculation ofnote_idbased on the class name.Similar to
BaseDeclarativeNote.singleton, but only the class name (not fully qualified) is used.
- idempotent_segment: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, sets segment name to class name for the purpose ofnote_idcalculation.An explicitly provided
BaseDeclarativeNote.note_id_segmenttakes precedence.
- leaf: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set to
Trueon aBaseDeclarativeNotesubclass, disables setting of child notes declaratively, allowing children to be manually maintained by the user. Otherwise, notes added by the user will be deleted to match the children added declaratively.Should be set on notes intended to hold user notes, e.g. todo lists.
- hide_new_note: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteWhether to hide “new note” button, regardless of whether it would otherwise be hidden.
Can be used to hide “new note” button for e.g.
Templateswhich otherwise would show it.
- property note_id_seed_final: str | None¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteGet the seed from which this note’s id was derived.
Useful for debugging.
- property note_id: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
noteId, orNoneif not created yet.
- property title: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property note_type: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property mime: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for MIME type.
- property is_protected: bool¶
Inherited from:
trilium_alchemy.core.note.NoteProtected state, can only be changed in Trilium UI.
- property date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal created datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal modified datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property utc_date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC created datetime, e.g.
2021-12-31 19:18:11.939Z.
- property utc_date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC modified datetime, e.g.
2021-12-31 19:18:11.939Z.
- property attributes: Attributes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attributes, both owned and inherited.
- Setter:
Sets list of owned attributes, replacing the existing list
- property labels: Labels¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property relations: Relations¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property branches: Branches¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for branches, both parents (
.parents) and children (.children).
- property parents: ParentNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for parent notes.
- Setter:
Sets set of parent notes, replacing the existing set
- property children: ChildNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for child notes.
- Setter:
Sets list of child notes, replacing the existing list
- property content: str | bytes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note content.
- property content_str: str¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for text note content.
- property content_bin: bytes¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for binary note content.
- property blob_id: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
blobId, a digest of the note content.
- property attachments: Attachments¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attachments, modeled as a list.
- Setter:
Sets list of attachments, replacing the existing list. Items may be an
Attachment, apathlib.Path, or a binary file handle with a.name.
- property is_string: bool¶
Inherited from:
trilium_alchemy.core.note.NoteTrueif note as it’s currently configured has text content.Mirrors Trilium’s
src/services/utils.js:isStringNote().
- property paths: list[list[Note]]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a list of ancestor notes.
- property paths_str: list[str]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a string like
A > B > C.
- get(name: str, default: str | None = None) str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGet value of first label with provided name, or
Noneif no such label exists.
- copy(deep: bool = False) Note¶
Inherited from:
trilium_alchemy.core.note.NoteReturn a copy of this note, including its title, type, MIME, attributes, and content.
If
deepisFalse, child notes are cloned to the returned copy. Otherwise, child notes are recursively deep copied.Note
The returned copy still needs to be placed in the tree hierarchy (added as a child of another note) before
Session.flush()is invoked.
- sync_template(template: Note)¶
Inherited from:
trilium_alchemy.core.note.NoteUpdate this note to match the provided template:
Set note type and MIME
Set content if empty
Recursively deep copy missing child notes, matched by title
- transmute(note_cls: type[NoteT]) NoteT¶
Inherited from:
trilium_alchemy.core.note.NoteChange this note’s base to the provided class and return it.
This is useful for converting a
Noteinstance to a subclass thereof with custom convenience APIs.Note
Has a side effect of committing any changes to this note to Trilium.
- export_zip(dest_file: pathlib.Path, export_format: Literal[html, markdown] = 'html', overwrite: bool = False)¶
Inherited from:
trilium_alchemy.core.note.NoteExport this note subtree to zip file.
- Parameters:
- dest_file: pathlib.Path
Destination .zip file
- export_format: Literal[html, markdown] = 'html'
Format of exported HTML notes
- overwrite: bool = False
Whether to overwrite destination path if it exists
- import_zip(src_file: pathlib.Path) Note¶
Inherited from:
trilium_alchemy.core.note.NoteImport note subtree from zip file, adding the imported root as a child of this note and returning it.
- Parameters:
- src_file: pathlib.Path
Source .zip file
- walk() Generator[Note, None, None]¶
Inherited from:
trilium_alchemy.core.note.NoteYield this note and all children recursively.
Each note will only occur once (clones are skipped).
- flush()¶
Inherited from:
trilium_alchemy.core.note.NoteFlush note along with its owned attributes.
- init(attributes: list[BaseAttribute], children: list[Branch], /)¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCan be overridden to add attributes and/or children during instantiation. Use the following to create attribute/child with deterministic id:
Note
User should not invoke
super().init(). To add attributes and children in an intuitive order, TriliumAlchemy manually traverses aBaseDeclarativeNotesubclass’s MRO and invokes decorator-patched inits followed byBaseDeclarativeMixin.init.- Parameters:
- attributes: list[BaseAttribute]
List of attributes to which user can append using
BaseDeclarativeMixin.create_declarative_labelorBaseDeclarativeMixin.create_declarative_relation- children: list[Branch]
List of children to which user can append using
BaseDeclarativeMixin.create_declarative_child
- create_declarative_label(name: str, value: str = '', inheritable: bool = False) Label¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Labelwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_relation(name: str, target: Note, inheritable: bool = False) Relation¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Relationwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_child(child_cls: type[BaseDeclarativeNote], title: str | None = None, note_type: str | None = None, mime: str | None = None, parents: Iterable[Note | Branch] | Note | Branch | None = None, children: Iterable[Note | Branch] | None = None, attributes: Iterable[BaseAttribute] | None = None, content: str | bytes | IO | None = None, template: Note | type[Note] | None = None, prefix: str = '', expanded: bool | None = None) Branch¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreates a child
BaseDeclarativeNotewith deterministicnote_idand returns aBranch. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the same childnote_idupon every instantiation.If the parent note’s
note_idset, the child note will be assigned one so as to create the samenote_idupon every instantiation.If the child’s
note_idis not fixed, a new note will be created upon every instantiation. This is the case for non-singleton subclasses.Params following
child_clsare passed to theNoteandBranchinitializers.- Parameters:
- child_cls: type[BaseDeclarativeNote]
Class of child to instantiate
- class trilium_alchemy.lib.extension_types.BaseFrontendScriptNote(title: str | None = None, note_type: str | None = None, mime: str | None = None, *, attributes: collections.abc.Iterable[BaseAttribute] | None = None, parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None, children: collections.abc.Iterable[Note | Branch] | None = None, content: str | bytes | IO | None = None, attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None, note_id: str | None = None, template: Note | type[Note] | None = None, session: Session | None = None, **kwargs)¶
Initialization:
- Parameters:
- title: str | None = None
Note title
- note_type: str | None = None
Note type, default
text; one of:"text","code","relationMap","search","render","book","mermaid","canvas","file","image"- mime: str | None = None
MIME type, default
text/html; needs to be specified only for note types"text","code","file","image"- parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None
Parent note/branch, or iterable of notes/branches (internally modeled as a
set)- children: collections.abc.Iterable[Note | Branch] | None = None
Iterable of child notes/branches (internally modeled as a
list)- attributes: collections.abc.Iterable[BaseAttribute] | None = None
Iterable of attributes (internally modeled as a
list)- content: str | bytes | IO | None = None
Text/binary content or file handle
- attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None
Iterable of attachments (internally modeled as a
list); items may be anAttachment, apathlib.Path, or a binary file handle with a.name- note_id: str | None = None
noteIdto use, will create if it doesn’t exist- template: Note | type[Note] | None = None
Note to set as target of
~templaterelation- session: Session | None = None
Session, or
Noneto use default- kwargs
Internal only
Bases:
trilium_alchemy.lib.note_types.JsFrontendNoteAliases:
trilium_alchemy.BaseFrontendScriptNote
trilium_alchemy.lib.BaseFrontendScriptNoteDefines 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.lib.note_types.JsFrontendNote
- icon¶
"bx bxl-javascript"Inherited from:
trilium_alchemy.lib.note_types.JsFrontendNote
- note_type_¶
"code"Inherited from:
trilium_alchemy.lib.note_types.CodeNote
- note_id_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNotenote_idto explicitly assign.
- title_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteTitle to set, or
Noneto use class name.
- content_: str | bytes | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteContent to set.
- content_file: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteName of file to use as content, relative to module’s location.
Also adds
#originalFilenamelabel.Note
Currently Trilium only shows
#originalFilenameif the note’s type isfile.
- note_id_seed: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSeed from which to generate
note_id.Useful to generate a collision-avoidant id from a human-friendly identifier. Generated as base64-encoded hash of seed.
- note_id_segment: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSegment with which to generate
note_idgiven the parent’snote_id, if nonote_idis otherwise specified.
- idempotent: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, enables deterministic calculation ofnote_idbased on the class name.Similar to
BaseDeclarativeNote.singleton, but only the class name (not fully qualified) is used.
- idempotent_segment: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, sets segment name to class name for the purpose ofnote_idcalculation.An explicitly provided
BaseDeclarativeNote.note_id_segmenttakes precedence.
- leaf: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set to
Trueon aBaseDeclarativeNotesubclass, disables setting of child notes declaratively, allowing children to be manually maintained by the user. Otherwise, notes added by the user will be deleted to match the children added declaratively.Should be set on notes intended to hold user notes, e.g. todo lists.
- hide_new_note: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteWhether to hide “new note” button, regardless of whether it would otherwise be hidden.
Can be used to hide “new note” button for e.g.
Templateswhich otherwise would show it.
- property note_id_seed_final: str | None¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteGet the seed from which this note’s id was derived.
Useful for debugging.
- property note_id: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
noteId, orNoneif not created yet.
- property title: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property note_type: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property mime: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for MIME type.
- property is_protected: bool¶
Inherited from:
trilium_alchemy.core.note.NoteProtected state, can only be changed in Trilium UI.
- property date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal created datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal modified datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property utc_date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC created datetime, e.g.
2021-12-31 19:18:11.939Z.
- property utc_date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC modified datetime, e.g.
2021-12-31 19:18:11.939Z.
- property attributes: Attributes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attributes, both owned and inherited.
- Setter:
Sets list of owned attributes, replacing the existing list
- property labels: Labels¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property relations: Relations¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property branches: Branches¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for branches, both parents (
.parents) and children (.children).
- property parents: ParentNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for parent notes.
- Setter:
Sets set of parent notes, replacing the existing set
- property children: ChildNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for child notes.
- Setter:
Sets list of child notes, replacing the existing list
- property content: str | bytes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note content.
- property content_str: str¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for text note content.
- property content_bin: bytes¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for binary note content.
- property blob_id: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
blobId, a digest of the note content.
- property attachments: Attachments¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attachments, modeled as a list.
- Setter:
Sets list of attachments, replacing the existing list. Items may be an
Attachment, apathlib.Path, or a binary file handle with a.name.
- property is_string: bool¶
Inherited from:
trilium_alchemy.core.note.NoteTrueif note as it’s currently configured has text content.Mirrors Trilium’s
src/services/utils.js:isStringNote().
- property paths: list[list[Note]]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a list of ancestor notes.
- property paths_str: list[str]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a string like
A > B > C.
- get(name: str, default: str | None = None) str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGet value of first label with provided name, or
Noneif no such label exists.
- copy(deep: bool = False) Note¶
Inherited from:
trilium_alchemy.core.note.NoteReturn a copy of this note, including its title, type, MIME, attributes, and content.
If
deepisFalse, child notes are cloned to the returned copy. Otherwise, child notes are recursively deep copied.Note
The returned copy still needs to be placed in the tree hierarchy (added as a child of another note) before
Session.flush()is invoked.
- sync_template(template: Note)¶
Inherited from:
trilium_alchemy.core.note.NoteUpdate this note to match the provided template:
Set note type and MIME
Set content if empty
Recursively deep copy missing child notes, matched by title
- transmute(note_cls: type[NoteT]) NoteT¶
Inherited from:
trilium_alchemy.core.note.NoteChange this note’s base to the provided class and return it.
This is useful for converting a
Noteinstance to a subclass thereof with custom convenience APIs.Note
Has a side effect of committing any changes to this note to Trilium.
- export_zip(dest_file: pathlib.Path, export_format: Literal[html, markdown] = 'html', overwrite: bool = False)¶
Inherited from:
trilium_alchemy.core.note.NoteExport this note subtree to zip file.
- Parameters:
- dest_file: pathlib.Path
Destination .zip file
- export_format: Literal[html, markdown] = 'html'
Format of exported HTML notes
- overwrite: bool = False
Whether to overwrite destination path if it exists
- import_zip(src_file: pathlib.Path) Note¶
Inherited from:
trilium_alchemy.core.note.NoteImport note subtree from zip file, adding the imported root as a child of this note and returning it.
- Parameters:
- src_file: pathlib.Path
Source .zip file
- walk() Generator[Note, None, None]¶
Inherited from:
trilium_alchemy.core.note.NoteYield this note and all children recursively.
Each note will only occur once (clones are skipped).
- flush()¶
Inherited from:
trilium_alchemy.core.note.NoteFlush note along with its owned attributes.
- init(attributes: list[BaseAttribute], children: list[Branch], /)¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCan be overridden to add attributes and/or children during instantiation. Use the following to create attribute/child with deterministic id:
Note
User should not invoke
super().init(). To add attributes and children in an intuitive order, TriliumAlchemy manually traverses aBaseDeclarativeNotesubclass’s MRO and invokes decorator-patched inits followed byBaseDeclarativeMixin.init.- Parameters:
- attributes: list[BaseAttribute]
List of attributes to which user can append using
BaseDeclarativeMixin.create_declarative_labelorBaseDeclarativeMixin.create_declarative_relation- children: list[Branch]
List of children to which user can append using
BaseDeclarativeMixin.create_declarative_child
- create_declarative_label(name: str, value: str = '', inheritable: bool = False) Label¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Labelwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_relation(name: str, target: Note, inheritable: bool = False) Relation¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Relationwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_child(child_cls: type[BaseDeclarativeNote], title: str | None = None, note_type: str | None = None, mime: str | None = None, parents: Iterable[Note | Branch] | Note | Branch | None = None, children: Iterable[Note | Branch] | None = None, attributes: Iterable[BaseAttribute] | None = None, content: str | bytes | IO | None = None, template: Note | type[Note] | None = None, prefix: str = '', expanded: bool | None = None) Branch¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreates a child
BaseDeclarativeNotewith deterministicnote_idand returns aBranch. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the same childnote_idupon every instantiation.If the parent note’s
note_idset, the child note will be assigned one so as to create the samenote_idupon every instantiation.If the child’s
note_idis not fixed, a new note will be created upon every instantiation. This is the case for non-singleton subclasses.Params following
child_clsare passed to theNoteandBranchinitializers.- Parameters:
- child_cls: type[BaseDeclarativeNote]
Class of child to instantiate
- class trilium_alchemy.lib.extension_types.BaseBackendScriptNote(title: str | None = None, note_type: str | None = None, mime: str | None = None, *, attributes: collections.abc.Iterable[BaseAttribute] | None = None, parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None, children: collections.abc.Iterable[Note | Branch] | None = None, content: str | bytes | IO | None = None, attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None, note_id: str | None = None, template: Note | type[Note] | None = None, session: Session | None = None, **kwargs)¶
Initialization:
- Parameters:
- title: str | None = None
Note title
- note_type: str | None = None
Note type, default
text; one of:"text","code","relationMap","search","render","book","mermaid","canvas","file","image"- mime: str | None = None
MIME type, default
text/html; needs to be specified only for note types"text","code","file","image"- parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None
Parent note/branch, or iterable of notes/branches (internally modeled as a
set)- children: collections.abc.Iterable[Note | Branch] | None = None
Iterable of child notes/branches (internally modeled as a
list)- attributes: collections.abc.Iterable[BaseAttribute] | None = None
Iterable of attributes (internally modeled as a
list)- content: str | bytes | IO | None = None
Text/binary content or file handle
- attachments: collections.abc.Iterable[Attachment | pathlib.Path | IO[bytes]] | None = None
Iterable of attachments (internally modeled as a
list); items may be anAttachment, apathlib.Path, or a binary file handle with a.name- note_id: str | None = None
noteIdto use, will create if it doesn’t exist- template: Note | type[Note] | None = None
Note to set as target of
~templaterelation- session: Session | None = None
Session, or
Noneto use default- kwargs
Internal only
Bases:
trilium_alchemy.lib.note_types.JsBackendNoteAliases:
trilium_alchemy.BaseBackendScriptNote
trilium_alchemy.lib.BaseBackendScriptNoteDefines 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.lib.note_types.JsBackendNote
- icon¶
"bx bxl-javascript"Inherited from:
trilium_alchemy.lib.note_types.JsBackendNote
- note_type_¶
"code"Inherited from:
trilium_alchemy.lib.note_types.CodeNote
- note_id_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNotenote_idto explicitly assign.
- title_: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteTitle to set, or
Noneto use class name.
- content_: str | bytes | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteContent to set.
- content_file: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteName of file to use as content, relative to module’s location.
Also adds
#originalFilenamelabel.Note
Currently Trilium only shows
#originalFilenameif the note’s type isfile.
- note_id_seed: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSeed from which to generate
note_id.Useful to generate a collision-avoidant id from a human-friendly identifier. Generated as base64-encoded hash of seed.
- note_id_segment: str | None¶
NoneInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteSegment with which to generate
note_idgiven the parent’snote_id, if nonote_idis otherwise specified.
- idempotent: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, enables deterministic calculation ofnote_idbased on the class name.Similar to
BaseDeclarativeNote.singleton, but only the class name (not fully qualified) is used.
- idempotent_segment: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set on a
BaseDeclarativeNotesubclass, sets segment name to class name for the purpose ofnote_idcalculation.An explicitly provided
BaseDeclarativeNote.note_id_segmenttakes precedence.
- leaf: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteIf set to
Trueon aBaseDeclarativeNotesubclass, disables setting of child notes declaratively, allowing children to be manually maintained by the user. Otherwise, notes added by the user will be deleted to match the children added declaratively.Should be set on notes intended to hold user notes, e.g. todo lists.
- hide_new_note: bool¶
FalseInherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteWhether to hide “new note” button, regardless of whether it would otherwise be hidden.
Can be used to hide “new note” button for e.g.
Templateswhich otherwise would show it.
- property note_id_seed_final: str | None¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeNoteGet the seed from which this note’s id was derived.
Useful for debugging.
- property note_id: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
noteId, orNoneif not created yet.
- property title: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property note_type: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note title.
- property mime: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for MIME type.
- property is_protected: bool¶
Inherited from:
trilium_alchemy.core.note.NoteProtected state, can only be changed in Trilium UI.
- property date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal created datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteLocal modified datetime, e.g.
2021-12-31 20:18:11.939+0100.
- property utc_date_created: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC created datetime, e.g.
2021-12-31 19:18:11.939Z.
- property utc_date_modified: str | None¶
Inherited from:
trilium_alchemy.core.note.NoteUTC modified datetime, e.g.
2021-12-31 19:18:11.939Z.
- property attributes: Attributes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attributes, both owned and inherited.
- Setter:
Sets list of owned attributes, replacing the existing list
- property labels: Labels¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property relations: Relations¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for labels, accessed as combined list or filtered by owned vs inherited.
- property branches: Branches¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for branches, both parents (
.parents) and children (.children).
- property parents: ParentNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for parent notes.
- Setter:
Sets set of parent notes, replacing the existing set
- property children: ChildNotes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for child notes.
- Setter:
Sets list of child notes, replacing the existing list
- property content: str | bytes¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for note content.
- property content_str: str¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for text note content.
- property content_bin: bytes¶
Inherited from:
trilium_alchemy.core.note.NoteType-safe getter/setter for binary note content.
- property blob_id: str¶
Inherited from:
trilium_alchemy.core.note.NoteGetter for
blobId, a digest of the note content.
- property attachments: Attachments¶
Inherited from:
trilium_alchemy.core.note.NoteGetter/setter for attachments, modeled as a list.
- Setter:
Sets list of attachments, replacing the existing list. Items may be an
Attachment, apathlib.Path, or a binary file handle with a.name.
- property is_string: bool¶
Inherited from:
trilium_alchemy.core.note.NoteTrueif note as it’s currently configured has text content.Mirrors Trilium’s
src/services/utils.js:isStringNote().
- property paths: list[list[Note]]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a list of ancestor notes.
- property paths_str: list[str]¶
Inherited from:
trilium_alchemy.core.note.NoteGet list of paths to this note, where each path is a string like
A > B > C.
- get(name: str, default: str | None = None) str | None¶
Inherited from:
trilium_alchemy.core.note.NoteGet value of first label with provided name, or
Noneif no such label exists.
- copy(deep: bool = False) Note¶
Inherited from:
trilium_alchemy.core.note.NoteReturn a copy of this note, including its title, type, MIME, attributes, and content.
If
deepisFalse, child notes are cloned to the returned copy. Otherwise, child notes are recursively deep copied.Note
The returned copy still needs to be placed in the tree hierarchy (added as a child of another note) before
Session.flush()is invoked.
- sync_template(template: Note)¶
Inherited from:
trilium_alchemy.core.note.NoteUpdate this note to match the provided template:
Set note type and MIME
Set content if empty
Recursively deep copy missing child notes, matched by title
- transmute(note_cls: type[NoteT]) NoteT¶
Inherited from:
trilium_alchemy.core.note.NoteChange this note’s base to the provided class and return it.
This is useful for converting a
Noteinstance to a subclass thereof with custom convenience APIs.Note
Has a side effect of committing any changes to this note to Trilium.
- export_zip(dest_file: pathlib.Path, export_format: Literal[html, markdown] = 'html', overwrite: bool = False)¶
Inherited from:
trilium_alchemy.core.note.NoteExport this note subtree to zip file.
- Parameters:
- dest_file: pathlib.Path
Destination .zip file
- export_format: Literal[html, markdown] = 'html'
Format of exported HTML notes
- overwrite: bool = False
Whether to overwrite destination path if it exists
- import_zip(src_file: pathlib.Path) Note¶
Inherited from:
trilium_alchemy.core.note.NoteImport note subtree from zip file, adding the imported root as a child of this note and returning it.
- Parameters:
- src_file: pathlib.Path
Source .zip file
- walk() Generator[Note, None, None]¶
Inherited from:
trilium_alchemy.core.note.NoteYield this note and all children recursively.
Each note will only occur once (clones are skipped).
- flush()¶
Inherited from:
trilium_alchemy.core.note.NoteFlush note along with its owned attributes.
- init(attributes: list[BaseAttribute], children: list[Branch], /)¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCan be overridden to add attributes and/or children during instantiation. Use the following to create attribute/child with deterministic id:
Note
User should not invoke
super().init(). To add attributes and children in an intuitive order, TriliumAlchemy manually traverses aBaseDeclarativeNotesubclass’s MRO and invokes decorator-patched inits followed byBaseDeclarativeMixin.init.- Parameters:
- attributes: list[BaseAttribute]
List of attributes to which user can append using
BaseDeclarativeMixin.create_declarative_labelorBaseDeclarativeMixin.create_declarative_relation- children: list[Branch]
List of children to which user can append using
BaseDeclarativeMixin.create_declarative_child
- create_declarative_label(name: str, value: str = '', inheritable: bool = False) Label¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Labelwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_relation(name: str, target: Note, inheritable: bool = False) Relation¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreate and return a
Relationwith deterministicattribute_idbased on itsnameand note’snote_id. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the sameattribute_idupon every instantiation.Multiple attributes of the same name are supported.
- create_declarative_child(child_cls: type[BaseDeclarativeNote], title: str | None = None, note_type: str | None = None, mime: str | None = None, parents: Iterable[Note | Branch] | Note | Branch | None = None, children: Iterable[Note | Branch] | None = None, attributes: Iterable[BaseAttribute] | None = None, content: str | bytes | IO | None = None, template: Note | type[Note] | None = None, prefix: str = '', expanded: bool | None = None) Branch¶
Inherited from:
trilium_alchemy.core.declarative.BaseDeclarativeMixinCreates a child
BaseDeclarativeNotewith deterministicnote_idand returns aBranch. Should be used in subclassedBaseDeclarativeNote.initorBaseDeclarativeMixin.initto generate the same childnote_idupon every instantiation.If the parent note’s
note_idset, the child note will be assigned one so as to create the samenote_idupon every instantiation.If the child’s
note_idis not fixed, a new note will be created upon every instantiation. This is the case for non-singleton subclasses.Params following
child_clsare passed to theNoteandBranchinitializers.- Parameters:
- child_cls: type[BaseDeclarativeNote]
Class of child to instantiate