# humansignal/label-studio-sdk architecture

> Architecture diagram of the GitHub repository humansignal/label-studio-sdk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/humansignal/label-studio-sdk
- Repository: https://github.com/humansignal/label-studio-sdk

## Overview

##### Project Type and Purpose
- This is a **client-SDK** for Label Studio: a Python library that provides synchronous and asynchronous wrappers around the Label Studio REST API.
- Purpose: Allow Python applications to interact programmatically with Label Studio (create projects, import/export data, manage users, trigger ML backends, etc.).

##### File Structure
- **Top-level** directories:
- `src/label_studio_sdk/` – the heart of the library
- `examples/` – code samples showing how to use the SDK
- `tests/` – extensive unit/integration tests
- `.mock/` – API definitions and sample OpenAPI spec (used for code generation via Fern)
- `.github/` – CI/CD, release and workflow definitions
- **Key subpackages** under `src/label_studio_sdk/`:
- `core/` – HTTP client wrapper, pagination, serialization utilities
- `client.py`, `base_client.py` – entry points for `LabelStudio` and `AsyncLabelStudio`
- Domain-specific clients: `projects/`, `tasks/`, `annotations/`, `comments/`, `import_storage/`, `export_storage/`, `files/`, `prompts/`, `webhooks/`, `workspaces/`, `ml/`, etc.
- `converter/` – transforms between Label Studio’s JSON schema and common annotation formats (COCO, YOLO, CSV…)
- `label_interface/` – helpers to build label configuration XML/JSON
- `_extensions/` – advanced tooling for ETL or custom evaluation extensions
- **Build & Release Files**: `pyproject.toml`, GitHub workflows under `.github/workflows/`

##### README for Additional Insights
- Confirms the two entry points (`LabelStudio`, `AsyncLabelStudio`)
- Shows usage patterns: instantiation with `base_url` + `api_key`, then `.projects.create()`, `.tasks.list()`, etc.
- Mentions advanced customization of HTTP client and timeouts

##### Main Components
a. **User Application**
- Your Python code or notebook that imports `label_studio_sdk` and calls methods
b. **SDK Entry Points**
- `Sync` client (`LabelStudio`)
- `Async` client (`AsyncLabelStudio`)
c. **Core HTTP Layer**
- `httpx` or custom HTTP client injected by the user
- Wrappers in `core/http_client.py`, `core/client_wrapper.py`
d. **Domain Clients & Utilities**
- Modules under `projects/`, `tasks/`, `annotations/`, etc.
- Shared utilities: pagination, serialization, error handling in `core/`
- `converter/` for import/export transformations
- `label_interface/` for label config construction
e. **Code-Generation Artifacts**
- `.mock/definition/*` and `openapi/openapi.yaml` (source of truth for API schemas)
f. **External Dependencies**
- External storage services: S3, GCS, Azure Blob, local disk, Redis (via import/export modules)
- Optional ML backends (triggered via `ml/` client)
g. **CI/CD & Testing**
- GitHub Actions workflows
- Unit & integration tests under `tests/`
h. **Examples & Tutorials**
- Code samples showing real-world usage

##### Relationships and Interactions
- **Flow**: User App → SDK Entry Point → Core HTTP Layer → Label Studio REST API → Server
- **Import/Export**: Domain client calls converter modules → writes/reads from storage clients (S3, GCS, etc.)
- **Extensions**: Optional pipelines via `_extensions/label_studio_tools` or `_extensions/eval`
- **Custom HTTP Client**: User-supplied client plugs into the core HTTP layer

##### Architectural Patterns & Design Principles
- **Modular**: Each domain has its own subpackage (Separation of Concerns)
- **Client-Server**: SDK on client side; Label Studio on server side
- **Adapter/Wrapper**: The SDK adapts raw REST calls into Pythonic methods
- **Code-Generation Driven**: API schemas under `.mock/` drive generation of types and clients
- **Sync vs Async**: Two parallel entry points sharing most of the same internal layers

