Create a project

from labelbox import MediaType, Client

client = Client(api_key="<YOUR_API_KEY>")

# Create a new project
project = client.create_project(name="my-test-project",
                                description="a description",
                                media_type=MediaType.Image)

Setting the queueing mode while setting up a project

from labelbox import Client
from labelbox.schema.queue_mode import QueueMode

client = Client(api_key="<YOUR_API_KEY>")

project = client.create_project(name="my-test-project",
                                description="a description",
                                queue_mode=QueueMode.Batch)

project = client.create_project(name="my-test-project",
                                description="a description",
                                queue_mode=QueueMode.Dataset)

Attach Ontology to a project to set up editor

# Get exsiting ontology (you can share an ontology across projects) or create a new one following Ontology section
ontology = client.get_ontology("ONTOLOGY_ID")

# Setup project editor with ontology
project.setup_editor(ontology)

Upload labeling instructions

project.upsert_instructions("LOCAL_FILE_PATH (PDF or HTML)")

If using Dataset mode (default) - attach/detach dataset

# Get dataset
dataset = client.get_dataset("DATASET_ID")

#Attach the dataset to the project
project.datasets.connect(dataset)

#Detach the dataset from the project
project.datasets.disconnect(dataset)

If using Batch mode - add a batch to queue

project.update(queue_mode=project.QueueMode.Batch)

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
)

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

Configure project settings

Change Queue mode

project.update(queue_mode=project.QueueMode.Batch)
project.update(queue_mode=project.QueueMode.Dataset)

Change project resource tag. See more in Organize projects with tags.

tags = project.update_project_resource_tags(["tag1", "tag2"])

Get a project

# Get project by id
project = client.get_project(PROJECT_ID)

# Alternatively you can query by name
projects = client.get_projects(
    where=((labelbox.Project.name == PROJECT_NAME) &
           (labelbox.Project.description == "new description field")))
project = next(projects, None)

Get project information

ontology = project.ontology()
batches = list(project.batches())

Export data rows queued in a project

data_rows = project.export_queued_data_rows(timeout_seconds=120)

Export labels

labels = project.label_generator()

## Alternatively you can specify date range to export desired labels from a project
labels = project.label_generator(start="2020-01-01", end="2020-01-02")

for label in labels:
  print(label.annotations)

Delete a project

project.delete()