Attachments Client¶
The Attachments client provides methods for managing file attachments in the Opik platform.
- class opik.rest_api.attachments.client.AttachmentsClient(*, client_wrapper: SyncClientWrapper)¶
Bases:
object
- attachment_list(*, project_id: str, entity_type: Literal['trace', 'span'] | Any, entity_id: str, path: str, page: int | None = None, size: int | None = None, request_options: RequestOptions | None = None) AttachmentPage ¶
Attachments list for entity
- Parameters:
project_id (str)
entity_type (AttachmentListRequestEntityType)
entity_id (str)
path (str)
page (Optional[int])
size (Optional[int])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
Attachment Resource
- Return type:
Examples
from Opik import OpikApi client = OpikApi(api_key=”YOUR_API_KEY”, workspace_name=”YOUR_WORKSPACE_NAME”, ) client.attachments.attachment_list(project_id=’project_id’, entity_type=”trace”, entity_id=’entity_id’, path=’path’, )
- complete_multi_part_upload(*, file_name: str, entity_type: Literal['trace', 'span'] | Any, entity_id: str, file_size: int, upload_id: str, uploaded_file_parts: Sequence[MultipartUploadPart], project_name: str | None = OMIT, container_id: str | None = OMIT, mime_type: str | None = OMIT, request_options: RequestOptions | None = None) None ¶
Complete multipart attachment upload
- Parameters:
file_name (str)
entity_type (CompleteMultipartUploadRequestEntityType)
entity_id (str)
file_size (int)
upload_id (str)
uploaded_file_parts (Sequence[MultipartUploadPart])
project_name (Optional[str]) – If null, the default project is used
container_id (Optional[str])
mime_type (Optional[str])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Return type:
None
Examples
from Opik import OpikApi from Opik import MultipartUploadPart client = OpikApi(api_key=”YOUR_API_KEY”, workspace_name=”YOUR_WORKSPACE_NAME”, ) client.attachments.complete_multi_part_upload(file_name=’file_name’, entity_type=”trace”, entity_id=’entity_id’, file_size=1000000, upload_id=’upload_id’, uploaded_file_parts=[MultipartUploadPart(e_tag=’e_tag’, part_number=1, )], )
- delete_attachments(*, file_name: str, entity_type: Literal['trace', 'span'] | Any, entity_id: str, file_size: int, upload_id: str, uploaded_file_parts: Sequence[MultipartUploadPart], project_name: str | None = OMIT, container_id: str | None = OMIT, mime_type: str | None = OMIT, request_options: RequestOptions | None = None) None ¶
Delete attachments
- Parameters:
file_name (str)
entity_type (CompleteMultipartUploadRequestEntityType)
entity_id (str)
file_size (int)
upload_id (str)
uploaded_file_parts (Sequence[MultipartUploadPart])
project_name (Optional[str]) – If null, the default project is used
container_id (Optional[str])
mime_type (Optional[str])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Return type:
None
Examples
from Opik import OpikApi from Opik import MultipartUploadPart client = OpikApi(api_key=”YOUR_API_KEY”, workspace_name=”YOUR_WORKSPACE_NAME”, ) client.attachments.delete_attachments(file_name=’file_name’, entity_type=”trace”, entity_id=’entity_id’, file_size=1000000, upload_id=’upload_id’, uploaded_file_parts=[MultipartUploadPart(e_tag=’e_tag’, part_number=1, )], )
- download_attachment(*, container_id: str, entity_type: Literal['trace', 'span'] | Any, entity_id: str, file_name: str, mime_type: str, workspace_name: str | None = None, request_options: RequestOptions | None = None) Iterator[bytes] ¶
Download attachment from MinIO
- Parameters:
container_id (str)
entity_type (DownloadAttachmentRequestEntityType)
entity_id (str)
file_name (str)
mime_type (str)
workspace_name (Optional[str])
request_options (Optional[RequestOptions]) – Request-specific configuration. You can pass in configuration such as chunk_size, and more to customize the request and response.
- Returns:
Attachment Resource
- Return type:
Iterator[bytes]
- start_multi_part_upload(*, file_name: str, num_of_file_parts: int, entity_type: Literal['trace', 'span'] | Any, entity_id: str, path: str, mime_type: str | None = OMIT, project_name: str | None = OMIT, request_options: RequestOptions | None = None) StartMultipartUploadResponse ¶
Start multipart attachment upload
- Parameters:
file_name (str)
num_of_file_parts (int)
entity_type (StartMultipartUploadRequestEntityType)
entity_id (str)
path (str)
mime_type (Optional[str])
project_name (Optional[str]) – If null, the default project is used
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
MultipartUploadResponse
- Return type:
Examples
from Opik import OpikApi client = OpikApi(api_key=”YOUR_API_KEY”, workspace_name=”YOUR_WORKSPACE_NAME”, ) client.attachments.start_multi_part_upload(file_name=’file_name’, num_of_file_parts=1, entity_type=”trace”, entity_id=’entity_id’, path=’path’, )
- upload_attachment(*, file_name: str, entity_type: Literal['trace', 'span'] | Any, entity_id: str, request: Dict[str, Any | None], project_name: str | None = None, mime_type: str | None = None, request_options: RequestOptions | None = None) None ¶
Upload attachment to MinIO
- Parameters:
file_name (str)
entity_type (UploadAttachmentRequestEntityType)
entity_id (str)
request (Dict[str, Optional[Any]])
project_name (Optional[str])
mime_type (Optional[str])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Return type:
None
Examples
from Opik import OpikApi client = OpikApi(api_key=”YOUR_API_KEY”, workspace_name=”YOUR_WORKSPACE_NAME”, ) client.attachments.upload_attachment(file_name=’file_name’, entity_type=”trace”, entity_id=’entity_id’, request={‘key’: ‘value’ }, )
Usage Example¶
import opik
client = opik.Opik()
# Upload an attachment
client.rest_client.attachments.upload_attachment(
entity_type="trace",
entity_id="trace-id",
name="results.json",
content=b"{'result': 'success'}"
)
# List attachments for an entity
attachments = client.rest_client.attachments.list_attachments(
entity_type="trace",
entity_id="trace-id"
)
# Download an attachment
content = client.rest_client.attachments.download_attachment(
entity_type="trace",
attachment_id="attachment-id"
)