AttachmentClient¶
- class opik.api_objects.attachment.client.AttachmentClient(rest_client: OpikApi, url_override: str, workspace_name: str)¶
Bases:
object
Client for interacting with attachment-related operations.
This client provides methods to retrieve attachment lists, download attachments, and upload attachments for traces and spans.
The AttachmentClient supports: - Listing attachments associated with traces or spans - Downloading attachment content as a byte stream - Uploading files as attachments to traces or spans
All operations are performed within the context of a specific project and require the project name to be provided.
- __init__(rest_client: OpikApi, url_override: str, workspace_name: str) None ¶
Initialize the AttachmentClient. It is typically created via
Opik.get_attachment_client()
rather than being instantiated directly.- Parameters:
rest_client – The REST API client instance for making backend requests.
url_override – The base URL for the Opik server.
workspace_name – The workspace name used for download operations.
- Returns:
None
- get_attachment_list(project_name: str, entity_id: str, entity_type: Literal['span', 'trace']) List[Attachment] ¶
Get a list of attachments for a specific entity (trace or span).
- Parameters:
project_name – The name of the project containing the entity.
entity_id – The ID of the trace or span to retrieve attachments for.
entity_type – The type of entity (“trace” or “span”).
- Returns:
List of attachment detail objects containing metadata about each attachment.
- Return type:
List[RESTAttachmentDetails]
- download_attachment(project_name: str, entity_type: Literal['trace', 'span'], entity_id: str, file_name: str, mime_type: str) Iterator[bytes] ¶
Download an attachment as a stream of bytes.
- Parameters:
project_name – The name of the project containing the entity.
entity_type – The type of entity (“trace” or “span”).
entity_id – The ID of the trace or span containing the attachment.
file_name – The name of the file to download.
mime_type – The MIME type of the file.
- Returns:
Iterator yielding bytes of the attachment content.
- Return type:
Iterator[bytes]
- upload_attachment(project_name: str, entity_type: Literal['trace', 'span'], entity_id: str, file_path: str, file_name: str | None = None, mime_type: str | None = None) None ¶
Upload an attachment for a specific entity (trace or span).
- Parameters:
project_name – The name of the project containing the entity.
entity_type – The type of entity (“trace” or “span”).
entity_id – The ID of the trace or span to attach the file to.
file_path – The path to the file to upload on the local filesystem.
file_name – The name to assign to the uploaded file. If not provided, uses the basename of file_path.
mime_type – The MIME type of the file. If not provided, attempts to automatically detect based on the file extension.
- Returns:
None