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 afterwards.
-
Python 3.7 - 3.9
Install/upgrade SDK
After you create an API key, you can start using our Python SDK.
To install, run either pip install labelbox
orpip install "labelbox[data]"
in your command line.
pip3 install "labelbox[data]"
# or
pip3 install labelbox
Command | Description |
---|---|
pip3 install "labelbox[data]" | Installs all required libraries plus extras requirements in manipulating annotations (shapely, geojson, numpy, PILLOW, opencv-python, etc.) |
pip3 install labelbox | Installs all required libraries for client-only functionality |
# install latest labelbox version
!pip3 install labelbox
import labelbox as lb
# Enter your Labelbox API key here
LB_API_KEY = ""
# Create Labelbox client
client = lb.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.
import labelbox as lb
client = lb.Client()
Option 2
Run this Python script and pass your API key as a string.
import labelbox as lb
if __name__ == '__main__':
API_KEY = "<your_api_key_here>"
client = lb.Client(API_KEY)