UserApi¶
- class UserApi[source]¶
Bases:
supervisely.api.module_api.ModuleApiBase
API for working with
Users
.UserApi
object is immutable.- Parameters
- api : Api
API connection to the server.
- Usage example
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() # Pass values into the API constructor (optional, not recommended) # api = sly.Api(server_address="https://app.supervise.ly", token="4r47N...xaTatb") users = api.user.get_list() # api usage example
Methods
Invites User to Team with the given role.
Invite User to Team with given role by login.
Changes User role in the given Team.
Creates new User with given login and password.
Disables User with the given ID.
Enables User with the given ID.
Get User information by ID.
Get User information by login.
Get list of information about Users.
Get list of all or limited quantity entities from the Supervisely server.
This generator function retrieves a list of all or a limited quantity of entities from the Supervisely server, yielding batches of entities as they are retrieved
Get User activity data.
Get information about team member by Team ID and User ID.
Get information about team member by Team ID and User login.
get_my_info
get_ssh_keys
Get list of information about Team Users.
Get Team role for given User and Team IDs.
Get list with information about User Teams.
get_token
NamedTuple UserInfo information about User.
NamedTuple name - UserInfo.
Removes User from Team.
Updates User info.
Attributes
MAX_WAIT_ATTEMPTS
Maximum number of attempts that will be made to wait for a certain condition to be met.
WAIT_ATTEMPT_TIMEOUT_SEC
Number of seconds for intervals between attempts.
- InfoType¶
alias of
supervisely.api.module_api.UserInfo
- class Membership¶
Bases:
tuple
Membership(id, name, role_id, role)
- __add__(value, /)¶
Return self+value.
- __mul__(value, /)¶
Return self*value.
- static __new__(_cls, id, name, role_id, role)¶
Create new instance of Membership(id, name, role_id, role)
- count(value, /)¶
Return number of occurrences of value.
-
index(value, start=
0
, stop=9223372036854775807
, /)¶ Return first index of value.
Raises ValueError if the value is not present.
- 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
- add_to_team(user_id, team_id, role_id)[source]¶
Invites User to Team with the given role.
- Parameters
- Returns
None
- Return type
NoneType
- Usage example
import supervisely as sly 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)
- add_to_team_by_login(user_login, team_id, role_id)[source]¶
Invite User to Team with given role by login.
- Parameters
- Returns
Information about new User in Team
- Return type
- Usage example
import supervisely as sly 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 # }
- change_team_role(user_id, team_id, role_id)[source]¶
Changes User role in the given Team.
- Parameters
- Returns
None
- Return type
NoneType
- Usage example
import supervisely as sly 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)
-
create(login, password, is_restricted=
False
, name=''
, email=''
)[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
UserInfo
- Usage example
import supervisely as sly 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)[source]¶
Disables User with the given ID.
- Parameters
- id : int
User ID in Supervisely.
- Returns
None
- Return type
NoneType
- Usage example
import supervisely as sly 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)[source]¶
Enables User with the given ID.
- Parameters
- id : int
User ID in Supervisely.
- Returns
None
- Return type
NoneType
- Usage example
import supervisely as sly 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_info_by_id(id)[source]¶
Get User information by ID.
- Parameters
- id : int
User ID in Supervisely.
- Returns
Information about User. See
info_sequence
- Return type
UserInfo
- Usage example
import supervisely as sly 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)[source]¶
Get User information by login.
- Parameters
- login : str
User login in Supervisely.
- Returns
Information about User. See
info_sequence
- Return type
UserInfo
- Usage example
import supervisely as sly 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_list(filters=
None
)[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[UserInfo]
- Usage example
import supervisely as sly 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" # ]
-
get_list_all_pages(method, data, progress_cb=
None
, convert_json_info_cb=None
, limit=None
, return_first_response=False
)¶ Get list of all or limited quantity entities from the Supervisely server.
- Parameters
- method : str
Request method name
- data : dict
Dictionary with request body info
- progress_cb : Progress, optional
Function for tracking download progress.
- convert_json_info_cb : Callable, optional
Function for convert json info
- limit : int, optional
Number of entity to retrieve
- return_first_response : bool, optional
Specify if return first response
-
get_list_all_pages_generator(method, data, progress_cb=
None
, convert_json_info_cb=None
, limit=None
, return_first_response=False
)¶ This generator function retrieves a list of all or a limited quantity of entities from the Supervisely server, yielding batches of entities as they are retrieved
- Parameters
- method : str
Request method name
- data : dict
Dictionary with request body info
- progress_cb : Progress, optional
Function for tracking download progress.
- convert_json_info_cb : Callable, optional
Function for convert json info
- limit : int, optional
Number of entity to retrieve
- return_first_response : bool, optional
Specify if return first response
-
get_member_activity(team_id, user_id, progress_cb=
None
)[source]¶ Get User activity data.
- Parameters
- Returns
Activity data as pd.DataFrame
- Return type
pd.DataFrame
- Usage example
import supervisely as sly 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]
- get_member_info_by_id(team_id, user_id)[source]¶
Get information about team member by Team ID and User ID.
- Parameters
- Returns
Information about User. See
info_sequence
- Return type
UserInfo
- Usage example
import supervisely as sly 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_member_info_by_login(team_id, login)[source]¶
Get information about team member by Team ID and User login.
- Parameters
- Returns
Information about User. See
info_sequence
- Return type
UserInfo
- Usage example
import supervisely as sly 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_team_members(team_id)[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[UserInfo]
- Usage example
import supervisely as sly 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, team_id)[source]¶
Get Team role for given User and Team IDs.
- Parameters
- Returns
Information about Team
Role<supervisely.api.role_api.RoleApi
- Return type
UserInfo
- Usage example
import supervisely as sly 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_teams(id)[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[UserInfo]
- Usage example
import supervisely as sly 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" # ] # ]
- 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')
- remove_from_team(user_id, team_id)[source]¶
Removes User from Team.
- Parameters
- Returns
None
- Return type
NoneType
- Usage example
import supervisely as sly 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, password=
None
, name=None
)[source]¶ Updates User info.
- Parameters
- Returns
New information about User. See
info_sequence
- Return type
UserInfo
- Usage example
import supervisely as sly 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" # ]