trilium_alchemy.core.note.attachments

Class index

Canonical

Attachment

Encapsulates an attachment, a named binary blob owned by a Note.

Attachments

Interface to a note’s attachments, modeled as a list.

Symbols

class trilium_alchemy.core.note.attachments.Attachment(content: bytes | IO[bytes] | pathlib.Path | None = None, *, title: str | None = None, role: str = 'image', mime: str | None = None, session: Session | None = None, **kwargs)

Bases:

trilium_alchemy.core.entity.entity.OrderedEntity

Aliases:

trilium_alchemy.Attachment
trilium_alchemy.core.Attachment
trilium_alchemy.core.note.Attachment

Encapsulates an attachment, a named binary blob owned by a Note.

Trilium only supports image attachments.

Add to a note using its Note.attachments list. An attachment can be created from raw bytes (requires a title), a pathlib.Path, or a binary file handle:

note.attachments = [
    Attachment(title="image.png", content=b"..."),
    Path("image.png"),
    open("image.png", "rb"),
]
property attachment_id: str | None

Getter for attachmentId, or None if not created yet.

property note: Note

Getter for note which owns this attachment.

Raises:

ValueError – If note has not been set

property role: str

Getter/setter for attachment role, e.g. "image".

property mime: str

Getter/setter for MIME type.

property title: str

Getter/setter for attachment title.

property content: bytes

Getter/setter for attachment content as bytes.

property blob_id: str

Getter for blobId, a digest of the attachment content.

property utc_date_modified: str | None

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

property position: int

Getter for position of this attachment.

Note

This is maintained automatically based on the order of this attachment in its note’s Note.attachments list.

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.

save(path: str | pathlib.Path)

Write attachment content to the provided path.

flush()

Inherited from: trilium_alchemy.core.entity.BaseEntity

Commit changes to Trilium for this entity and its dependencies.

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.

class trilium_alchemy.core.note.attachments.Attachments(entity: BaseEntity)

Bases:

trilium_alchemy.core.note.extension.BaseEntityList

Interface to a note’s attachments, modeled as a list.

Items assigned may be an Attachment, a pathlib.Path, or a binary file handle with a .name. Raw bytes is not accepted here since a title can’t be derived; construct an Attachment explicitly with a title instead.

insert(index: int, value: Any)

S.insert(index, value) – insert value before index

append(value)

Inherited from: collections.abc.MutableSequence

S.append(value) – append value to the end of the sequence

clear()

Inherited from: collections.abc.MutableSequence

S.clear() -> None – remove all items from S

reverse()

Inherited from: collections.abc.MutableSequence

S.reverse() – reverse IN PLACE

extend(values)

Inherited from: collections.abc.MutableSequence

S.extend(iterable) – extend sequence by appending elements from the iterable

pop(index=-1)

Inherited from: collections.abc.MutableSequence

S.pop([index]) -> item – remove and return item at index (default last). Raise IndexError if list is empty or index is out of range.

remove(value)

Inherited from: collections.abc.MutableSequence

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

index(value, start=0, stop=None)

Inherited from: collections.abc.Sequence

S.index(value, [start, [stop]]) -> integer – return first index of value. Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

count(value)

Inherited from: collections.abc.Sequence

S.count(value) -> integer – return number of occurrences of value