source code Browse git
from pydantic import BaseModel
from typing import List, Optional
from .users import User
from .client import Client


class Workspace(BaseModel):
    id: int
    title: str
    description: Optional[str]
    color: str
    is_personal: bool
    created_by: int
    client: Client

    class Config:
        arbitrary_types_allowed = True

    def add_user(self, user: User):
        """ Add user to workspace

        Parameters
        ----------
        user: label_studio_sdk.users.User
            User
        """
        response = self.client.make_request(
            'POST', f'/api/workspaces/{self.id}/memberships',
            json={'workspace': self.id, 'user': user.id})
        return response.json()

    def remove_user(self, user: User):
        """ Remove user from workspace

        Parameters
        ----------
        user: label_studio_sdk.users.User
            User
        """
        response = self.client.make_request(
            'DELETE', f'/api/workspaces/{self.id}/memberships',
            json={'workspace': self.id, 'user': user.id})
        if response.status_code != 204:
            raise ValueError(str(response.content))

    def get_projects(self):
        """ Get projects in current workspace

        Returns
        -------
        projects: list of label_studio_sdk.project.Project
            Project
        """
        from .project import Project
        final_results = []
        response = self.client.make_request(
            'GET', f'/api/workspaces/{self.id}/projects'
        )
        projects = response.json()
        for project_data in projects:
            project_id = project_data['id']
            final_results.append(Project.get_from_id(client=self.client,
                                                     project_id=project_id,
                                                     ))
        return final_results

Classes

class Workspace (**data: Any)

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

source code Browse git
class Workspace(BaseModel):
    id: int
    title: str
    description: Optional[str]
    color: str
    is_personal: bool
    created_by: int
    client: Client

    class Config:
        arbitrary_types_allowed = True

    def add_user(self, user: User):
        """ Add user to workspace

        Parameters
        ----------
        user: label_studio_sdk.users.User
            User
        """
        response = self.client.make_request(
            'POST', f'/api/workspaces/{self.id}/memberships',
            json={'workspace': self.id, 'user': user.id})
        return response.json()

    def remove_user(self, user: User):
        """ Remove user from workspace

        Parameters
        ----------
        user: label_studio_sdk.users.User
            User
        """
        response = self.client.make_request(
            'DELETE', f'/api/workspaces/{self.id}/memberships',
            json={'workspace': self.id, 'user': user.id})
        if response.status_code != 204:
            raise ValueError(str(response.content))

    def get_projects(self):
        """ Get projects in current workspace

        Returns
        -------
        projects: list of label_studio_sdk.project.Project
            Project
        """
        from .project import Project
        final_results = []
        response = self.client.make_request(
            'GET', f'/api/workspaces/{self.id}/projects'
        )
        projects = response.json()
        for project_data in projects:
            project_id = project_data['id']
            final_results.append(Project.get_from_id(client=self.client,
                                                     project_id=project_id,
                                                     ))
        return final_results

Constants

Config
clientClient
color : str
created_by : int
description : Optional[str]
id : int
is_personal : bool
title : str

Methods

def add_user(self, user: User)

Add user to workspace

Parameters

user : User
User
source code Browse git
def add_user(self, user: User):
    """ Add user to workspace

    Parameters
    ----------
    user: label_studio_sdk.users.User
        User
    """
    response = self.client.make_request(
        'POST', f'/api/workspaces/{self.id}/memberships',
        json={'workspace': self.id, 'user': user.id})
    return response.json()
def get_projects(self)

Get projects in current workspace

Returns

projects : list of Project
Project
source code Browse git
def get_projects(self):
    """ Get projects in current workspace

    Returns
    -------
    projects: list of label_studio_sdk.project.Project
        Project
    """
    from .project import Project
    final_results = []
    response = self.client.make_request(
        'GET', f'/api/workspaces/{self.id}/projects'
    )
    projects = response.json()
    for project_data in projects:
        project_id = project_data['id']
        final_results.append(Project.get_from_id(client=self.client,
                                                 project_id=project_id,
                                                 ))
    return final_results
def remove_user(self, user: User)

Remove user from workspace

Parameters

user : User
User
source code Browse git
def remove_user(self, user: User):
    """ Remove user from workspace

    Parameters
    ----------
    user: label_studio_sdk.users.User
        User
    """
    response = self.client.make_request(
        'DELETE', f'/api/workspaces/{self.id}/memberships',
        json={'workspace': self.id, 'user': user.id})
    if response.status_code != 204:
        raise ValueError(str(response.content))