trilium_alchemy.core.note
¶
Class index¶
Canonical
Encapsulates a note. Can be subclassed for custom attribute accessors. |
Symbols¶
- class trilium_alchemy.core.note.Note(title: str | None = None, note_type: str | None = None, mime: str | None = None, parents: collections.abc.Iterable[Note | Branch] | Note | Branch | None = None, children: collections.abc.Iterable[Note | Branch] | None = None, attributes: collections.abc.Iterable[BaseAttribute] | None = None, content: str | bytes | IO | None = None, note_id: str | None = None, template: Note | type[Note] | None = None, session: Session | None = None, **kwargs)¶
- Parameters:
- title: str | None = None
Note title
- note_type: str | None = None
Note type, default
text
; one of:"text"
,"code"
,"file"
,"image"
,"search"
,"book"
,"relationMap"
,"render"
- mime: str | None = None
MIME type, default
text/html
; needs to be specified only for note types"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
- note_id: str | None = None
noteId
to use, will create if it doesn’t exist- template: Note | type[Note] | None = None
Note to set as target of
~template
relation- session: Session | None = None
Session, or
None
to use default- kwargs
Internal only
Bases:
trilium_alchemy.core.entity.BaseEntity
Aliases:
trilium_alchemy.Note
trilium_alchemy.core.Note
Encapsulates 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 parent notes, replacing the existing list
- property is_string: bool¶
True
if 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.BaseEntity
Current state.
- property session: Session¶
Inherited from:
trilium_alchemy.core.entity.BaseEntity
Session to which this entity belongs.
- property str_short: str¶
Inherited from:
trilium_alchemy.core.entity.BaseEntity
Get a short description of this entity.
- property str_summary: str¶
Inherited from:
trilium_alchemy.core.entity.BaseEntity
Get 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
None
if no such label exists.
- copy(deep: bool = False) Note ¶
Return a copy of this note, including its title, type, MIME, attributes, and content.
If
deep
isFalse
, 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
Note
instance 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_path: pathlib.Path, export_format: Literal[html, markdown] = 'html')¶
Export this note subtree to zip file.
- Parameters:
- dest_path: pathlib.Path
Destination .zip file
- export_format: Literal[html, markdown] = 'html'
Format of exported HTML notes
- import_zip(src_path: pathlib.Path) Note ¶
Import note subtree from zip file, adding the imported root as a child of this note and returning it.
- Parameters:
- src_path: pathlib.Path
Source .zip file
- flush()¶
Flush note along with its owned attributes.
- invalidate()¶
Inherited from:
trilium_alchemy.core.entity.BaseEntity
Discard 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.BaseEntity
Mark this entity for pending delete.
- refresh()¶
Inherited from:
trilium_alchemy.core.entity.BaseEntity
Update value from Trilium, discarding any local changes.