trilium_alchemy.core.note¶
Class index¶
Canonical
Encapsulates a note. |
Imported
Encapsulates an attachment, a named binary blob owned by a |
Symbols¶
- class trilium_alchemy.core.note.Note(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.core.entity.BaseEntityAliases:
trilium_alchemy.Note
trilium_alchemy.core.NoteEncapsulates a note.
Can be subclassed for custom attribute accessors. For a detailed walkthrough of how to use this class, see Working with notes.
- property attributes: Attributes¶
Getter/setter for attributes, both owned and inherited.
- Setter:
Sets list of owned attributes, replacing the existing list
- property labels: Labels¶
Getter for labels, accessed as combined list or filtered by owned vs inherited.
- property relations: Relations¶
Getter for labels, accessed as combined list or filtered by owned vs inherited.
- property parents: ParentNotes¶
Getter/setter for parent notes.
- Setter:
Sets set of parent notes, replacing the existing set
- property children: ChildNotes¶
Getter/setter for child notes.
- Setter:
Sets list of child notes, replacing the existing list
- property attachments: Attachments¶
Getter/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¶
Trueif note as it’s currently configured has text content.Mirrors Trilium’s
src/services/utils.js:isStringNote().
- property paths: list[list[Note]]¶
Get list of paths to this note, where each path is a list of ancestor notes.
- property paths_str: list[str]¶
Get 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¶
Get value of first label with provided name, or
Noneif no such label exists.
- copy(deep: bool = False) Note¶
Return 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)¶
Update 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¶
Change 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)¶
Export 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¶
Import 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]¶
Yield this note and all children recursively.
Each note will only occur once (clones are skipped).
- flush()¶
Flush note along with its owned attributes.