##### Final Checklist
- Break the system into these main layers:
1. User Application
2. SDK Entry Points (Sync / Async)
3. Core HTTP & Utilities
4. Domain Clients (projects, tasks, annotations, etc.)
5. Converter & Label Interface
6. External Services (REST API, Storage, ML backends)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    subgraph "User Layer"
        UA["User Application"]:::example
    end

    %% SDK Entry Points
    subgraph "SDK Entry Points"
        LS["LabelStudio (Sync)"]:::sdk
        BC["BaseClient & AsyncLabelStudio"]:::sdk
    end

    %% Core HTTP & Utilities
    subgraph "Core HTTP & Utilities"
        HC["http_client.py"]:::sdk
        CW["client_wrapper.py"]:::sdk
        PG["pagination.py"]:::sdk
        SE["serialization.py"]:::sdk
        ER["api_error.py"]:::sdk
    end

    %% Domain Clients
    subgraph "Domain Clients"
        PR["projects/client.py"]:::sdk
        TA["tasks/client.py"]:::sdk
        AN["annotations/client.py"]:::sdk
        CO["comments/client.py"]:::sdk
        FI["files/client.py"]:::sdk
        WH["webhooks/client.py"]:::sdk
        WO["workspaces/client.py"]:::sdk
        ML["ml/client.py"]:::sdk
    end

    %% Converter & Interface
    subgraph "Converter & Interface"
        CN["converter/"]:::sdk
        LI["label_interface/"]:::sdk
    end

    %% Storage Adapters
    subgraph "Storage Adapters"
        IM["import_storage/"]:::sdk
        EXA["export_storage/"]:::sdk
    end

    %% Extensions
    subgraph "Extensions"
        EXTN["_extensions/"]:::sdk
    end

    %% External Services
    subgraph "External Services"
        LSAPI["Label Studio REST API"]:::external
        STORAGE["S3, GCS, Azure, Redis"]:::external
        MLB["ML Backends"]:::external
    end

    %% Code Generation & CI
    subgraph "Code Generation & CI"
        CG[".mock/definition & openapi.yaml"]:::codegen
        CI[".github/workflows/"]:::codegen
        TE["tests/"]:::codegen
        PRJ["pyproject.toml"]:::codegen
        EXS["examples/"]:::example
    end

    %% Connections
    UA -->|uses| LS
    UA -->|uses| BC
    UA -.->|custom HTTP client| HC

    LS -->|calls| PR
    LS -->|calls| TA
    LS -->|calls| AN
    LS -->|calls| CO
    LS -->|calls| FI
    LS -->|calls| WH
    LS -->|calls| WO
    LS -->|calls| ML

    BC -->|calls| PR
    BC -->|calls| TA

    PR -->|uses| HC
    TA -->|uses| HC
    AN -->|uses| HC
    CO -->|uses| HC
    FI -->|uses| HC
    WH -->|uses| HC
    WO -->|uses| HC
    ML -->|uses| HC

    HC -->|executes HTTP| LSAPI

    PR -->|uses| PG
    PR -->|uses| SE
    PR -->|uses| ER

    CN -->|transforms| IM
    CN -->|transforms| EXA
    LI -->|builds config| LSAPI

    IM -->|stores| STORAGE
    EXA -->|stores| STORAGE

    ML -->|triggers| MLB

    CG -->|drives generation| PR
    CG -->|drives generation| TA

    CI -->|runs tests| TE
    CI -->|builds| PRJ

    EXS -->|demonstrates| LS
    EXS -->|demonstrates| BC

    EXTN -.->|extends| CN
    EXTN -.->|extends| PR

    %% Click Events
    click EXS "https://github.com/humansignal/label-studio-sdk/tree/master/examples/"
    click LS "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/client.py"
    click BC "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/base_client.py"
    click HC "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/core/http_client.py"
    click CW "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/core/client_wrapper.py"
    click PG "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/core/pagination.py"
    click SE "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/core/serialization.py"
    click ER "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/core/api_error.py"
    click PR "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/projects/client.py"
    click TA "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/tasks/client.py"
    click AN "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/annotations/client.py"
    click CO "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/comments/client.py"
    click FI "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/files/client.py"
    click WH "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/webhooks/client.py"
    click WO "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/workspaces/client.py"
    click ML "https://github.com/humansignal/label-studio-sdk/blob/master/src/label_studio_sdk/ml/client.py"
    click CN "https://github.com/humansignal/label-studio-sdk/tree/master/src/label_studio_sdk/converter/"
    click LI "https://github.com/humansignal/label-studio-sdk/tree/master/src/label_studio_sdk/label_interface/"
    click IM "https://github.com/humansignal/label-studio-sdk/tree/master/src/label_studio_sdk/import_storage/"
    click EXA "https://github.com/humansignal/label-studio-sdk/tree/master/src/label_studio_sdk/export_storage/"
    click EXTN "https://github.com/humansignal/label-studio-sdk/tree/master/src/label_studio_sdk/_extensions/"
    click CG "https://github.com/humansignal/label-studio-sdk/tree/master/.mock/definition/"
    click CG "https://github.com/humansignal/label-studio-sdk/blob/master/.mock/openapi/openapi.yaml"
    click CI "https://github.com/humansignal/label-studio-sdk/tree/master/.github/workflows/"
    click TE "https://github.com/humansignal/label-studio-sdk/tree/master/tests/"
    click PRJ "https://github.com/humansignal/label-studio-sdk/blob/master/pyproject.toml"

    %% Styles
    classDef sdk fill:#bee3f8,stroke:#333,stroke-width:1px
    classDef external fill:#c6f6d5,stroke:#333,stroke-width:1px
    classDef codegen fill:#e2e8f0,stroke:#333,stroke-width:1px
    classDef example fill:#f0fff4,stroke:#333,stroke-width:1px
```
