UserApi

class UserApi(api)[source]

Bases: ModuleApiBase

API for working with users.

Parameters:
api

Api object to use for API connection.

Usage Example:
import supervisely as sly
api = sly.Api.from_env()
users = api.user.get_list()

Methods

add_to_team

Invites User to Team with the given role.

add_to_team_by_login

Invite User to Team with given role by login.

change_team_role

Changes User role in the given Team.

convert_info_to_json

Convert information about an entity to a dictionary.

create

Creates new User with given login and password.

disable

Disables User with the given ID.

enable

Enables User with the given ID.

get_info_by_id

Get User information by User ID.

get_info_by_login

Get User information by User login.

get_list

Get list of information about Users.

get_list_all_pages

Get list of all or limited quantity entities from the Supervisely server.

get_list_all_pages_generator

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_list_idx_page_async

Get the list of items for a given page number.

get_list_page_generator_async

Yields list of images in dataset asynchronously page by page.

get_member_activity

Get User activity data.

get_member_info_by_id

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

get_member_info_by_login

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

get_my_info

get_ssh_keys

get_team_members

Get list of information about Team Users.

get_team_role

Get Team role for given User and Team IDs.

get_teams

Get list with information about User Teams.

get_token

info_sequence

Sequence of fields that are returned by the API to represent UserInfo.

info_tuple_name

Name of the tuple that represents UserInfo.

remove_from_team

Removes User from Team.

update

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 UserInfo

class Membership(id, name, role_id, role)

Bases: tuple

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

classmethod convert_info_to_json(info)

Convert information about an entity to a dictionary.

Parameters:
info : NamedTuple

Information about the entity.

Returns:

Dictionary with information about the entity.

Return type:

dict

static info_sequence()[source]

Sequence of fields that are returned by the API to represent UserInfo.

Usage 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]

Name of the tuple that represents UserInfo.

add_to_team(user_id, team_id, role_id)[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:

None

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()

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:
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:
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()

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:
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:

None

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()

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.

Return type:

UserInfo

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()

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:

None

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()

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:

None

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()

user_id = 8
api.user.enable(user_id)
get_info_by_id(id)[source]

Get User information by User ID.

Parameters:
id : int

User ID in Supervisely.

Returns:

Information about User.

Return type:

UserInfo

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()

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 User login.

Parameters:
login : str

User login in Supervisely.

Returns:

Information about User.

Return type:

UserInfo

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()

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.

Return type:

List[UserInfo]

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()

# 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

Returns:

List of entities.

Return type:

List[dict]

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

async get_list_idx_page_async(method, data)

Get the list of items for a given page number. Page number is specified in the data dictionary.

Parameters:
method : str

Method to call for listing items.

data : dict

Data to pass to the API method.

Returns:

List of items.

Return type:

Tuple[int, List[NamedTuple]]

async get_list_page_generator_async(method, data, pages_count=None, semaphore=None)

Yields list of images in dataset asynchronously page by page.

Parameters:
method : str

Method to call for listing items.

data : dict

Data to pass to the API method.

pages_count : int, optional

Preferred number of pages to retrieve if used with a per_page limit. Will be automatically adjusted if the pagesCount differs from the requested number.

semaphore=None

Semaphore for limiting the number of simultaneous requests.

Returns:

List of images in dataset.

Return type:

AsyncGenerator[List[ImageInfo]]

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()

method = 'images.list'
data = {'datasetId': 123456}

loop = sly.utils.get_or_create_event_loop()
images = loop.run_until_complete(api.image.get_list_generator_async(method, data))
get_member_activity(team_id, user_id, progress_cb=None)[source]

Get User activity data.

Parameters:
team_id : int

Team ID in Supervisely.

user_id : int

User ID in Supervisely.

progress_cb : tqdm or callable, optional

Function to check progress.

Returns:

Activity data as pd.DataFrame

Return type:

pd.DataFrame

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()

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:
team_id : int

Team ID in Supervisely.

user_id : int

User ID in Supervisely.

Returns:

Information about User.

Return type:

UserInfo

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()

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 by login.

Parameters:
team_id : int

Team ID in Supervisely.

login : str

User login in Supervisely.

Returns:

Information about User.

Return type:

UserInfo

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()

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 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()

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:
user_id : int

User ID in Supervisely.

team_id : int

Team ID in Supervisely.

Returns:

Membership information for the specified team (team id, name, and role).

Return type:

UserInfo, optional

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()

user_id = 8
team_id = 9
team_role = api.user.get_team_role(user_id, team_id)
print(team_role)
# Output: TeamMembership(id=9, name="alex", role_id=1, role="admin")
get_teams(id)[source]

Get list with information about User Teams.

Parameters:
id : int

User ID in Supervisely.

Returns:

List of teams where the user is a member (team id, name, and role).

Return type:

List[UserInfo]

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()

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

Removes User from Team.

Parameters:
user_id : int

User ID in Supervisely.

team_id : int

Team ID in Supervisely.

Returns:

None

Return type:

None

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()

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:
id : int

User ID in Supervisely.

password : str

User password.

name : str

User name.

Returns:

New information about User.

Return type:

UserInfo

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()

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"
# ]