import labelbox as lb
from uuid import uuid4
import datetime
# insert your API key
LB_API_KEY = "<API KEY>"
client = lb.Client(api_key=LB_API_KEY)
# get the metadata ontology
metadata_ontology = client.get_data_row_metadata_ontology()
# create the dataset
dataset = client.create_dataset(name="Bulk import example")
# build the assets
assets = [
{"row_data": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/basic.jpg", "global_key": str(uuid4())},
{"row_data": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/basic.jpg", "global_key": str(uuid4())},
{"row_data": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/basic.jpg", "global_key": str(uuid4())}
]
# build the metadata
asset_metadata_fields = [
{"name": "captureDateTime", "value": datetime.datetime.utcnow()},
{"name": "tag", "value": "tag_string"},
{"name": "split", "value": "train"}
]
# build the attachments
asset_attachments = [
{"type": "IMAGE", "value": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/disease_attachment.jpeg"},
{"type": "VIDEO", "value": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/drone_video.mp4"},
{"type": "RAW_TEXT", "value": "IOWA, Zone 2232, June 2022 [Text string]"},
{"type": "RAW_TEXT", "value": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/text_attachment.txt"},
{"type": "TEXT_URL", "value": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/text_attachment.txt"},
{"type": "HTML", "value": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/windy.html"},
{"type": "IMAGE_OVERLAY", "value": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/rgb.jpg", "name": "RGB" },
{"type": "IMAGE_OVERLAY", "value": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/cir.jpg", "name": "CIR"},
{"type": "IMAGE_OVERLAY", "value": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/weeds.jpg", "name": "Weeds"},
{"type": "PDF_URL", "value": "https://storage.googleapis.com/labelbox-datasets/arxiv-pdf/data/99-word-token-pdfs/0801.3483.pdf"}
]
# connect the metadata and attachments to the data rows
for item in assets:
item["metadata_fields"] = asset_metadata_fields
item["attachments"] = asset_attachments
# create the data rows
task = dataset.upsert_data_rows(assets) # or # or alternatively use create_data_rows()
task.wait_till_done()
print(task.results)
print(task.errors)