Labelbox Python SDK
The Labelbox Python SDK (current version 7.6.0) provides a programmatic interface to interact with the Labelbox platform, enabling users to manage data, projects, labels, and model integrations. It allows for automating data import, export of labeled data, managing labeling projects, and integrating machine learning workflows. The library has a frequent release cadence, with multiple minor versions and bug fixes released throughout the year.
Warnings
- gotcha Always store your Labelbox API key securely, preferably as an environment variable (e.g., `LABELBOX_API_KEY`) rather than hardcoding it directly in your code. The `Client` constructor expects the key.
- gotcha When uploading data, ensure your `DataRow` metadata and assets conform to the expected Labelbox formats. Incorrect formatting, especially for complex data types or external URLs, is a common source of upload errors.
- breaking While v7.0.0 primarily introduced new features, any significant changes to project ontologies or workflow management (added in v7.x releases) can impact existing labeling pipelines or data exports. Always test with a staging environment.
- gotcha Be mindful of API rate limits when performing bulk operations. While the SDK handles some retries, extensive, rapid requests can lead to `TooManyRequests` errors. Implement exponential backoff for large-scale automation.
Install
-
pip install labelbox
Imports
- Client
from labelbox import Client
- Project
from labelbox import Project
- Dataset
from labelbox import Dataset
- DataRow
from labelbox import DataRow
Quickstart
import os
from labelbox import Client, Project
# Authenticate with your Labelbox API key
# It is recommended to store your API key as an environment variable
# e.g., export LABELBOX_API_KEY="YOUR_API_KEY"
try:
client = Client(os.environ.get('LABELBOX_API_KEY'))
print("Successfully connected to Labelbox.")
# Example: List your projects
projects = list(client.get_projects())
if projects:
print(f"Found {len(projects)} projects:")
for project in projects:
print(f"- {project.name} (ID: {project.uid})")
else:
print("No projects found in your workspace.")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure your LABELBOX_API_KEY environment variable is set correctly.")