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
Note title
- note_type
Note type, default
text; one of:"text","code","relationMap","search","render","book","mermaid","canvas","file","image"- mime
MIME type, default
text/html; needs to be specified only for note types"text","code","file","image"- parents
Parent note/branch, or iterable of notes/branches (internally modeled as a
set)- children
Iterable of child notes/branches (internally modeled as a
list)- attributes
Iterable of attributes (internally modeled as a
list)- content
Text/binary content or file handle
- attachments
Iterable of attachments (internally modeled as a
list); items may be anAttachment, apathlib.Path, or a binary file handle with a.name- note_id
noteIdto use, will create if it doesn’t exist- template
Note to set as target of
~templaterelation- session
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.
- property state: State¶
Inherited from:
trilium_alchemy.core.entity.BaseEntityCurrent state.
- property session: Session¶
Inherited from:
trilium_alchemy.core.entity.BaseEntitySession to which this entity belongs.
- property str_short: str¶
Inherited from:
trilium_alchemy.core.entity.BaseEntityGet a short description of this entity.
- property str_summary: str¶
Inherited from:
trilium_alchemy.core.entity.BaseEntityGet a summary of this entity, including its current state and model values.
- 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
Destination .zip file
- export_format
Format of exported HTML notes
- overwrite
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
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.
- invalidate()¶
Inherited from:
trilium_alchemy.core.entity.BaseEntityDiscard cached contents and user-provided data for this object.
Upon next access, data will be fetched from Trilium.
- delete()¶
Inherited from:
trilium_alchemy.core.entity.BaseEntityMark this entity for pending delete.
- refresh()¶
Inherited from:
trilium_alchemy.core.entity.BaseEntityUpdate value from Trilium, discarding any local changes.