trilium_alchemy.core.note

Class index

Canonical

Note

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 note_id: str | None

Getter for noteId, or None if not created yet.

property title: str

Getter/setter for note title.

property note_type: str

Getter/setter for note title.

property mime: str

Getter/setter for MIME type.

property is_protected: bool

Protected state, can only be changed in Trilium UI.

property date_created: str

Local created datetime, e.g. 2021-12-31 20:18:11.939+0100.

property date_modified: str

Local modified datetime, e.g. 2021-12-31 20:18:11.939+0100.

property utc_date_created: str

UTC created datetime, e.g. 2021-12-31 19:18:11.939Z.

property utc_date_modified: str

UTC modified datetime, e.g. 2021-12-31 19:18:11.939Z.

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 branches: Branches

Getter/setter for branches, both parent and child.

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 content: str | bytes

Getter/setter for note content.

property content_str: str

Type-safe getter/setter for text note content.

property content_bin: bytes

Type-safe getter/setter for binary note content.

property blob_id: str

Getter for blobId, a digest of the note content.

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 is False, 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.