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.
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)
After you create your 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 see examples of common tasks and workflows with the Python SDK, visit our Tutorials section.
There are 3 ways to set up authentication with Labelbox.
Pass your API key as an environment variable in the command line.
Then, import and initialize the API Client.
from labelbox import Client client = Client()
Pass a custom endpoint. This is only applicable for 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")
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)
If there is something you cannot accomplish with the Python SDK, first share your feedback in Github. It is likely we will consider and add the functionality. Otherwise, you can use the raw but powerful GraphQL API reference.
Visit our GraphQL API explorer to try out our GraphQL API.
Updated 5 months ago