How to: Update Attachments for a Datarow using Python SDK

Hello Labelbox Community! :star2:

Are you looking to update attachments in your datarows quickly? Weโ€™ve got you covered! This quick guide provides a very simple Python script to help you update attachments efficiently in Labelbox (version 3.66.0+).

Easy Steps to Follow:

  1. Import Labelbox
import labelbox as lb
  1. Set Up Your API Key :key:
client = labelbox.Client(api_key=API_KEY)
  1. Define Attachment URLs :link:
data_row_id = 'YOUR_DATA_ROW_ID'
new_attachment_url = 'NEW_ATTACHMENT_URL'
  1. Update the Attachment :arrows_counterclockwise:
    data_row = client.get_data_row(data_row_id)
    for attachment in data_row.attachments():
        if attachment.attachment_value == update_url:
            attachment.update(name= "new_name", value=new_attachment_url)
            print(f"Attachment updated: {new_attachment_url}")
        print("No matching attachment found.")
except labelbox.exceptions.LabelboxError as e:
    print(f"Error: {e}")

This script changes the URL of an existing attachment. For other updates, check the Labelbox docs! :books:

Questions? Drop them below! Weโ€™re here to help you keep your datasets fresh and up-to-date! :bulb::tada:

1 Like