Skip to content

Commit c9d4719

Browse files
author
Val Brodsky
committed
Add Project get_labeling_service
1 parent 49b5957 commit c9d4719

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

docs/labelbox/labeling-service.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Project Labeling Service
2+
===============================================================================================
3+
4+
.. automodule:: labelbox.schema.labeling_service
5+
:members:
6+
:show-inheritance:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from datetime import datetime
2+
from enum import Enum
3+
4+
from labelbox.data.annotation_types.types import Cuid
5+
from labelbox.orm.db_object import experimental
6+
from labelbox.pydantic_compat import BaseModel
7+
from labelbox.utils import _CamelCaseMixin
8+
9+
10+
class LabelingServiceStatus(Enum):
11+
Accepted = 'ACCEPTED',
12+
Calibration = 'CALIBRATION',
13+
Complete = 'COMPLETE',
14+
Production = 'PRODUCTION',
15+
Requested = 'REQUESTED',
16+
SetUp = 'SET_UP'
17+
18+
19+
@experimental
20+
class LabelingService(_CamelCaseMixin, BaseModel):
21+
id: Cuid
22+
project_id: Cuid
23+
created_at: datetime
24+
updated_at: datetime
25+
created_by_id: Cuid
26+
status: LabelingServiceStatus
27+
28+
def status_as_string(self):
29+
return self.status.value

libs/labelbox/src/labelbox/schema/project.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, TypeVar, Union, overload
1010
from urllib.parse import urlparse
1111

12+
from .labeling_service import LabelingService
1213
import requests
1314

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

1908+
@experimental
1909+
def get_labeling_service(self) -> LabelingService:
1910+
"""
1911+
Returns the labeling service associated with the project.
1912+
1913+
Returns:
1914+
LabelingService: The labeling service associated with the project.
1915+
1916+
Raises:
1917+
ResourceNotFoundError: If the project does not have a labeling service.
1918+
"""
1919+
query = """
1920+
query GetProjectBoostWorkforcePyApi($projectId: ID!) {
1921+
projectBoostWorkforce(data: { projectId: $projectId }) {
1922+
id
1923+
projectId
1924+
createdAt
1925+
updatedAt
1926+
createdById
1927+
status
1928+
}
1929+
}
1930+
"""
1931+
result = self.client.execute(query, {"projectId": self.uid})
1932+
if result["projectBoostWorkforce"] is None:
1933+
raise ResourceNotFoundError(
1934+
message="The project does not have a labeling service.")
1935+
return LabelingService(**result["projectBoostWorkforce"])
1936+
19071937

19081938
class ProjectMember(DbObject):
19091939
user = Relationship.ToOne("User", cache=True)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from labelbox.exceptions import ResourceNotFoundError
2+
import pytest
3+
4+
5+
def test_get_labeling_service_throws_exception(project):
6+
with pytest.raises(ResourceNotFoundError): # No labeling service by default
7+
project.get_labeling_service()

0 commit comments

Comments
 (0)