Getting started
Version 2.0 of the Label Studio SDK is here, and it’s packed with more functionality and a smoother developer experience!
If you’re using an older version, please review the breaking changes before upgrading.
You can use the Label Studio Python SDK to make annotating data a more integrated part of your data science and machine learning pipelines. This software development kit (SDK) lets you call the Label Studio API directly from scripts using predefined classes and methods.
The following are basic examples. For more advanced examples, see Tutorials.
Install
Install the Label Studio SDK using pip:
or
Authenticate and Connect to the API
In your Python scripts, you will need to do the following:
-
Import the SDK.
-
Define your Label Studio URL.
For example,
http://localhost:8080
orhttps://app.humansignal.com
Note:
- Do not including a trailing slash in your URL
LABEL_STUDIO_URL
should start withhttps://
orhttp://
-
Define your API key.
This should be available on the Account & Settings page, but you may need to enable it at the organization level first. See Access tokens.
You can use either the Legacy Token or the Personal Access Token, but for the SDK we recommend the Personal Access Token.
-
Connect to the API.
Try this example:
You can set LABEL_STUDIO_URL
and LABEL_STUDIO_API_KEY
as environment variables:
Tutorials
For examples of getting started using SDK, see the following tutorials:
- Create a Project
- Import Tasks
- Assign Users to Tasks
- Add Model Predictions
- Export and Convert Snapshots
Advanced tutorials focused on ML backends:
- Logging ML Server Predictions
- Evaluate LLM Responses
- Improve Object Detection with YOLO
- Interactive OCR with Tesseract
SDK versions and compatibility
SDK version < 1 is deprecated and no longer supported. We recommend upgrading to the latest version.
If you still want to use the older version, you can install it using pip install "label-studio-sdk<1"
.
You can also check out an older branch version in the GitHub repository:
Or you can simply modify you code to change the import stream as follows:
If you’re looking for the documentation for the older version, you can find it here.
Advanced
Handling Errors
If you encounter an error while using the Label Studio Python SDK, you can catch the error and handle it in your script.
Annotations are exported in the format specified in the Label Studio JSON format.
Timeouts
By default, requests time out after 5 seconds. You can configure this with a timeout option at the client or request level.
Custom HTTP client
You can override the httpx client to customize it for your use case. Some common use cases include support for proxies and transports.