User API

class supervisely_lib.api.user_api.UserApi(api)[source]

Bases: supervisely_lib.api.module_api.ModuleApiBase

API for working with Users. UserApi object is immutable.

Parameters

api (Api) – API connection to the server.

Usage example
# You can connect to API directly
address = 'https://app.supervise.ly/'
token = 'Your Supervisely API Token'
api = sly.Api(address, token)

# Or you can use API from environment
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

users = api.user.get_list() # api usage example
class Membership(id, name, role_id, role)

Bases: tuple

id

Alias for field number 0

name

Alias for field number 1

role

Alias for field number 3

role_id

Alias for field number 2

static info_sequence()[source]

NamedTuple UserInfo information about User.

Example
UserInfo(id=8,
         login='alex',
         role=None,
         role_id=None,
         name=None,
         email=None,
         logins=20,
         disabled=False,
         last_login='2021-03-24T15:06:26.804Z',
         created_at='2020-04-17T10:24:09.077Z',
         updated_at='2021-03-24T15:13:01.148Z')
static info_tuple_name()[source]

NamedTuple name - UserInfo.

get_info_by_id(id: int) → NamedTuple[source]

Get User information by ID.

Parameters

id (int) – User ID in Supervisely.

Returns

Information about User. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

user_info = api.user.get_info_by_id(8)
print(user_info)
# Output: [
#     8,
#     "alex",
#     null,
#     null,
#     null,
#     null,
#     20,
#     false,
#     "2021-03-24T15:06:26.804Z",
#     "2020-04-17T10:24:09.077Z",
#     "2021-03-24T15:13:01.148Z"
# ]
get_info_by_login(login: str) → NamedTuple[source]

Get User information by login.

Parameters

login (str) – User login in Supervisely.

Returns

Information about User. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

user_info = api.user.get_info_by_login('alex')
print(user_info)
# Output: [
#     8,
#     "alex",
#     null,
#     null,
#     null,
#     null,
#     20,
#     false,
#     "2021-03-24T15:06:26.804Z",
#     "2020-04-17T10:24:09.077Z",
#     "2021-03-24T15:13:01.148Z"
# ]
get_member_info_by_login(team_id: int, login: str) → NamedTuple[source]

Get information about team member by Team ID and User login.

Parameters
  • team_id (int) – Team ID in Supervisely.

  • login (str) – User login in Supervisely.

Returns

Information about User. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

member_info = api.user.get_member_info_by_login(64, 'alex')
print(member_info)
# Output: [
#     8,
#     "alex",
#     "manager",
#     3,
#     null,
#     null,
#     20,
#     false,
#     "2021-03-24T15:06:26.804Z",
#     "2020-04-17T10:24:09.077Z",
#     "2021-03-24T15:13:01.148Z"
# ]
get_member_info_by_id(team_id: int, user_id: int) → NamedTuple[source]

Get information about team member by Team ID and User ID.

Parameters
  • team_id (int) – Team ID in Supervisely.

  • user_id (int) – User ID in Supervisely.

Returns

Information about User. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

member_info = api.user.get_member_info_by_id(64, 8)
print(member_info)
# Output: [
#     8,
#     "alex",
#     "manager",
#     3,
#     null,
#     null,
#     20,
#     false,
#     "2021-03-24T15:06:26.804Z",
#     "2020-04-17T10:24:09.077Z",
#     "2021-03-24T15:13:01.148Z"
# ]
get_list(filters: Optional[List[dict]] = None) → List[NamedTuple][source]

Get list of information about Users.

Parameters

filters (List[dict], optional) – List of params to sort output Users.

Returns

List of information about Users. See info_sequence

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

# Get list of Users with id = 8
user_info = api.user.get_list(filters=[{'field': 'id', 'operator': '=', 'value': '8'}])
print(user_info)
# Output: [
#     8,
#     "alex",
#     "manager",
#     3,
#     null,
#     null,
#     20,
#     false,
#     "2021-03-24T15:06:26.804Z",
#     "2020-04-17T10:24:09.077Z",
#     "2021-03-24T15:13:01.148Z"
# ]
create(login: str, password: str, is_restricted: bool = False, name: str = '', email: str = '') → NamedTuple[source]

Creates new User with given login and password.

Parameters
  • login (str) – New User login.

  • password (str) – New User password.

  • is_restricted (bool, optional) – If True, new User will have no access to Explore section, won’t be able to create or switch Teams, and no personal Team will be created for this User during signup.

  • name (str, optional) – New User name.

  • email (str, optional) – New User email.

Returns

Information about new User. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

new_user_info = api.user.create('John', 'qwerty', is_restricted=True, name='John Wick', email='excomunicado@gmail.com')
print(new_user_info)
# Output: [
#     274,
#     "John",
#     null,
#     null,
#     "John Wick",
#     "excomunicado@gmail.com",
#     0,
#     false,
#     null,
#     "2021-03-24T16:20:03.110Z",
#     "2021-03-24T16:20:03.110Z"
# ]
disable(id: int) → None[source]

Disables User with the given ID.

Parameters

id (int) – User ID in Supervisely.

Returns

None

Return type

NoneType

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

