Skip to content

[PLT-1304] Add Project get_labeling_service #1742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/labelbox/labeling-service.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Project Labeling Service
===============================================================================================

.. automodule:: labelbox.schema.labeling_service
:members:
:show-inheritance:
29 changes: 29 additions & 0 deletions libs/labelbox/src/labelbox/schema/labeling_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from datetime import datetime
from enum import Enum

from labelbox.data.annotation_types.types import Cuid
from labelbox.orm.db_object import experimental
from labelbox.pydantic_compat import BaseModel
from labelbox.utils import _CamelCaseMixin


class LabelingServiceStatus(Enum):
Accepted = 'ACCEPTED',
Calibration = 'CALIBRATION',
Complete = 'COMPLETE',
Production = 'PRODUCTION',
Requested = 'REQUESTED',
SetUp = 'SET_UP'


@experimental
class LabelingService(_CamelCaseMixin, BaseModel):
id: Cuid
project_id: Cuid
created_at: datetime
updated_at: datetime
created_by_id: Cuid
status: LabelingServiceStatus

def status_as_string(self):
return self.status.value
30 changes: 30 additions & 0 deletions libs/labelbox/src/labelbox/schema/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, TypeVar, Union, overload
from urllib.parse import urlparse

from labelbox.schema.labeling_service import LabelingService
import requests

from labelbox import parser
Expand Down Expand Up @@ -1904,6 +1905,35 @@ def clone(self) -> "Project":
result = self.client.execute(mutation, {"projectId": self.uid})
return self.client.get_project(result["cloneProject"]["id"])

@experimental
def get_labeling_service(self) -> LabelingService:
"""
Returns the labeling service associated with the project.

Returns:
LabelingService: The labeling service associated with the project.

Raises:
ResourceNotFoundError: If the project does not have a labeling service.
"""
query = """
query GetProjectBoostWorkforcePyApi($projectId: ID!) {
projectBoostWorkforce(data: { projectId: $projectId }) {
id
projectId
createdAt
updatedAt
createdById
status
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extreme nit: Indentation of this gql query seems off

"""
result = self.client.execute(query, {"projectId": self.uid})
if result["projectBoostWorkforce"] is None:
raise ResourceNotFoundError(
message="The project does not have a labeling service.")
return LabelingService(**result["projectBoostWorkforce"])


class ProjectMember(DbObject):
user = Relationship.ToOne("User", cache=True)
Expand Down
7 changes: 7 additions & 0 deletions libs/labelbox/tests/integration/test_labeling_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from labelbox.exceptions import ResourceNotFoundError
import pytest


def test_get_labeling_service_throws_exception(project):
with pytest.raises(ResourceNotFoundError): # No labeling service by default
project.get_labeling_service()
Loading