Skip to content

rg.Workspace

In Argilla, workspaces are used to organize datasets in to groups. For example, you might have a workspace for each project or team.

Usage Examples

To create a new workspace, instantiate the Workspace object with the client and the name:

workspace = rg.Workspace(name="my_workspace")
workspace.create()

To retrieve an existing workspace, use the client.workspaces attribute:

workspace = client.workspaces("my_workspace")

Workspace

Bases: Resource

Class for interacting with Argilla workspaces. Workspaces are used to organize datasets in the Argilla server.

Attributes:

Name Type Description
name str

The name of the workspace.

id UUID

The ID of the workspace. This is a unique identifier for the workspace in the server.

datasets List[Dataset]

A list of all datasets in the workspace.

users WorkspaceUsers

A list of all users in the workspace.

Source code in src/argilla/workspaces/_resource.py
class Workspace(Resource):
    """Class for interacting with Argilla workspaces. Workspaces are used to organize datasets in the Argilla server.

    Attributes:
        name (str): The name of the workspace.
        id (UUID): The ID of the workspace. This is a unique identifier for the workspace in the server.
        datasets (List[Dataset]): A list of all datasets in the workspace.
        users (WorkspaceUsers): A list of all users in the workspace.
    """

    name: Optional[str]

    _api: "WorkspacesAPI"

    def __init__(
        self,
        name: Optional[str] = None,
        id: Optional[UUID] = None,
        client: Optional["Argilla"] = None,
    ) -> None:
        """Initializes a Workspace object with a client and a name or id

        Parameters:
            client (Argilla): The client used to interact with Argilla
            name (str): The name of the workspace
            id (UUID): The id of the workspace

        Returns:
            Workspace: The initialized workspace object
        """
        client = client or Argilla._get_default()
        super().__init__(client=client, api=client.api.workspaces)

        self._model = WorkspaceModel(name=name, id=id)

    def add_user(self, user: Union["User", str]) -> "User":
        """Adds a user to the workspace. After adding a user to the workspace, it will have access to the datasets
        in the workspace.

        Args:
            user (Union[User, str]): The user to add to the workspace. Can be a User object or a username.

        Returns:
            User: The user that was added to the workspace
        """
        return self.users.add(user)

    def remove_user(self, user: Union["User", str]) -> "User":
        """Removes a user from the workspace. After removing a user from the workspace, it will no longer have access

        Args:
            user (Union[User, str]): The user to remove from the workspace. Can be a User object or a username.

        Returns:
            User: The user that was removed from the workspace.
        """
        return self.users.delete(user)

    # TODO: Make this method private
    def list_datasets(self) -> List["Dataset"]:
        from argilla.datasets import Dataset

        datasets = self._client.api.datasets.list(self.id)
        self._log_message(f"Got {len(datasets)} datasets for workspace {self.id}")
        return [Dataset.from_model(model=dataset, client=self._client) for dataset in datasets]

    @classmethod
    def from_model(cls, model: WorkspaceModel, client: Argilla) -> "Workspace":
        instance = cls(name=model.name, id=model.id, client=client)
        instance._model = model

        return instance

    ############################
    # Properties
    ############################

    @property
    def name(self) -> Optional[str]:
        return self._model.name

    @name.setter
    def name(self, value: str) -> None:
        self._model.name = value

    @property
    def datasets(self) -> List["Dataset"]:
        """List all datasets in the workspace

        Returns:
            List[Dataset]: A list of all datasets in the workspace
        """
        return self.list_datasets()

    @property
    def users(self) -> "WorkspaceUsers":
        """List all users in the workspace

        Returns:
            WorkspaceUsers: A list of all users in the workspace
        """
        return WorkspaceUsers(workspace=self)
datasets: List[Dataset] property

List all datasets in the workspace

Returns:

Type Description
List[Dataset]

List[Dataset]: A list of all datasets in the workspace

users: WorkspaceUsers property

List all users in the workspace

Returns:

Name Type Description
WorkspaceUsers WorkspaceUsers

A list of all users in the workspace

__init__(name=None, id=None, client=None)

Initializes a Workspace object with a client and a name or id

Parameters:

Name Type Description Default
client Argilla

The client used to interact with Argilla

None
name str

The name of the workspace

None
id UUID

The id of the workspace

None

Returns:

Name Type Description
Workspace None

The initialized workspace object

Source code in src/argilla/workspaces/_resource.py
def __init__(
    self,
    name: Optional[str] = None,
    id: Optional[UUID] = None,
    client: Optional["Argilla"] = None,
) -> None:
    """Initializes a Workspace object with a client and a name or id

    Parameters:
        client (Argilla): The client used to interact with Argilla
        name (str): The name of the workspace
        id (UUID): The id of the workspace

    Returns:
        Workspace: The initialized workspace object
    """
    client = client or Argilla._get_default()
    super().__init__(client=client, api=client.api.workspaces)

    self._model = WorkspaceModel(name=name, id=id)
add_user(user)

Adds a user to the workspace. After adding a user to the workspace, it will have access to the datasets in the workspace.

Parameters:

Name Type Description Default
user Union[User, str]

The user to add to the workspace. Can be a User object or a username.

required

Returns:

Name Type Description
User User

The user that was added to the workspace

Source code in src/argilla/workspaces/_resource.py
def add_user(self, user: Union["User", str]) -> "User":
    """Adds a user to the workspace. After adding a user to the workspace, it will have access to the datasets
    in the workspace.

    Args:
        user (Union[User, str]): The user to add to the workspace. Can be a User object or a username.

    Returns:
        User: The user that was added to the workspace
    """
    return self.users.add(user)
remove_user(user)

Removes a user from the workspace. After removing a user from the workspace, it will no longer have access

Parameters:

Name Type Description Default
user Union[User, str]

The user to remove from the workspace. Can be a User object or a username.

required

Returns:

Name Type Description
User User

The user that was removed from the workspace.

Source code in src/argilla/workspaces/_resource.py
def remove_user(self, user: Union["User", str]) -> "User":
    """Removes a user from the workspace. After removing a user from the workspace, it will no longer have access

    Args:
        user (Union[User, str]): The user to remove from the workspace. Can be a User object or a username.

    Returns:
        User: The user that was removed from the workspace.
    """
    return self.users.delete(user)