Label Studio SDK

2.0.19 · active · verified Sat Apr 11

The `label-studio-sdk` is the official Python client library for interacting with the Label Studio API. It provides programmatic access to manage projects, tasks, annotations, import/export data, and automate various data labeling workflows. It is currently at version 2.0.19 and maintains a regular release cadence with frequent updates adding new features and API endpoint support.

Warnings

Install

Imports

Quickstart

Initializes the Label Studio client, connects to your instance, and lists all available projects. Ensure `LABEL_STUDIO_URL` and `LABEL_STUDIO_API_KEY` are set either as environment variables or directly in the code.

import os
from label_studio_sdk import Client

# Set your Label Studio URL and API Key
# It's recommended to set these as environment variables
LABEL_STUDIO_URL = os.environ.get('LABEL_STUDIO_URL', 'http://localhost:8080')
LABEL_STUDIO_API_KEY = os.environ.get('LABEL_STUDIO_API_KEY', 'YOUR_API_KEY_HERE') # Replace with your actual API key if not in env

if not LABEL_STUDIO_API_KEY or LABEL_STUDIO_API_KEY == 'YOUR_API_KEY_HERE':
    print("Warning: LABEL_STUDIO_API_KEY not set. Please set it as an environment variable or replace 'YOUR_API_KEY_HERE'.")
    exit()

try:
    # Initialize the Label Studio client
    ls = Client(url=LABEL_STUDIO_URL, api_key=LABEL_STUDIO_API_KEY)
    
    # Test connection and fetch projects
    projects = ls.get_projects()
    print(f"Successfully connected to Label Studio at {LABEL_STUDIO_URL}.")
    print(f"Found {len(projects)} projects:")
    for p in projects:
        print(f"  - Project ID: {p.id}, Title: {p.title}")

except Exception as e:
    print(f"Error connecting to Label Studio or fetching projects: {e}")
    print("Please ensure LABEL_STUDIO_URL and LABEL_STUDIO_API_KEY are correct and Label Studio is running.")

view raw JSON →