Skip to content

Commit a2cdae4

Browse files
committed
Add resourceTag GET and projectResourceTag CREATE for project tagging
1 parent 0ab238d commit a2cdae4

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

labelbox/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@
2323
from labelbox.schema.model_run import ModelRun
2424
from labelbox.schema.benchmark import Benchmark
2525
from labelbox.schema.iam_integration import IAMIntegration
26+
from labelbox.schema.resource_tag import ResourceTag
27+
from labelbox.schema.project_resource_tag import ProjectResourceTag

labelbox/schema/organization.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from typing import TYPE_CHECKING, List, Optional
23

34
from labelbox.exceptions import LabelboxError
@@ -126,6 +127,24 @@ def remove_user(self, user: "User") -> None:
126127
updateUser(where: {id: $%s}, data: {deleted: true}) { id deleted }
127128
}""" % (user_id_param, user_id_param), {user_id_param: user.uid})
128129

130+
def get_resource_tags(self) -> List["ResourceTag"]:
131+
"""
132+
Returns all resource tags for an organization
133+
"""
134+
res = self.client.execute(
135+
"""query {
136+
organization {
137+
resourceTag {
138+
id,
139+
text,
140+
color
141+
}
142+
}
143+
}""")
144+
145+
# print(json.dumps(res['organization']['resourceTag'], indent=2, sort_keys=True))
146+
return res['organization']['resourceTag']
147+
129148
def get_iam_integrations(self) -> List["IAMIntegration"]:
130149
"""
131150
Returns all IAM Integrations for an organization

labelbox/schema/project.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,33 @@ def members(self) -> PaginatedCollection:
121121
{id_param: str(self.uid)},
122122
["project", "members"], ProjectMember)
123123

124+
def create_project_resource_tags(self, tagIdsParam) -> List["ProjectResourceTag"]:
125+
""" Creates a project resource tag
126+
127+
TODO
128+
"""
129+
project_id_param = "projectId"
130+
tag_ids_param = "resourceTagIds"
131+
132+
query_str = """mutation AttatchProjectResourceTags($%s: ID!, $%s: [String!]) {
133+
project(where:{id:$%s}){updateProjectResourceTags(input:{%s:$%s}){id}}
134+
}""" % (
135+
project_id_param,
136+
tag_ids_param,
137+
project_id_param,
138+
tag_ids_param,
139+
tag_ids_param
140+
)
141+
142+
print('tagIdsParam', tagIdsParam)
143+
res = self.client.execute(
144+
query_str, {
145+
project_id_param: self.uid,
146+
tag_ids_param: tagIdsParam
147+
})
148+
149+
return res["project"]["updateProjectResourceTags"]
150+
124151
def labels(self, datasets=None, order_by=None) -> PaginatedCollection:
125152
""" Custom relationship expansion method to support limited filtering.
126153
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from labelbox.orm.db_object import DbObject, Updateable
2+
from labelbox.orm.model import Field, Relationship
3+
4+
class ProjectResourceTag(DbObject, Updateable):
5+
""" Project resource tag to associate ProjectResourceTag to Project.
6+
7+
Attributes:
8+
resourceTagId (str)
9+
projectId (str)
10+
11+
resource_tag (Relationship): `ToOne` relationship to ResourceTag
12+
"""
13+
14+
resourceTagId = Field.ID("resourceTagId")
15+
projectId = Field.ID("projectId")

labelbox/schema/resource_tag.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from labelbox.orm.db_object import DbObject
2+
from labelbox.orm.model import Field, Relationship
3+
4+
class ResourceTag(DbObject):
5+
""" Resource tag to label and identify your labelbox resources easier.
6+
7+
Attributes:
8+
text (str)
9+
color (str)
10+
11+
project_resource_tag (Relationship): `ToMany` relationship to ProjectResourceTag
12+
"""
13+
14+
text = Field.String("text")
15+
color = Field.String("color")

0 commit comments

Comments
 (0)