No project description provided
Project description
Label Studio Python Library
:warning: Note
The version of
label-studio-sdk<1
is deprecated and no longer supported. We recommend updating to the latest version. If you still want to use the old version, you can install it withpip install "label-studio-sdk<1"
. OR You can find the branch with the old version by cloning the repository and checking out the branch as follows:git clone https://github.com/HumanSignal/label-studio-sdk.git cd label-studio-sdk git checkout previous-versionOR you can change your import statements as follows:
from label_studio_sdk import Client from label_studio_sdk.data_manager import Filters, Column, Operator, Type from label_studio_sdk._legacy import Project
The Label Studio Python Library provides convenient access to the Label Studio API from applications written in Python.
- Installation
- Usage
- Examples
- Get all projects
- Create a new project
- Get project by ID
- Update project
- Delete project
- Get tasks with annotations and predictions
- Get task by ID
- Get all annotations for a task
- Create a new task
- Import batch tasks
- Update task
- Delete task
- Create prediction
- Update prediction
- Delete prediction
- Async client
Documentation
Explore the Label Studio API documentation here.
Installation
pip install --upgrade label-studio-sdk
Usage
from label_studio_sdk.client import LabelStudio
client = LabelStudio(
api_key="YOUR_API_KEY",
)
Examples
Get all projects
projects = client.projects.list()
Create a new project
project = client.projects.create(
name="Project name",
description="Project description",
label_config="""
<View>
<Image name="image" value="$image" />
<RectangleLabels name="label" toName="image">
<Label value="cat" />
<Label value="dog" />
</RectangleLabels>
</View>
"""
)
Get project by ID
project = client.projects.get("PROJECT_ID")
Update project
project = client.projects.update(
project="PROJECT_ID",
description="New project description",
)
Delete project
client.projects.delete("PROJECT_ID")
Get tasks with annotations and predictions
tasks = client.tasks.list(project="PROJECT_ID")
Get task by ID
task = client.tasks.get("TASK_ID")
print(task)
Task data, annotations and predictions in Label Studio tasks format:
{
"id": "TASK_ID",
"data": {
"image": "https://example.com/image.jpg",
"label": "cat"
},
"annotations": [],
"predictions": []
}
Get all annotations for a task
annotations = client.annotations.list(task="TASK_ID")
Create a new task
task = client.tasks.create(
project="PROJECT_ID",
data={
"data": {
"image": "https://example.com/image.jpg",
"label": "cat"
}
}
)
Import batch tasks
tasks = client.projects.import_tasks(
project="PROJECT_ID",
data=[
{
"data": {
"image": "https://example.com/image1.jpg",
"label": "cat"
}
},
{
"data": {
"image": "https://example.com/image2.jpg",
"label": "dog"
}
}
]
)
Update task
task = client.tasks.update(
project="PROJECT_ID",
task="TASK_ID",
data={
"data": {
"image": "https://example.com/image.jpg",
"label": "dog"
}
}
)
Delete task
client.tasks.delete(project="PROJECT_ID", task="TASK_ID")
Create prediction
prediction = client.predictions.create(
task="TASK_ID",
result=[{'from_name': 'bbox', 'to_name': 'image', 'type': 'labels', 'value': {'rectanglelabels': [{'x': 10, 'y': 20, 'width': 30, 'height': 40, 'rectanglelabels': ['cat']}]}}],
score=0.9,
model_version='yolov8',
)
Update prediction
prediction = client.predictions.update(
task="TASK_ID",
prediction="PREDICTION_ID",
result=[{'from_name': 'bbox', 'to_name': 'image', 'type': 'labels', 'value': {'rectanglelabels': [{'x': 10, 'y': 20, 'width': 30, 'height': 40, 'rectanglelabels': ['dog']}]}}],
score=0.8,
model_version='yolov8',
)
Delete prediction
client.predictions.delete(task="TASK_ID", prediction="PREDICTION_ID")
Async client
from label_studio_sdk.client import AsyncLabelStudio
client = AsyncLabelStudio(
api_key="YOUR_API_KEY",
)
Beta Status
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version. This way, you can install the same version each time without breaking changes.
Contributing
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for label_studio_sdk-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d69235cde5b8464979568c51bc40e23ddef9e8cea191bf06eea638cd2bbcb42 |
|
MD5 | 2bf4c976984cfbaa218936bbdb2de2c5 |
|
BLAKE2b-256 | e1470855891b5692466cc758eb2f8e65e27e3a9f09b60170f1b1d95362beca67 |