Describes how to install, update, and authenticate to the Labelbox Python SDK.
Many actions and workflows available in the Labelbox app can be automated using the the Python SDK, which provides access to the Labelbox API.
Requirements
-
Make sure
pip
is installed and up-to-date. -
Use the Workspace settings menu of the Labelbox app to create an API key. Store your key in a safe place, as you cannot view it after it has been created.
-
A supported version of Python.
Install or 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 dependencies (libraries, tools to manipulate annotations, and more.) |
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 to the latest version, use your package manager:
pip install --upgrade labelbox
To run the Python SDK in a Dcker container, use the included Dockerfile as a starting place.
Related info:
- The Python SDK Github repository
- Changelog of recent changes.
- Tutorials for help learning the Labelbox API
- The Contribution guidelines for help setting up and building the SDK
Authentication
You need an API key to authenticate your client. You can:
-
Save your key to an environment variable passed via the command-line:
user@machine:~$ export LABELBOX_API_KEY="<your_api_key>" user@machine:~$ python3
Then, import and initialize the API Client.
import labelbox as lb client = lb.Client()
-
Paste your API key directly into your script (not recommended)
import labelbox as lb if __name__ == '__main__': API_KEY = "<your_api_key_here>" client = lb.Client(API_KEY)
Remember that your API key authorizes access to Labelbox, your acount, and your data assets; treat your APIkey as carefully as any other set of credentials.