labapi.entry.entries.attachment.AttachmentEntry#

class labapi.entry.entries.attachment.AttachmentEntry(
eid: str,
caption: str,
user: User,
*,
created_at: datetime | None = None,
updated_at: datetime | None = None,
version: int | None = None,
)[source]#

Bases: Entry[Attachment]

Represents an attachment entry on a LabArchives page.

This class handles the retrieval and updating of file attachments, providing access to the attachment’s content, filename, and caption.

__init__(
eid: str,
caption: str,
user: User,
*,
created_at: datetime | None = None,
updated_at: datetime | None = None,
version: int | None = None,
)[source]#

Initialize an attachment entry.

Parameters:
  • eid – The unique ID of the entry.

  • caption – The caption associated with the attachment.

  • user – The authenticated user.

Methods

__init__(eid, caption, user, *[, ...])

Initialize an attachment entry.

class_of(part_type)

Return the registered entry class for part_type.

from_part_type(part_type, eid, data, user, *)

Create an entry instance for a LabArchives part type.

get_attachment([use_tempfile])

Return the attachment payload as an independent stream copy.

is_registered(part_type)

Return whether an entry class is registered for part_type.

Attributes

caption

Return the attachment caption.

content

Return the attachment content.

content_type

Return the LabArchives content type identifier for this entry.

created_at

Return when this entry was created, if supplied by the API.

id

Return the unique identifier of the entry.

updated_at

Return when this entry was last updated, if supplied by the API.

version

Return this entry's API version number, if supplied by the API.

get_attachment(
use_tempfile: bool = False,
) Attachment[source]#

Return the attachment payload as an independent stream copy.

The attachment data is fetched from the LabArchives API on first call and cached.

Parameters:

use_tempfile – If True, the attachment data will be stored in a temporary file; otherwise, in an in-memory BytesIO object. Defaults to False.

Returns:

An Attachment object containing the file data and metadata.

property content: Attachment#

Return the attachment content.

This property retrieves the attachment data, caching it for subsequent access.

Returns:

The attachment object.

property caption: str#

Return the attachment caption.

Returns:

The caption string.

static class_of(
part_type: str,
) type[Entry[Any]]#

Return the registered entry class for part_type.

Parameters:

part_type – The LabArchives part type identifier.

Returns:

The Entry subclass registered for this part type.

Raises:

KeyError – If no class is registered for the specified part type.

property content_type: str#

Return the LabArchives content type identifier for this entry.

Returns:

A string representing the entry’s type (e.g., “text entry”, “Attachment”).

property created_at: datetime | None#

Return when this entry was created, if supplied by the API.

static from_part_type(
part_type: str,
eid: str,
data: str,
user: User,
*,
created_at: datetime | None = None,
updated_at: datetime | None = None,
version: int | None = None,
) Entry[Any]#

Create an entry instance for a LabArchives part type.

This method takes a part type string and returns the corresponding entry class instance when one is registered. Recognized-but-unimplemented part types resolve to UnimplementedEntry, while truly unknown part types fall back to UnknownEntry.

Parameters:
  • part_type – The type of entry to create (e.g., “heading”, “text entry”, “plain text entry”, “attachment”, “widget entry”).

  • eid – The unique ID of the entry.

  • data – The entry data. For text-based entries, this is the text content. For attachment entries, this is the caption.

  • user – The authenticated user associated with this entry.

  • created_at – When the entry was created, if supplied by the API.

  • updated_at – When the entry was last updated, if supplied by the API.

  • version – The entry’s API version number, if supplied by the API.

Returns:

An entry instance of the appropriate type.

property id: str#

Return the unique identifier of the entry.

Returns:

The entry’s ID as a string.

static is_registered(part_type: str) bool#

Return whether an entry class is registered for part_type.

Parameters:

part_type – The LabArchives part type identifier to check.

Returns:

True if a class is registered for this part type, False otherwise.

property updated_at: datetime | None#

Return when this entry was last updated, if supplied by the API.

property version: int | None#

Return this entry’s API version number, if supplied by the API.