Attachment#
- class nominal.core.Attachment(rid, name, description, properties, labels, created_at, is_archived)#
Bases:
HasRid,RefreshableGrpcMixin[Attachment]An uploaded file that can be attached to assets or runs.
- created_at: IntegralNanosecondsUTC#
- archive()#
Archive this attachment. Archived attachments are not deleted, but are hidden from the UI.
Refreshes this instance from the update response without an additional fetch.
- Raises:
NominalError – If the archive request fails.
- get_contents()#
Retrieve the contents of this attachment. Returns a file-like object in binary mode for reading.
The contents are streamed from object storage through a short-lived presigned URI, the same storage that attachment uploads are written to. Close the returned stream when finished, e.g. with a
withblock.- Raises:
NominalError – If the download URI cannot be retrieved.
requests.RequestException – If downloading the contents fails.
- Return type:
- unarchive()#
Unarchive this attachment, allowing it to be viewed in the UI.
Refreshes this instance from the update response without an additional fetch.
- Raises:
NominalError – If the unarchive request fails.
- update(*, name=None, description=None, properties=None, labels=None, is_archived=None)#
Replace attachment metadata. Updates the current instance, and returns it.
None leaves a field unchanged. Updates refresh this instance from the response; when no fields are supplied, fetch the latest attachment instead.
- Parameters:
name (str | None)
Replacement name.
description (str | None)
Replacement description. An empty string clears it.
properties (Mapping[str, str] | None)
Replacement properties. An empty mapping clears them.
-
Replacement labels. An empty sequence clears them.
is_archived (bool | None)
True archives the attachment; False restores it.
- Returns:
This instance with refreshed metadata.
- Return type:
Note
This replaces the metadata rather than appending it. To append to labels or properties, merge them before calling this method. E.g.:
new_labels = ["new-label-a", "new-label-b", *attachment.labels] attachment = attachment.update(labels=new_labels)
- Raises:
NominalError – If the update request fails.
- Return type:
- write(path, mkdir=True)#
Write an attachment to the filesystem.
pathshould be the path you want to save to, i.e. a file, not a directory.