How to modify attachment values?

I need to modify the attachment values for most of my data rows. Mainly, I need to re-point a number of image urls and text urls. The actual end content does not change, just the urls where that content lives.

I see a way to update a data row’s “row_data”, but not a way to alter attachments at all (not even a way to delete them).

Hi @adam,

Thank you for the question.

There is no direct way to update an attachment. You will need to create a new one (Data Row) and delete the previous one (via attachment.delete())

For example, you could do:

from labelbox import Client
from uuid import uuid4

client = Client(api_key="<YOUR API KEY>")
metadata_ontology = client.get_data_row_metadata_ontology()

##### Create the dataset and the original data row #####

dataset = client.create_dataset(name="Example - attachment")

asset = {
  "row_data": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/basic.jpg", 
  "global_key": str(uuid4()),
  "media_type": "IMAGE",
  "attachments": [{"type": "IMAGE", "value": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/disease_attachment.jpeg"}],
}

dr = dataset.create_data_row(asset)

##### Update the attachment #####

# Remove the first (in our case only) attachment
# Note that you will need to filter if you have multiple attachments
next(dr.attachments()).delete()

# Create the updated attachment
dr.create_attachment(attachment_type="TEXT_URL", attachment_value="https://storage.googleapis.com/labelbox-sample-datasets/Docs/text_attachment.txt", attachment_name="Text1")

Best regards,
Paul N.
Labelbox Support