### Install Label Studio SDK Source: https://context7.com/humansignal/label-studio-sdk/llms.txt Install the SDK using pip or poetry. Ensure you have the latest version for all features. ```bash pip install --upgrade label-studio-sdk ``` ```bash poetry add label-studio-sdk ``` -------------------------------- ### Install Label Studio SDK Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/active_learning/active_learning.ipynb Install the Label Studio SDK using pip. This is the first step to interact with the Label Studio API. ```python !pip install label-studio-sdk ``` -------------------------------- ### Install Label Studio SDK Source: https://github.com/humansignal/label-studio-sdk/blob/master/README.md Install or upgrade the label-studio-sdk package using pip or poetry. ```sh pip install --upgrade label-studio-sdk ``` ```sh # or poetry add label-studio-sdk ``` -------------------------------- ### Install Label Studio SDK Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/migrate_ls_to_ls/README.md Install or upgrade the Label Studio SDK to version 2.0 or higher. This is a prerequisite for running the migration script. ```python pip install -U label-studio-sdk ``` -------------------------------- ### Start Interface and Create Project Source: https://github.com/humansignal/label-studio-sdk/blob/master/interface-cli.md Use the `start` command to sync an interface, create a new project using it, and open the project's data page. It's useful for publishing a new interface version and setting up a project that references it. The `--params` option requires a JSON file for project interface parameters. ```bash label-studio-sdk interface start Screen.jsx \ --project-title "Review Project" \ --params params.json ``` -------------------------------- ### Install Deprecated SDK Version Source: https://github.com/humansignal/label-studio-sdk/blob/master/README.md Install a version of the label-studio-sdk older than 1.0. ```sh pip install "label-studio-sdk<1" ``` -------------------------------- ### Run CLI with uv Source: https://github.com/humansignal/label-studio-sdk/blob/master/README.md Execute the label-studio-sdk CLI using uv for different installation sources. ```bash # from PyPI uv run --with label_studio_sdk label-studio-sdk --help ``` ```bash # from github uv run --with git+https://github.com/HumanSignal/label-studio-sdk.git label-studio-sdk --help ``` ```bash # from local uv run --with-editable . label-studio-sdk --help ``` -------------------------------- ### YOLO classes.txt Example Source: https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/README.md An example of the `classes.txt` file used in YOLO datasets, listing each class name on a new line. ```text Airplane Car ``` -------------------------------- ### Get CLI Help Source: https://github.com/humansignal/label-studio-sdk/blob/master/README.md Use -h for minimal help and --help for full documentation on CLI commands. ```bash # minimal help for one command label-studio-sdk projects create -h ``` ```bash # full help (longer) label-studio-sdk projects create --help ``` ```bash # top-level label-studio-sdk --help ``` -------------------------------- ### Install Dependencies and Run Background Task Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/mensuration_and_polling/README.md Installs required Python packages and runs the background task script to poll for new annotations. Ensure your Label Studio URL, API key, and project ID are correctly configured in `poll_for_tasks.py`. ```bash pip install -r requirements.txt python poll_for_tasks.py ``` -------------------------------- ### Label Studio JSON Manifest Example Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/mensuration_and_polling/README.md Example JSON manifest for uploading data to Label Studio, specifying image paths and placeholder fields for mensuration results. Adapt 's3://my-bucket/path/' to your storage configuration. ```json [ { "data": { "image": "s3://my-bucket/path/image1.jpg", "perimeter_m": "placeholder", "area_m2": "placeholder", "major_axis_m": "placeholder", "minor_axis_m": "placeholder" } }, { "data": { "image": "s3://my-bucket/path/image2.jpg", "perimeter_m": "placeholder", "area_m2": "placeholder", "major_axis_m": "placeholder", "minor_axis_m": "placeholder" } } ] ``` -------------------------------- ### client.ml.train Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Start training with already-labeled tasks after adding an ML backend. This is useful for active learning strategies. ```APIDOC ## POST /api/v1/ml/{id}/train ### Description After you add an ML backend, call this API with the ML backend ID to start training with already-labeled tasks. ### Method POST ### Endpoint /api/v1/ml/{id}/train ### Parameters #### Path Parameters - **id** (int) - Required - A unique integer value identifying this ML backend. #### Query Parameters - **use_ground_truth** (bool) - Optional - Whether to include ground truth annotations in training. - **request_options** (RequestOptions) - Optional - Request-specific configuration. ``` -------------------------------- ### Check Local Setup with Doctor Command Source: https://github.com/humansignal/label-studio-sdk/blob/master/interface-cli.md Run the `doctor` command to check your local setup and ensure all dependencies for the interface CLI are correctly installed. This may install Node validator dependencies. ```bash label-studio-sdk interface doctor ``` -------------------------------- ### Get ML Backend Details Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Retrieves details for a specific ML backend connection using its ID. The cURL example shows how to fetch the details. ```bash curl http://localhost:8000/api/ml/{ml_backend_ID} -H 'Authorization: Token abc123' ``` ```python from label_studio_sdk import LabelStudio from label_studio_sdk.environment import LabelStudioEnvironment client = LabelStudio( api_key="", environment=LabelStudioEnvironment.DEFAULT, ) client.ml.get( id=1, ) ``` -------------------------------- ### client.projects.metrics.custom.logs Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Get AWS lambda logs for a project, including filtering by start and end dates. This endpoint is only available in Label Studio Enterprise Edition. ```APIDOC ## client.projects.metrics.custom.logs ### Description Get AWS lambda logs for project, including filtering by start and end dates. ### Method GET (inferred from SDK usage) ### Endpoint /api/projects/{id}/metrics/custom/logs (inferred from SDK usage) ### Parameters #### Path Parameters - **id** (int) - Required - The project ID. #### Query Parameters - **start_date** (str) - Optional - Start date for AWS logs filtering in format %Y-%m-%d. - **end_date** (str) - Optional - End date for AWS logs filtering in format %Y-%m-%d. - **limit** (int) - Optional - Limit the number of logs to return. ### Request Example ```python client.projects.metrics.custom.logs( id=1, start_date="2023-01-01", end_date="2023-01-31", limit=100 ) ``` ### Response #### Success Response (200) - **(Dict[str, Any])** - A dictionary containing log data. #### Response Example (Response example not explicitly defined in source) ``` -------------------------------- ### Initialize a New Interface Project Source: https://github.com/humansignal/label-studio-sdk/blob/master/interface-cli.md Scaffold a new interface project in a specified directory. Use the `--force` flag to overwrite existing files if necessary. ```bash label-studio-sdk interface init ./my-interface ``` ```bash label-studio-sdk interface init ./my-interface --force ``` -------------------------------- ### Install scikit-learn Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/active_learning/active_learning.ipynb Installs the scikit-learn library, which is required for the TF-IDF Text Classification model. ```python !pip install scikit-learn ``` -------------------------------- ### List Projects via CLI Source: https://github.com/humansignal/label-studio-sdk/blob/master/README.md List all available projects using the label-studio-sdk CLI. ```bash # List projects label-studio-sdk projects list ``` -------------------------------- ### Install Pandas Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/weak_supervision/weak_supervision.ipynb Installs the pandas library, which is required for data manipulation and reading CSV files. ```bash !pip install pandas ``` -------------------------------- ### Preview Interface and Sync Local Changes Source: https://github.com/humansignal/label-studio-sdk/blob/master/interface-cli.md Open a live playground for your interface and sync local file changes in real-time. This requires a Label Studio Enterprise instance. ```bash label-studio-sdk interface preview . ``` -------------------------------- ### Start a Project with a Synced Interface Source: https://github.com/humansignal/label-studio-sdk/blob/master/interface-cli.md Create a new Label Studio project that utilizes a locally synced interface. This command requires the interface to be synced first. ```bash label-studio-sdk interface start . \ --project-title "Sentiment Review Project" \ --workspace 3 ``` -------------------------------- ### Create Label Studio Project Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/cloud_storages/cloud_storage_guide.ipynb Initializes a Label Studio client and creates a new project with a specified label configuration. Requires LABEL_STUDIO_URL and API_KEY environment variables. ```python import os from label_studio_sdk import LabelStudio LABEL_STUDIO_URL = os.environ.get('LABEL_STUDIO_URL') API_KEY = os.environ.get('LABEL_STUDIO_API_KEY') # for storages AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY') ls = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=API_KEY) # Start new project project = ls.projects.create( title='Storage Test Project', label_config=''' ''' ) ``` -------------------------------- ### JSON Export Example Output Source: https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/README.md This is an example of the JSON output format generated by the converter for sentiment analysis tasks. ```json [ { "reviewText": "Good case, Excellent value.", "sentiment": "Positive" }, { "reviewText": "What a waste of money and time!", "sentiment": "Negative" }, { "reviewText": "The goose neck needs a little coaxing", "sentiment": "Neutral" } ] ``` -------------------------------- ### COCO JSON Output Example Source: https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/README.md This is an example of the JSON structure generated in COCO format. It includes image information, categories, and annotations. ```json { "images": [ { "width": 800, "height": 501, "id": 0, "file_name": "tmp/images/62a623a0d3cef27a51d3689865e7b08a" } ], "categories": [ { "id": 0, "name": "Planet" }, { "id": 1, "name": "Moonwalker" } ], "annotations": [ { "id": 0, "image_id": 0, "category_id": 0, "segmentation": [], "bbox": [ 299, 6, 377, 260 ], "ignore": 0, "iscrowd": 0, "area": 98020 }, { "id": 1, "image_id": 0, "category_id": 1, "segmentation": [], "bbox": [ 288, 300, 132, 90 ], "ignore": 0, "iscrowd": 0, "area": 11880 } ], "info": { "year": 2019, "version": "1.0", "contributor": "Label Studio" } } ``` -------------------------------- ### Create a Label Studio Project Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/annotate_data_from_gcs/annotate_data_from_gcs.ipynb Create a new Label Studio project with a specified title and label configuration. This example uses a configuration for image object detection. ```python project = ls.projects.create( title='Using Images from GCS', label_config=''' ''' ) ``` -------------------------------- ### Initialize Label Studio SDK and Project Variables Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/adding_new_labels_to_project.ipynb Set up necessary environment variables for Label Studio URL, API key, and project ID. Define the target tag name and the JSON payload for the new taxonomy structure. ```python import os # Label Studio instance - replace if using self-hosted app LABEL_STUDIO_URL = os.getenv("LABEL_STUDIO_URL", "http://localhost:8080") LABEL_STUDIO_API_KEY = os.getenv("LABEL_STUDIO_API_KEY") # The project ID where you want to add new labels project_id = int(os.getenv("LABEL_STUDIO_PROJECT_ID", "1")) # Taxonomy tag name where labels should be added in each project tag_name = 'taxonomy' # JSON payload representing the taxonomy tree to be added update_taxonomy = { 'New Top Level class': 1, 'Eukarya': { 'Cat': 1 }, 'New Class': { 'Object': 1, 'Nested classes': { 'And deeper hierarchy': { 'Object': 1 }, 'Another Object': 1 } } } ``` -------------------------------- ### CSV Export Example Output Source: https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/README.md Example of a TSV (tab-separated values) output for sentiment analysis tasks, showing the review text and its sentiment. ```tsv reviewText sentiment Good case, Excellent value. Positive What a waste of money and time! Negative The goose neck needs a little coaxing Neutral ``` -------------------------------- ### Path Troubleshooting Example for YOLO Source: https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/README.md Illustrates the calculation for the `--image-root-url` path based on your local file structure and Label Studio's document root setting. ```text `Absolute local path from Local Storage Settings` - `LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT` = `path for --image_root_url` ``` ```text /yolo/datasets/one/images - /yolo/datasets/ = one/images ``` -------------------------------- ### COCO JSON Annotation File Structure Example Source: https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/README.md Example structure of a COCO JSON annotation file, showing 'images', 'annotations', and 'categories' keys. ```json { "images": [ { "id": 139, "width": 426, "height": 640, "file_name": "000000000139.jpg" } ], "annotations": [ { "id": 1768, "image_id": 139, "category_id": 64, "bbox": [412.8, 157.61, 11.65, 12.64], "area": 147.24, "iscrowd": 0, "segmentation": [[...]] } ], "categories": [ { "id": 1, "name": "person", "supercategory": "person" } ] } ``` -------------------------------- ### Create Project via CLI Source: https://github.com/humansignal/label-studio-sdk/blob/master/README.md Create a new project using the label-studio-sdk CLI with title and label config. ```bash # Create a project (generic key=value params) label-studio-sdk projects create \ --param title="CLI Example" \ --param 'label_config=' ``` -------------------------------- ### Pascal VOC XML Output Example Source: https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/README.md This is an example of an annotation file in Pascal VOC XML format. It details image properties and object bounding boxes. ```xml tmp/images 62a623a0d3cef27a51d3689865e7b08a MyDatabase COCO2017 flickr NULL NULL Label Studio 800 501 3 0 Planet Unspecified 0 0 299 6 676 266 Moonwalker Unspecified 0 0 288 300 420 390 ``` -------------------------------- ### CSV Chat Transcript Example Row Source: https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/README.md This example shows how chat messages are exported to CSV. The original chat payload is in JSON format, and a human-readable transcript is added. ```text chat,"[{"role": "user", "content": "hi"},{"role": "assistant", "content": "Hello! How can I assist you today?"}]" chat_transcript,"user: hi\nassistant: Hello! How can I assist you today?" ``` -------------------------------- ### Enable Local Storage Serving (Unix) Source: https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/README.md Set environment variables to enable local file serving and specify the document root for Label Studio on Unix-like systems. ```bash export LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true export LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=/coco/dataset label-studio ``` -------------------------------- ### CoNLL 2003 Export Example Output Source: https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/README.md An example of the CoNLL 2003 format output, typically used for named entity recognition tasks. It shows tokens and their corresponding entity tags. ```text -DOCSTART- -X- O Showers -X- _ O continued -X- _ O throughout -X- _ O the -X- _ O week -X- _ O in -X- _ O the -X- _ O Bahia -X- _ B-Location cocoa -X- _ O zone, -X- _ O ... ``` -------------------------------- ### Initialize Label Studio SDK Client Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/import_preannotations/import_preannotations.ipynb Connect to the Label Studio API using the Client module. Ensure LABEL_STUDIO_URL and LABEL_STUDIO_API_KEY environment variables are set. ```python import os LABEL_STUDIO_URL = os.getenv('LABEL_STUDIO_URL', 'http://localhost:8080') LABEL_STUDIO_API_KEY = os.getenv('LABEL_STUDIO_API_KEY') from label_studio_sdk import LabelStudio ls = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=LABEL_STUDIO_API_KEY) ``` -------------------------------- ### Label Studio SDK CLI Usage Source: https://context7.com/humansignal/label-studio-sdk/llms.txt Examples of using the Label Studio SDK command-line interface for managing projects. Environment variables for API key and URL are recommended. ```bash export LABEL_STUDIO_API_KEY="YOUR_API_KEY" export LABEL_STUDIO_URL="http://localhost:8080" # List projects label-studio-sdk projects list # Create a project label-studio-sdk projects create \ --param title="My Project" \ --param 'label_config=' # Get full help for any command label-studio-sdk projects create --help # Run with uv without installing globally uv run --with label_studio_sdk label-studio-sdk projects list ``` -------------------------------- ### Create a Webhook with Label Studio SDK Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Create a new webhook for your organization. You must provide a URL. Optional parameters include actions, headers, and project association. ```python from label_studio_sdk import LabelStudio from label_studio_sdk.environment import LabelStudioEnvironment client = LabelStudio( api_key="", environment=LabelStudioEnvironment.DEFAULT, ) client.webhooks.create( url="url", ) ``` -------------------------------- ### client.organizations.invites.get_invite_link Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Get invite link for organization. ```APIDOC ## client.organizations.invites.get_invite_link ### Description Get invite link for organization. ### Method GET ### Endpoint /api/organizations/invites/invite-link ### Parameters (No parameters are explicitly documented for this operation) ### Request Example (No request example is provided in the source text) ### Response #### Success Response (200) - **url** (str) - The invite link URL. #### Response Example ```json { "url": "" } ``` ``` -------------------------------- ### Client Initialization Source: https://context7.com/humansignal/label-studio-sdk/llms.txt Instantiate the LabelStudio client with your Label Studio URL and API key. The API key can also be read from the LABEL_STUDIO_API_KEY environment variable. Both synchronous and asynchronous clients are available. ```APIDOC ## Client Initialization Instantiate `LabelStudio` with your Label Studio URL and API key. The API key can also be read from the `LABEL_STUDIO_API_KEY` environment variable. ```python from label_studio_sdk import LabelStudio # Basic initialization client = LabelStudio( base_url="http://localhost:8080", api_key="YOUR_API_KEY", ) # With custom timeout and logging from label_studio_sdk.core.logging import LogConfig client = LabelStudio( base_url="http://localhost:8080", api_key="YOUR_API_KEY", timeout=120.0, logging=LogConfig(level="debug", silent=False), ) # Async client from label_studio_sdk import AsyncLabelStudio import asyncio async_client = AsyncLabelStudio( base_url="http://localhost:8080", api_key="YOUR_API_KEY", ) ``` ``` -------------------------------- ### Label Studio Interface Scenario Example Source: https://github.com/humansignal/label-studio-sdk/blob/master/interface-cli.md Example of a scenario file used for validating Label Studio interfaces. Scenarios define tasks and expected outcomes, with the `run` function interacting with the Playwright page to simulate user actions. ```javascript export default [ { name: "selects a label", task: { data: { text: "Example text" } }, async run({ page }) { await page.getByRole("button", { name: "Positive" }).click(); }, expect: { visibleText: ["Example text"], results: [ { from_name: "sentiment", type: "choices", value: { choices: ["Positive"] }, }, ], }, }, ]; ``` -------------------------------- ### Initialize Label Studio SDK Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/annotate_data_from_gcs/annotate_data_from_gcs.ipynb Connect to the Label Studio API using your Label Studio URL and API key. The URL defaults to http://localhost:8080 if not specified. ```python from label_studio_sdk import LabelStudio LABEL_STUDIO_URL = os.getenv("LABEL_STUDIO_URL", "http://localhost:8080") API_KEY = os.getenv("LABEL_STUDIO_API_KEY") ls = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=API_KEY) ``` -------------------------------- ### Async Client for Project Creation and Task Import Source: https://context7.com/humansignal/label-studio-sdk/llms.txt Demonstrates using the asynchronous client for creating a project with a dynamic label configuration and concurrently importing tasks. Requires asyncio to run. ```python import asyncio from label_studio_sdk import AsyncLabelStudio from label_studio_sdk.label_interface import LabelInterface from label_studio_sdk.label_interface.create import choices async def main(): client = AsyncLabelStudio( base_url="http://localhost:8080", api_key="YOUR_API_KEY", ) # Create project label_config = LabelInterface.create({ 'text': 'Text', 'label': choices(['Spam', 'Ham']) }) project = await client.projects.create( title="Spam Classifier", label_config=label_config, ) # Import tasks concurrently await client.projects.import_tasks( id=project.id, request=[{"text": f"Message {i}"} for i in range(100)], ) # Retrieve and process annotations async for task in await client.tasks.list(project=project.id): for ann in (task.annotations or []): print(f"Task {task.id}: {ann.result}") asyncio.run(main()) ``` -------------------------------- ### Get Project Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Retrieve information about a project by its ID. ```APIDOC ## Get Project ### Description Retrieve information about a project by project ID. ### Method GET (implied by SDK method) ### Endpoint /api/projects/{id} ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the project to retrieve. #### Query Parameters - **members_limit** (typing.Optional[int]) - Optional - Maximum number of members to return - **request_options** (typing.Optional[RequestOptions]) - Optional - Request-specific configuration. ### Request Example ```python from label_studio_sdk import LabelStudio from label_studio_sdk.environment import LabelStudioEnvironment client = LabelStudio( api_key="", environment=LabelStudioEnvironment.DEFAULT, ) client.projects.get( id=1, ) ``` ### Response #### Success Response (200) - **(response structure not detailed in source)** #### Response Example **(response example not detailed in source)** ``` -------------------------------- ### Create New Project Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/getting_started.ipynb Creates a new project in Label Studio with a specified title and labeling configuration. The output shows the URL of the newly created project. ```python project = ls.projects.create( title='Text Classification', label_config=label_config ) print(f'Created project:\n{ls._client_wrapper.get_base_url()}/projects/{project.id}') ``` -------------------------------- ### client.import_storage.gcs.list Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Get a list of all GCS import storage connections. ```APIDOC ## client.import_storage.gcs.list ### Description Get a list of all GCS import storage connections. ### Method GET ### Endpoint /api/v1.5/import-storage/gcs ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python client.import_storage.gcs.list() ``` ### Response #### Success Response (200) Returns a list of GCS import storage configurations. #### Response Example ```json [ { "id": 1, "title": "My GCS Bucket", "description": "Connection to my main GCS bucket" } ] ``` ``` -------------------------------- ### client.export_storage.s3.list Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Get a list of all S3 export storage connections. ```APIDOC ## client.export_storage.s3.list ### Description Get a list of all S3 export storage connections. ### Method list ### Parameters #### Path Parameters - **project** (int) - Required - Project ID. #### Query Parameters - **ordering** (typing.Optional[str]) - Which field to use when ordering the results. #### Request Body - **request_options** (typing.Optional[RequestOptions]) - Request-specific configuration. ### Request Example ```python client.export_storage.s3.list( project=1, ordering='id' ) ``` ### Response #### Success Response (200) - **List[S3ExportStorage]** - A list of S3 export storage connections. ``` -------------------------------- ### Initialize Label Studio Client Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/active_learning/active_learning.ipynb Import the Client module and initialize the Label Studio client to establish a connection with the API. ```python from label_studio_sdk import LabelStudio ls = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=LABEL_STUDIO_API_KEY) ``` -------------------------------- ### Get organization by ID Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Retrieves a specific organization by its ID. ```python client.organizations.get( id="id", ) ``` -------------------------------- ### Initialize Label Studio Client Source: https://github.com/humansignal/label-studio-sdk/blob/master/tutorials/yolo_predictions.ipynb Initializes the Label Studio client using your API key. Ensure you replace 'YOUR_API_KEY' with your actual key. ```python from label_studio_sdk.client import LabelStudio API_KEY = 'YOUR_API_KEY' client = LabelStudio(api_key=API_KEY) ``` -------------------------------- ### Sidecar File Example Source: https://github.com/humansignal/label-studio-sdk/blob/master/interface-cli.md After a successful `sync` or `pull` operation, a sidecar file is generated next to the source file. This file, named `Screen.jsx.ls-interface.json` in this example, stores metadata like interface ID, title, and workspace ID, keyed by the Label Studio base URL. ```text Screen.jsx.ls-interface.json ``` -------------------------------- ### Create Label Studio Project Source: https://github.com/humansignal/label-studio-sdk/blob/master/tutorials/yolo_predictions.ipynb Creates a new Label Studio project with a specified title, description, and label configuration. This sets up the project for annotation. ```python project = client.projects.create( title='Object detection', description='Detect objects with YOLOv8', label_config=label_config ) ``` -------------------------------- ### Get Organization Settings Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Retrieve the settings for a specific organization by its ID. ```APIDOC ## Get Organization Settings ### Description Retrieve the settings for a specific organization by ID. ### Method GET (implied by SDK method) ### Endpoint (Not explicitly defined in source, inferred from SDK usage) ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the organization to retrieve. #### Query Parameters - **request_options** (typing.Optional[RequestOptions]) - Optional - Request-specific configuration. ### Request Example ```python client.organizations.get( id=1, ) ``` ### Response #### Success Response (200) (Response schema not explicitly defined in source) #### Response Example (Response example not explicitly defined in source) ``` -------------------------------- ### Create a New Label Studio Project Source: https://github.com/humansignal/label-studio-sdk/blob/master/tutorials/connect_to_ml_backend.ipynb Create a new project in Label Studio using the client. This project will be used to connect the ML backend. ```python project = ls.projects.create( title='Live OCR', description='A project to demonstrate live OCR with connected Tesseract model' ) ``` -------------------------------- ### client.users.get_token() Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Get a user token to authenticate to the API as the current user. ```APIDOC ## GET /users/token ### Description Get a user token to authenticate to the API as the current user. ### Method GET ### Endpoint /users/token ### Parameters #### Query Parameters - **request_options** (RequestOptions) - Optional - Request-specific configuration. ### Response #### Success Response (200) - **token** (str) - The user token. ### Response Example ```json { "token": "user_token" } ``` ``` -------------------------------- ### Connect to Label Studio Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/view_management.ipynb Establishes a connection to the Label Studio instance. Ensure LABEL_STUDIO_URL and LABEL_STUDIO_API_KEY environment variables are set. ```python import os from label_studio_sdk import LabelStudio ls = LabelStudio( base_url=os.getenv('LABEL_STUDIO_URL', 'http://localhost:8080'), api_key=os.getenv('LABEL_STUDIO_API_KEY') ) ``` -------------------------------- ### Get Agreement V2 Backfill Job Status Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Retrieve the status of an Agreement V2 backfill job. By default, returns aggregated organization status. Specify job_id or project_id to get a specific job status. Requires administrator or owner role and the Agreement V2 feature flag. ```python from label_studio_sdk import LabelStudio from label_studio_sdk.environment import LabelStudioEnvironment client = LabelStudio( api_key="", environment=LabelStudioEnvironment.DEFAULT, ) client.dimensions.get_backfill_status() ``` -------------------------------- ### Create Project and View with Filters Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/view_management.ipynb Creates a new Label Studio project with a specified label configuration and then creates a view for that project using predefined filters. Filters can be based on task ID, completion time, and other criteria. ```python from label_studio_sdk.data_manager import Filters, Column, Operator, Type from datetime import datetime project = ls.projects.create( title='Project Created from SDK', label_config=''' ''' ) filters = Filters.create(Filters.OR, [ Filters.item( Column.id, Operator.GREATER, Type.Number, Filters.value(42) ), Filters.item( Column.completed_at, Operator.IN, Type.Datetime, Filters.value( datetime(2021, 11, 1), datetime(2021, 11, 5), ) ) ]) view = ls.views.create(project=project.id, data={'filters': filters}) ``` -------------------------------- ### Get Data Quality Agreement Distribution Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Returns the distribution of agreement scores. ```APIDOC ## Get Data Quality Agreement Distribution ### Description Returns the distribution of agreement scores. ### Method GET ### Endpoint /projects/{id}/stats/data-quality/agreement/distribution ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the project. #### Query Parameters - **request_options** (RequestOptions) - Optional - Request-specific configuration. ### Request Example ```python client.projects.stats.data_quality_agreement_distribution(id=1) ``` ### Response #### Success Response (200) - **distribution** (dict) - The distribution of agreement scores. #### Response Example ```json { "distribution": { "0.8-0.9": 50, "0.9-1.0": 150 } } ``` ``` -------------------------------- ### Enable Local Storage Serving (Windows) Source: https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/converter/README.md Set environment variables to enable local file serving and specify the document root for Label Studio on Windows systems. ```batch set LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true set LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=C:\\coco\\dataset label-studio ``` -------------------------------- ### get() Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Retrieves details for a specific S3 export storage connection by its ID. ```APIDOC ## get(id: int) ### Description Get a specific S3 export storage connection. ### Method GET ### Endpoint /api/export-storage/s3/{id} ### Parameters #### Path Parameters - **id** (int) - Required - Storage ID. #### Query Parameters - **request_options** (Optional[RequestOptions]) - Request-specific configuration. ``` -------------------------------- ### Connect to Label Studio Enterprise Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/label_studio_enterprise/user_management.ipynb Initialize the Label Studio client by providing the base URL and API key. Ensure LABEL_STUDIO_URL and LABEL_STUDIO_API_KEY environment variables are set. ```python import os from label_studio_sdk.client import LabelStudio ls = LabelStudio(base_url=os.getenv('LABEL_STUDIO_URL', 'https://app.humansignal.com'), api_key=os.getenv('LABEL_STUDIO_API_KEY')) ``` -------------------------------- ### Get Prediction Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Retrieves the details of a specific prediction using its unique ID. ```APIDOC ## get ### Description Get details about a specific prediction by its ID. ### Method `client.predictions.get` ### Parameters #### Parameters - **id** (int) - Prediction ID. - **request_options** (Optional[RequestOptions]) - Request-specific configuration. ### Request Example ```python client.predictions.get( id=1, ) ``` ``` -------------------------------- ### Create a User in Label Studio Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Creates a new user in Label Studio. Various details like email, name, and avatar can be provided. ```python from label_studio_sdk import LabelStudio from label_studio_sdk.environment import LabelStudioEnvironment client = LabelStudio( api_key="", environment=LabelStudioEnvironment.DEFAULT, ) client.users.create() ``` -------------------------------- ### List ML Backends for a Project Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Lists all configured ML backends for a specific project. Requires the project ID. The cURL example shows how to make the request. ```bash curl http://localhost:8000/api/ml?project={project_id} -H 'Authorization: Token abc123' ``` ```python from label_studio_sdk import LabelStudio from label_studio_sdk.environment import LabelStudioEnvironment client = LabelStudio( api_key="", environment=LabelStudioEnvironment.DEFAULT, ) client.ml.list() ``` -------------------------------- ### Get Export Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Retrieve information about an export file by export ID for a specific project. ```APIDOC ## get ### Description Retrieve information about an export file by export ID for a specific project. ### Method client.projects.exports.get ### Parameters #### Path Parameters - **id** (int) - Required - A unique integer value identifying this project. - **export_pk** (int) - Required - Primary key identifying the export file. #### Request Body None ### Request Example ```python client.projects.exports.get( id=1, export_pk=123 ) ``` ### Response #### Success Response (200) - **export_details** (Export) - Details of the specified export file. ### Response Example ```json { "id": 123, "project": 1, "created_at": "2023-01-01T10:00:00Z", "status": "completed", "download_url": "/api/v1/projects/1/exports/123/download" } ``` ``` -------------------------------- ### client.users.create() Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Creates a new user in Label Studio. Various user details can be provided. ```APIDOC ## POST /users ### Description Create a user in Label Studio. ### Method POST ### Endpoint /api/users ### Parameters #### Request Body - **email** (Optional[str]) - Email of the user. - **username** (Optional[str]) - Username of the user. - **first_name** (Optional[str]) - First name of the user. - **last_name** (Optional[str]) - Last name of the user. - **phone** (Optional[str]) - Phone number of the user. - **avatar** (Optional[str]) - Avatar URL of the user. - **initials** (Optional[str]) - Initials of the user. - **allow_newsletters** (Optional[bool]) - Whether the user allows newsletters. - **id** (Optional[int]) - User ID (typically assigned by the server). - **request_options** (Optional[RequestOptions]) - Request-specific configuration. ### Response #### Success Response (201) - **user** (LseUser) - The created user object. ### Response Example ```json { "id": 1, "email": "newuser@example.com", "username": "newuser", "first_name": "Jane", "last_name": "Doe" } ``` ``` -------------------------------- ### Get Organization Member Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Retrieves details for a specific organization member by user ID. ```APIDOC ## Get Organization Member ### Description Get organization member details by user ID. ### Method GET (assumed based on SDK usage, actual HTTP method not specified) ### Endpoint `/organizations/{organization_id}/members/{user_pk}` (inferred from SDK usage) ### Parameters #### Path Parameters - **id** (int) - Required - Organization ID. - **user_pk** (int) - Required - A unique integer value identifying the user to get organization details for. #### Query Parameters - **contributed_to_projects** (Optional[bool]) - Whether to include projects created and contributed to by the member. #### Request Body - **request_options** (Optional[RequestOptions]) - Request-specific configuration. ### Request Example ```python client.organizations.members.get( id=1, user_pk=1, contributed_to_projects=True ) ``` ### Response #### Success Response (200) - **OrganizationMember** (OrganizationMember) - Details of the organization member. #### Response Example (No example provided in source) ``` -------------------------------- ### client.import_storage.local.list Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Get a list of all local file import storage connections for a given project. ```APIDOC ## client.import_storage.local.list ### Description Get a list of all local file import storage connections. ### Method GET ### Endpoint /api/projects/{project}/import-storage/local ### Parameters #### Path Parameters - **project** (int) - Required - A unique integer value identifying this project. #### Query Parameters This endpoint does not have query parameters. #### Request Body This endpoint does not have a request body. ### Response #### Success Response (200) - **connections** (list) - A list of local file import storage connections. - Each connection is an object with details like `id`, `title`, `description`, etc. #### Response Example ```json [ { "id": 1, "title": "Local Files", "description": "Local files on the server", "created_at": "2023-01-01T10:00:00Z", "updated_at": "2023-01-01T10:00:00Z" } ] ``` ``` -------------------------------- ### Open Saved Interface Source: https://github.com/humansignal/label-studio-sdk/blob/master/interface-cli.md Use the `open` command to launch a previously saved interface using its local sidecar file. Ensure `sync` has been run first to populate the sidecar with the interface ID for the selected Label Studio URL. ```bash label-studio-sdk interface open Screen.jsx ``` ```bash label-studio-sdk interface open Screen.jsx --no-open ``` -------------------------------- ### Create an ML Backend Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Adds an ML backend to a project. This can be done via the Label Studio UI or by sending a POST request with the backend details. The cURL example demonstrates the POST request format. ```bash curl -X POST -H 'Content-type: application/json' http://localhost:8000/api/ml -H 'Authorization: Token abc123'\n --data '{"url": "http://localhost:9090", "project": {project_id}}' ``` ```python from label_studio_sdk import LabelStudio from label_studio_sdk.environment import LabelStudioEnvironment client = LabelStudio( api_key="", environment=LabelStudioEnvironment.DEFAULT, ) client.ml.create() ``` -------------------------------- ### Initialize Label Studio Client Source: https://github.com/humansignal/label-studio-sdk/blob/master/examples/adding_new_labels_to_project.ipynb Instantiate the Label Studio client using the base URL and API key. This client is used to interact with the Label Studio API for project operations. ```python from label_studio_sdk.client import LabelStudio ls = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=LABEL_STUDIO_API_KEY) ``` -------------------------------- ### List Compatible Projects for a Prompt with Label Studio SDK Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Retrieve a list of projects compatible with a specific prompt. Supports pagination and ordering. ```python from label_studio_sdk import LabelStudio from label_studio_sdk.environment import LabelStudioEnvironment client = LabelStudio( api_key="", environment=LabelStudioEnvironment.DEFAULT, ) client.prompts.compatible_projects() ``` -------------------------------- ### Get Data Quality Agreement Dimensions Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Returns per-dimension agreement scores for active dimensions. ```APIDOC ## Get Data Quality Agreement Dimensions ### Description Returns per-dimension agreement scores for active dimensions. ### Method GET ### Endpoint /projects/{id}/stats/data-quality/agreement/dimensions ### Parameters #### Path Parameters - **id** (int) - Required - The ID of the project. #### Query Parameters - **request_options** (RequestOptions) - Optional - Request-specific configuration. ### Request Example ```python client.projects.stats.data_quality_agreement_dimensions(id=1) ``` ### Response #### Success Response (200) - **dimensions** (list) - A list of agreement scores for each dimension. #### Response Example ```json [ { "dimension": "label", "agreement": 0.85 } ] ``` ``` -------------------------------- ### client.project_templates.list Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Get a list of all project templates for an organization. This endpoint is only available in Label Studio Enterprise. ```APIDOC ## client.project_templates.list ### Description Get a list of all project templates for an organization. This endpoint is not available in Label Studio Community Edition. ### Method GET ### Endpoint /api/project-templates ### Parameters #### Query Parameters - **ordering** (typing.Optional[str]) - Optional - Which field to use when ordering the results. - **request_options** (typing.Optional[RequestOptions]) - Optional - Request-specific configuration. ### Response #### Success Response (200) - **ProjectTemplate** (typing.List[ProjectTemplate]) - A list of project templates. ``` -------------------------------- ### Preview Label Studio Interface Source: https://github.com/humansignal/label-studio-sdk/blob/master/interface-cli.md Open the Label Studio interface playground to live-sync source changes. This command starts a local file watcher that pushes updates to the playground on save. You can specify task data and a Label Studio backend URL. ```bash label-studio-sdk interface preview ./my-interface ``` ```bash label-studio-sdk interface preview Screen.jsx --task task.json ``` ```bash label-studio-sdk interface preview Screen.jsx --task task.json --no-open ``` ```bash label-studio-sdk interface preview Screen.jsx --lse-url http://localhost:8080 ``` -------------------------------- ### client.states.state_history Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Get the state history of an entity. This endpoint is available in Label Studio Enterprise Edition. ```APIDOC ## client.states.state_history ### Description Get the state history of an entity. ### Parameters #### Path Parameters - **entity_name** (str) - Required - The name of the entity. - **entity_id** (int) - Required - The ID of the entity. #### Query Parameters - **created_at_from** (str) - Optional - Filter for state history items created at or after the ISO 8601 formatted date (YYYY-MM-DDTHH:MM:SS). - **created_at_to** (str) - Optional - Filter for state history items created at or before the ISO 8601 formatted date (YYYY-MM-DDTHH:MM:SS). - **ordering** (str) - Optional - Which field to use when ordering the results. - **page** (int) - Optional - A page number within the paginated result set. - **page_size** (int) - Optional - Number of results to return per page. - **previous_state** (str) - Optional - Filter previous_state by exact match (case-insensitive). - **state** (str) - Optional - Filter state by exact match (case-insensitive). - **transition_name** (str) - Optional - Filter transition_name by exact match (case-insensitive). - **triggered_by** (float) - Optional - Filter triggered_by by exact match. #### Request Body - **request_options** (RequestOptions) - Optional - Request-specific configuration. ``` -------------------------------- ### client.prompts.compatible_projects Source: https://github.com/humansignal/label-studio-sdk/blob/master/reference.md Retrieves a list of projects compatible with a given prompt. ```APIDOC ## client.prompts.compatible_projects ### Description Retrieve a list of compatible projects for a prompt. ### Method GET ### Endpoint /api/prompts/compatible-projects ### Parameters #### Query Parameters - **ordering** (str) - Optional - Which field to use when ordering the results. - **page** (int) - Optional - A page number within the paginated result set. - **page_size** (int) - Optional - Number of results to return per page. - **project_type** (CompatibleProjectsPromptsRequestProjectType) - Optional - Skill to filter by. - **request_options** (RequestOptions) - Optional - Request-specific configuration. ### Response #### Success Response (200) - **results** (list) - A list of compatible projects. - **count** (int) - The total number of compatible projects. - **next** (str) - URL for the next page of results. - **previous** (str) - URL for the previous page of results. #### Response Example ```json { "results": [ { "id": 1, "name": "Project A", "created_at": "2023-10-27T10:00:00Z" } ], "count": 1, "next": null, "previous": null } ``` ```