Labelbox Client is essential for all SDK workflows. It connects to a Labelbox server with your authentication API key and provides functions for querying and creating data assets.

Instantiate Labelbox Client

Your Client is associated with the API key of your account. See more in Create an API key.

from labelbox import Client

## Option 1: List API_KEY in your Python script
client = Client(api_key=API_KEY)

## Option 2: Pass your API key as an environment variable $LABELBOX_API_KEY
# In your terminal:
[email protected]:~$ export LABELBOX_API_KEY="<YOUR_API_KEY>"
# In Python:
client = Client()

## Option 3: Pass a custom endpoint. 
# This is only applicable for Customer-managed infra use cases (on-prem). If this applies to you, you may pass the API key and server endpoint explicitly when you initialize the Client object. 
client = Client("<YOUR_API_KEY>", "")

Create high-level assets

Using the Client interface, you can create high-level data assets - Dataset, Project, Ontology, and Model. For details, please refer to the documentation linked in each of these modules.

from labelbox import Client
client = Client(api_key="<YOUR_API_KEY>")

dataset = client.create_dataset(name="<dataset_name>")

project = client.create_project(name="<project_name>")

feature_schema = client.create_feature_schema(normalized={'tool': 'polygon',  'name': 'cat', 'color': 'black'})
ontology = client.create_ontology_from_feature_schemas(name="<ontology_name>", feature_schema_ids=[feature_schema.uid]) #option 1
ontology = client.create_ontology(name="<ontology_name>", normalized={"tools" : [{'tool': 'polygon',  'name': 'cat', 'color': 'black'}], "classifications" : []}) #option 2

model = client.create_model(name="<model_name>", ontology_id=ontology.uid)

Query assets

Using the Client interface, you can query your data assets. For details, please refer to the documentation for each of these modules.

from labelbox import Client, Project, Dataset, Model
client = Client(api_key="<YOUR_API_KEY>")

project = client.get_project("<project_id>")
projects = client.get_projects(where=( == "<project_name>") & (Project.description == "<project_description>"))

dataset = client.get_dataset("<dataset_id>")
datasets = client.get_datasets(where=( == "<dataset_name>") & (Dataset.description == "<dataset_description>"))

data_row = client.get_data_row("<data_row_id>")
data_row_ids_dict = client.get_data_row_ids_for_external_ids(external_ids=["id"]) #A dict of {key: external_id, value: matching data_row_ids }

ontology = client.get_ontology("<ontology_id>")
ontologies = client.get_ontologies(name_contains="<keyword>")

feature_schema = client.get_feature_schema("<feature_schema_id>")
feature_schemas = client.get_feature_schemas(name_contains="<keyword>")
metadata_ontology = client.get_data_row_metadata_ontology()

model = client.get_model("<model_id>")
models = client.get_models(where=( == "<model_name>"))

model_run = client.get_model_run("<model_run_id>")

user = client.get_user() # current user
organization = client.get_organization() # current user's organization