A developer guide for creating and modifying batches via the Python SDK.
Client
import labelbox as lb
client = lb.Client(api_key="<YOUR_API_KEY>")
Fundamentals
Get a batch
Batches are accessible via an object of the Project
class.
# get a project
project = client.get_project("<project_id>")
# get the batches (returns a paginated collection of Batch objects)
batches = project.batches()
# get one batch
batch = next(batches)
# inspect all batches
for batch in batches:
print(batch)
# for ease of use, you can convert the paginated collection to a list
list(batches)
Create a batch
When creating a batch to send to a project, one of either global_keys
or data_rows
must be supplied as an argument. If using the data_rows
argument, you can supply either a list of data row IDs or a list of DataRow
class objects.
Optionally, you can supply a priority
, ranging from 1 (highest) to 5 (lowest), for which the batch should be labeled. This will determine the order in which the included data rows appear in the labeling queue compared to other batches. If no value is provided, the batch will assume the lowest priority.
project.create_batch(
name="<unique_batch_name>",
global_keys=["key1", "key2", "key3"],
priority=5,
)
# if the project uses consensus, you can optionally supply a dictionary with consensus settings
# if provided, the batch will use consensus with the specificed coverage and votes
project.create_batch(
name="<unique_batch_name>",
data_rows=["<data_row_id>", "<data_row_id>"],
priority=1,
consensus_settings={"number_of_labels": 3, "coverage_percentage": 0.1}
)
Methods
Export the data rows
This method returns a generator that produces all data rows currently in the batch.
data_rows = batch.export_data_rows(include_metadata=False)
# inspect the data rows
for data_row in data_rows:
print(data_row)
Remove queued data rows
This method removes queued data rows from the batch and consequently the labeling queue of the project.
batch.remove_queued_data_rows()
Delete the labels
This method deletes the labels made on data rows in the batch and re-queues the data rows for labeling.
batch.delete_labels()
# alternatively, you can re-queue the data with labels as templates
batch.delete_labels(set_labels_as_template=True)
Delete a batch
If any labels exist that were created on data rows in the batch, the batch cannot be deleted. You need to first delete the labels made on data rows in the batch, as shown above, before deleting the batch itself.
batch.delete()
Attributes
Get the basics
# name (str)
batch.name
# created at (datetime)
batch.created_at
# updated at (datetime)
batch.updated_at
# size, the number of data rows in the batch (int)
batch.size
# project (relationship to Project object)
project = batch.project()