user_id = 8
api.user.disable(user_id)
enable(id: int) → None[source]

Enables User with the given ID.

Parameters

id (int) – User ID in Supervisely.

Returns

None

Return type

NoneType

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

user_id = 8
api.user.enable(user_id)
get_teams(id: int) → List[NamedTuple][source]

Get list with information about User Teams.

Parameters

id (int) – User ID in Supervisely.

Returns

List of teams in which the User with the given ID is located

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

teams = api.user.get_teams(8)
print(teams)
# Output: [
#     [
#         9,
#         "alex",
#         1,
#         "admin"
#     ],
#     [
#         64,
#         "test",
#         3,
#         "manager"
#     ]
# ]
add_to_team(user_id: int, team_id: int, role_id: int) → None[source]

Invites User to Team with the given role.

Parameters
  • user_id (int) – User ID in Supervisely.

  • team_id (int) – Team ID in Supervisely.

  • role_id (int) – Role ID in Supervisely.

Returns

None

Return type

NoneType

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

user_id = 8
team_id = 76
role_id = 5
api.user.add_to_team(user_id, team_id, role_id)
remove_from_team(user_id: int, team_id: int) → None[source]

Removes User from Team.

Parameters
  • user_id (int) – User ID in Supervisely.

  • team_id (int) – Team ID in Supervisely.

Returns

None

Return type

NoneType

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

user_id = 8
team_id = 76
api.user.remove_from_team(user_id, team_id)
update(id: int, password: Optional[str] = None, name: Optional[str] = None) → NamedTuple[source]

Updates User info.

Parameters
  • id (int) – User ID in Supervisely.

  • password (str) – User password.

  • name (str) – User name.

Returns

New information about User. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

user_info = api.user.update(8, name='Aleksey')
print(user_info)
# Output: [
#     8,
#     "alex",
#     null,
#     null,
#     "Aleksey",
#     null,
#     21,
#     false,
#     "2021-03-25T08:06:03.498Z",
#     "2020-04-17T10:24:09.077Z",
#     "2021-03-25T08:37:17.257Z"
# ]
change_team_role(user_id: int, team_id: int, role_id: int) → None[source]

Changes User role in the given Team.

Parameters
  • user_id (int) – User ID in Supervisely.

  • team_id (int) – Team ID in Supervisely.

  • role_id (int) – Role ID in Supervisely.

Returns

None

Return type

NoneType

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

user_id = 8
team_id = 64
new_role_id = 2
api.user.change_team_role(user_id, team_id, new_role_id)
get_team_members(team_id: int) → List[NamedTuple][source]

Get list of information about Team Users.

Parameters

team_id (int) – Team ID in Supervisely.

Returns

List of information about Team Users

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

team_id = 9
team_members = api.user.get_team_members(team_id)
get_team_role(user_id: int, team_id: int) → NamedTuple[source]

Get Team role for given User and Team IDs.

Parameters
  • user_id (int) – User ID in Supervisely.

  • team_id (int) – Team ID in Supervisely.

Returns

Information about Team :class:`Role<supervisely_lib.api.role_api.RoleApi

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

user_id = 8
team_id = 9
team_role = api.user.get_team_role(user_id, team_id)
print(team_role)
# Output: [
#     9,
#     "alex",
#     1,
#     "admin"
# ]
get_member_activity(team_id: int, user_id: int) → pandas.core.frame.DataFrame[source]

Get User activity data.

Parameters
  • team_id (int) – Team ID in Supervisely.

  • user_id (int) – User ID in Supervisely.

Returns

Activity data as pd.DataFrame

Return type

pd.DataFrame

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

activity = api.user.get_member_activity(64, 8)
print(activity)
# Output:
#    userId               action                      date  ... jobId   tag tagId
# 0        8        login_to_team  2021-03-13T08:57:26.832Z  ...  None  None  None
# 1        8  annotation_duration  2021-03-02T13:16:23.833Z  ...  None  None  None
# 2        8        login_to_team  2021-03-02T13:15:58.775Z  ...  None  None  None
# 3        8        login_to_team  2021-02-06T09:47:22.999Z  ...  None  None  None
# ................................................................................
# 38       8     create_workspace  2021-01-04T12:25:37.916Z  ...  None  None  None
# 39       8        login_to_team  2021-01-04T12:24:58.257Z  ...  None  None  None
# 40       8        login_to_team  2021-01-04T12:23:43.056Z  ...  None  None  None
# 41       8        login_to_team  2021-01-04T11:53:56.447Z  ...  None  None  None
# [42 rows x 18 columns]
add_to_team_by_login(user_login: str, team_id: int, role_id: int) → dict[source]

Invite User to Team with given role by login.

Parameters
  • user_login (str) – User login in Supervisely.

  • team_id (int) – Team ID in Supervisely.

  • role_id (int) – Role ID in Supervisely.

Returns

Information about new User in Team

Return type

dict

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

team_id = 13
role_id = 2
new_user_data = api.user.add_to_team_by_login('alex', team_id, role_id)
print(new_user_data)
# Output: {
#     "userId": 8
# }
InfoType

alias of supervisely_lib.api.module_api.UserInfo