Skip to content

Commit bb6b170

Browse files
committed
Add team metadata retrieval
1 parent 360ef36 commit bb6b170

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

docs/source/superannotate.sdk.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ __________________
101101
Team contributors
102102
_________________
103103

104+
.. autofunction:: superannotate.get_team_metadata
104105
.. autofunction:: superannotate.invite_contributor_to_team
105106

106107
----------

superannotate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
upload_images_from_s3_bucket_to_project, upload_images_to_project,
5454
upload_preannotations_from_folder_to_project
5555
)
56-
from .db.teams import invite_contributor_to_team
56+
from .db.teams import get_team_metadata, invite_contributor_to_team
5757
from .db.users import search_team_contributors
5858
from .dicom_converter import dicom_to_rgb_sequence
5959
from .exceptions import (

superannotate/db/teams.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from ..api import API
4+
from ..common import user_role_int_to_str
45
from ..exceptions import SABaseException
56

67
logger = logging.getLogger("superannotate-python-sdk")
@@ -12,7 +13,7 @@ def invite_contributor_to_team(email, admin=False):
1213
"""Invites a contributor to team
1314
1415
:param email: email of the contributor
15-
:type project: str
16+
:type email: str
1617
:param admin: enables admin priviledges for the contributor
1718
:type admin: bool
1819
"""
@@ -29,6 +30,28 @@ def invite_contributor_to_team(email, admin=False):
2930
return response.json()
3031

3132

33+
def get_team_metadata(convert_users_role_to_string=False):
34+
"""Returns team metadata
35+
36+
:param convert_users_role_to_string: convert integer team users' roles to human comprehensible strings
37+
:type convert_users_role_to_string: bool
38+
:return: team metadata
39+
:rtype: dict
40+
"""
41+
response = _api.send_request(req_type='GET', path=f'/team/{_api.team_id}')
42+
if not response.ok:
43+
raise SABaseException(
44+
response.status_code, "Couldn't get team metadata. " + response.text
45+
)
46+
47+
res = response.json()
48+
if convert_users_role_to_string:
49+
for user in res["users"]:
50+
user["user_role"] = user_role_int_to_str(user["user_role"])
51+
52+
return res
53+
54+
3255
# def delete_team_contributor_invitation(invitation):
3356
# """Deletes team contributor invitation
3457

tests/test_team_metadata.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pathlib import Path
2+
3+
import superannotate as sa
4+
5+
sa.init(Path.home() / ".superannotate" / "config.json")
6+
7+
8+
def test_team_metadata():
9+
metadata = sa.get_team_metadata(convert_users_role_to_string=True)
10+
print(len(metadata["users"]))
11+
print(metadata["users"])

0 commit comments

Comments
 (0)