All actions and workflows available in the Labelbox UI are also possible to do with the Python SDK. We recommend that you use the Python SDK to make your workflows easier. The Python SDK allows you to access all of the functionalities of the Labelbox API without having to use GraphQL.
Requirements
-
Make sure
pip
is installed. -
Create your API key in the Workspace settings section in your Labelbox account. Save your API key somewhere as it will be hidden afterward.
-
Python 3.7 - 3.9 (Python 3.6 will soon no longer be supported)
Install/upgrade SDK
After you create an API key, you can start using our Python SDK.
pip3 install "labelbox[data]" # installs all required libraries plus extras required in manipulating annotations (shapely, geojson, numpy, PILLOW, opencv-python, etc.)
pip3 install labelbox # installs all required libraries for client only functionality
To install, run pip install labelbox
in your command line.
# install latest labelbox version
!pip3 install labelbox[data]
import labelbox
# Enter your Labelbox API key here
LB_API_KEY = ""
# Create Labelbox client
lb = labelbox.Client(api_key=LB_API_KEY)
To upgrade, consult the changelog and run pip install --upgrade labelbox
. See the Python SDK in Github.
To see examples of common tasks and workflows with the Python SDK, visit our Tutorials section.
Authentication
There are 3 ways to set up authentication with Labelbox.
Option 1
Pass your API key as an environment variable in the command line.
[email protected]:~$ export LABELBOX_API_KEY="<your_api_key>"
[email protected]:~$ python3
Then, import and initialize the API Client.
from labelbox import Client
client = Client()
Option 2
Pass a custom endpoint. This is only applicable to Customer-managed infra use cases. If this applies to you, you may pass the API key and server endpoint explicitly when you initialize the Client object. Otherwise, refer to Option 1.
from labelbox import Client
client = Client("<your_api_key_here>", "https://app.your-domain.com/api/graphql")
Option 3
Run this Python script and pass your API key as a string.
from labelbox import Client
if __name__ == '__main__':
API_KEY = "<your_api_key_here>"
client = Client(API_KEY)