Use this file to discover all available pages before exploring further.
Open in Colab
Open in GitHub
This short introduction to Labelbox Python SDK is designed mainly for new users. The example will introduce you to Labelbox Python SDK concepts that you will use commonly. We will demonstrate a simple but common workflow of importing an image data row, setting up a project, and exporting.
We must first install the Labelbox library and then import the SDK module. It is recommended to install "labelbox[data]" over labelbox to obtain all the correct dependencies. We will also be importing the Python UUID library to generate universal unique IDs for the variety of objects that will be created with this notebook.
pip install -q "labelbox[data]"
import labelbox as lbimport uuid
Replace the value of API_KEY with a valid API key to connect to the Labelbox client.
Below, we will create a and then attach a publicly hosted image . Typically, you would import data rows hosted on a cloud provider (recommended) or import them locally. For more information, visit our import image data section in our developer guides. You can find your dataset inside the Catalog section of Labelbox.
# Create dataset from clientdataset = client.create_dataset(name="Quick Start Example Dataset")global_key = str(uuid.uuid4()) # Unique user specified ID# Data row structureimage_data_rows = [{ "row_data": "https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg", "global_key": global_key, "media_type": "IMAGE",}]# Bulk import data rowtask = dataset.create_data_rows(image_data_rows) # List of data rowstask.wait_till_done()print(task.errors) # Print any errors
Before sending our data row to a labeling project, we must create an . The example below will create a simple ontology with a bounding box tool and a checklist classification feature. For more information, visit the ontology section inside our developer guides.
Step 3: Creating a project and attaching our ontology
Now that we have made our ontology, we are ready to create a where we can label our data row.
# Create a new projectproject = client.create_project( name="Quick Start Example Project", media_type=lb.MediaType.Image,)# Attach created ontologyproject.connect_ontology(ontology)
Step 4: Sending our data row to our project by creating a batch
With our project created, we can send our data rows by creating a . Our data rows will start in the initial labeling queue, where labelers are able to annotate our data row. For more information on batches, review the batches section of our developer guides.
project.create_batch( name="Quick Start Example Batch" + str(uuid.uuid4()), global_keys=[ global_key ], # Global key we used earlier in this guide to create our dataset priority=5,)
We have now successfully set up a project for labeling using only the SDK!From here, you can either label our data row directly inside the labeling queue or import annotations directly through our SDK. Below we will demonstrate the final step of this guide by exporting from our project. Since we did not label any data rows or import annotations within this guide, no labels will be presented on our data row. For a full overview of exporting, visit our export overview developer guide.
# Start export from projectexport_task = project.export()export_task.wait_till_done()# Stream the export using a callback functiondef json_stream_handler(output: labelbox.BufferedJsonConverterOutput):print(output.json)export_task.get_buffered_stream(stream_type=labelbox.StreamType.RESULT).start(stream_handler=json_stream_handler)# Collect all exported data into a listexport_json = [data_row.json for data_row in export_task.get_buffered_stream()]
This section serves as an optional clean-up step to delete the Labelbox assets created within this guide. You will need to uncomment the delete methods shown.