Create a batch and attach to project

First, make sure the project is in Batch mode. You can then sample data rows from an existing dataset, and attach it to a project.

from labelbox import Client
import random

client = Client(api_key="<YOUR_API_KEY>")
project = client.get_project(PROJECT_ID)
project.update(queue_mode=project.QueueMode.Batch)

# prepare some datarows and store them in dataset
dataset = client.create_dataset(name=DATASET_NAME)
uploads = []
for i in range(10):
    uploads.append({
        'external_id': i,
        'row_data': 'https://picsum.photos/200/300'
    })
dataset.create_data_rows(uploads)
data_rows = [dr.uid for dr in list(dataset.export_data_rows())]


# Randomly select 5 Data Rows
sampled_data_rows = random.sample(data_rows, 5)

batch = project.create_batch(
  "Initial batch", # name of the batch
  sampled_data_rows, # list of Data Rows
  1 # priority between 1-5
)

Get a batch

# list batches in a project
for batch in project.batches():
    print(batch.project().name)

# List project that batch is part of
batch.project()

We currently don't support SDK method to get a batch by name/id or list data rows in a batch. You can view your batch in the Data Row table of the project.

Archive a dataset

# archiving batch removes all queued data rows from the project
batch.remove_queued_data_rows()

Delete batch

You need to first delete the labels in the batch before deleting the batch itself.

# set_labels_as_template=True will set the deleted labels as template for future re-labeling. 
batch.delete_labels(set_labels_as_template=False)
batch.delete()