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)

# prepare some datarows and store them in dataset
dataset = client.create_dataset(name=DATASET_NAME)
uploads = []
for i in range(10):
        'external_id': i,
        'row_data': ''
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():

# List project that batch is part of

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

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.