Supervisely
About SuperviselyEcosystemContact usSlack
  • 💻Supervisely Developer Portal
  • 🎉Getting Started
    • Installation
    • Basics of authentication
    • Intro to Python SDK
    • Environment variables
    • Supervisely annotation format
      • Project Structure
      • Project Meta: Classes, Tags, Settings
      • Objects
      • Tags
      • Image Annotation
      • Video Annotation
      • Point Clouds Annotation
      • Point Cloud Episode Annotation
      • Volumes Annotation
    • Python SDK tutorials
      • Images
        • Images
        • Image and object tags
        • Spatial labels on images
        • Keypoints (skeletons)
        • Multispectral images
        • Multiview images
        • Advanced: Optimized Import
        • Advanced: Export
      • Videos
        • Videos
        • Video and object tags
        • Spatial labels on videos
      • Point Clouds
        • Point Clouds (LiDAR)
        • Point Cloud Episodes and object tags
        • 3D point cloud object segmentation based on sensor fusion and 2D mask guidance
        • 3D segmentation masks projection on 2D photo context image
      • Volumes
        • Volumes (DICOM)
        • Spatial labels on volumes
      • Common
        • Iterate over a project
        • Iterate over a local project
        • Progress Bar tqdm
        • Cloning projects for development
    • Command Line Interface (CLI)
      • Enterprise CLI Tool
        • Instance administration
        • Workflow automation
      • Supervisely SDK CLI
    • Connect your computer
      • Linux
      • Windows WSL
      • Troubleshooting
  • 🔥App development
    • Basics
      • Create app from any py-script
      • Configuration file
        • config.json
        • Example 1. Headless
        • Example 2. App with GUI
        • v1 - Legacy
          • Example 1. v1 Modal Window
          • Example 2. v1 app with GUI
      • Add private app
      • Add public app
      • App Compatibility
    • Apps with GUI
      • Hello World!
      • App in the Image Labeling Tool
      • App in the Video Labeling Tool
      • In-browser app in the Labeling Tool
    • Custom import app
      • Overview
      • From template - simple
      • From scratch - simple
      • From scratch GUI - advanced
      • Finding directories with specific markers
    • Custom export app
      • Overview
      • From template - simple
      • From scratch - advanced
    • Neural Network integration
      • Overview
      • Serving App
        • Introduction
        • Instance segmentation
        • Object detection
        • Semantic segmentation
        • Pose estimation
        • Point tracking
        • Object tracking
        • Mask tracking
        • Image matting
        • How to customize model inference
        • Example: Custom model inference with probability maps
      • Serving App with GUI
        • Introduction
        • How to use default GUI template
        • Default GUI template customization
        • How to create custom user interface
      • Inference API
      • Training App
        • Overview
        • Tensorboard template
        • Object detection
      • High level scheme
      • Custom inference pipeline
      • Train and predict automation model pipeline
    • Advanced
      • Advanced debugging
      • How to make your own widget
      • Tutorial - App Engine v1
        • Chapter 1 Headless
          • Part 1 — Hello world! [From your Python script to Supervisely APP]
          • Part 2 — Errors handling [Catching all bugs]
          • Part 3 — Site Packages [Customize your app]
          • Part 4 — SDK Preview [Lemons counter app]
          • Part 5 — Integrate custom tracker into Videos Annotator tool [OpenCV Tracker]
        • Chapter 2 Modal Window
          • Part 1 — Modal window [What is it?]
          • Part 2 — States and Widgets [Customize modal window]
        • Chapter 3 UI
          • Part 1 — While True Script [It's all what you need]
          • Part 2 — UI Rendering [Simplest UI Application]
          • Part 3 — APP Handlers [Handle Events and Errors]
          • Part 4 — State and Data [Mutable Fields]
          • Part 5 — Styling your app [Customizing the UI]
        • Chapter 4 Additionals
          • Part 1 — Remote Developing with PyCharm [Docker SSH Server]
      • Custom Configuration
        • Fixing SSL Certificate Errors in Supervisely
        • Fixing 400 HTTP errors when using HTTP instead of HTTPS
      • Autostart
      • Coordinate System
      • MLOps Workflow integration
    • Widgets
      • Input
        • Input
        • InputNumber
        • InputTag
        • BindedInputNumber
        • DatePicker
        • DateTimePicker
        • ColorPicker
        • TimePicker
        • ClassesMapping
        • ClassesColorMapping
      • Controls
        • Button
        • Checkbox
        • RadioGroup
        • Switch
        • Slider
        • TrainValSplits
        • FileStorageUpload
        • Timeline
        • Pagination
      • Text Elements
        • Text
        • TextArea
        • Editor
        • Copy to Clipboard
        • Markdown
        • Tooltip
        • ElementTag
        • ElementTagsList
      • Media
        • Image
        • LabeledImage
        • GridGallery
        • Video
        • VideoPlayer
        • ImagePairSequence
        • Icons
        • ObjectClassView
        • ObjectClassesList
        • ImageSlider
        • Carousel
        • TagMetaView
        • TagMetasList
        • ImageAnnotationPreview
        • ClassesMappingPreview
        • ClassesListPreview
        • TagsListPreview
        • MembersListPreview
      • Selection
        • Select
        • SelectTeam
        • SelectWorkspace
        • SelectProject
        • SelectDataset
        • SelectItem
        • SelectTagMeta
        • SelectAppSession
        • SelectString
        • Transfer
        • DestinationProject
        • TeamFilesSelector
        • FileViewer
        • Dropdown
        • Cascader
        • ClassesListSelector
        • TagsListSelector
        • MembersListSelector
        • TreeSelect
        • SelectCudaDevice
      • Thumbnails
        • ProjectThumbnail
        • DatasetThumbnail
        • VideoThumbnail
        • FolderThumbnail
        • FileThumbnail
      • Status Elements
        • Progress
        • NotificationBox
        • DoneLabel
        • DialogMessage
        • TaskLogs
        • Badge
        • ModelInfo
        • Rate
        • CircleProgress
      • Layouts and Containers
        • Card
        • Container
        • Empty
        • Field
        • Flexbox
        • Grid
        • Menu
        • OneOf
        • Sidebar
        • Stepper
        • RadioTabs
        • Tabs
        • TabsDynamic
        • ReloadableArea
        • Collapse
        • Dialog
        • IFrame
      • Tables
        • Table
        • ClassicTable
        • RadioTable
        • ClassesTable
        • RandomSplitsTable
        • FastTable
      • Charts and Plots
        • LineChart
        • GridChart
        • HeatmapChart
        • ApexChart
        • ConfusionMatrix
        • LinePlot
        • GridPlot
        • ScatterChart
        • TreemapChart
        • PieChart
      • Compare Data
        • MatchDatasets
        • MatchTagMetas
        • MatchObjClasses
        • ClassBalance
        • CompareAnnotations
      • Widgets demos on github
  • 😎Advanced user guide
    • Objects binding
    • Automate with Python SDK & API
      • Start and stop app
      • User management
      • Labeling Jobs
  • 🖥️UI widgets
    • Element UI library
    • Supervisely UI widgets
    • Apexcharts - modern & interactive charts
    • Plotly graphing library
  • 📚API References
    • REST API Reference
    • Python SDK Reference
Powered by GitBook
On this page
  • Introduction
  • How to debug this tutorial
  • User automation
  • Import libraries
  • Init API client
  • Get your IDs and username from environment
  • List available roles on Supervisely instance
  • Get UserInfo by ID
  • List all team users with corresponding roles
  • Methods that require admin permisssion
  • List all registered users
  • Get UserInfo by login
  • List all user teams with corresponding roles
  • Create new user
  • Update user info
  • Disable/Enable user
  • Invite user to team
  • Change user role in team
  • Remove user from team

Was this helpful?

Edit on GitHub
  1. Advanced user guide
  2. Automate with Python SDK & API

User management

Guide explains how to manipulate user and team members using Supervisely SDK and API

PreviousStart and stop appNextLabeling Jobs

Last updated 2 years ago

Was this helpful?

Introduction

In this tutorial you will learn how to work with User and manage team members using Supervisely SDK and API.

📗 Everything you need to reproduce : source code and demo data.

How to debug this tutorial

Step 1. Prepare ~/supervisely.env file with credentials.

Step 2. Clone with source code and demo data and create .

git clone https://github.com/supervisely-ecosystem/automation-with-python-sdk-and-api
cd automation-with-python-sdk-and-api
./create_venv.sh

Step 3. Open repository directory in Visual Studio Code.

code -r .

Step 4. change ✅ IDs ✅ in local.env file by copying the IDs from Supervisely instance.

  • Copy your TEAM ID from context menu of the team.

    CONTEXT_TEAMID=8                 # ⬅️ change it
  • You can find your user ID and login at Start -> Team members page

    CONTEXT_USERID=7                 # ⬅️ change it
    CONTEXT_USERLOGIN="my_username"  # ⬅️ change it

Step 5. Start debugging examples/user-automation/main.py

User automation

Import libraries

import os
from dotenv import load_dotenv
import supervisely as sly

Init API client

​Init API for communicating with Supervisely Instance. First, we load environment variables with credentials:

load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()

Get your IDs and username from environment

TEAM_ID = int(os.environ["CONTEXT_TEAMID"])
USER_ID = int(os.environ["CONTEXT_USERID"])
USER_LOGIN = os.environ["CONTEXT_USERLOGIN"]

List available roles on Supervisely instance

Print all roles that are available on Supervisely instance.

roles = api.role.get_list()
print(roles)

Output:

[
  RoleInfo(id=1, role='admin', created_at='2019-04-11T10:52:06.517Z', updated_at='2019-04-11T10:52:06.517Z'),
  RoleInfo(id=2, role='developer', created_at='2019-04-11T10:52:06.517Z', updated_at='2019-04-11T10:52:06.517Z'),
  RoleInfo(id=3, role='annotator', created_at='2019-04-11T10:52:06.517Z', updated_at='2019-04-11T10:52:06.517Z'),
  RoleInfo(id=4, role='viewer', created_at='2019-04-11T10:52:06.517Z', updated_at='2019-04-11T10:52:06.517Z')
]

Get UserInfo about yourself

my_info = api.user.get_my_info()
print("my login:", my_info.login)
print("my ID:", my_info.id)

Output:

my login: my_username
my ID: 100

Get UserInfo by ID

Get general information about user by ID.

Note: requires admin permission if requested ID is not equal to user id

user_info = api.user.get_info_by_id(USER_ID)
print(user_info)

Output:

UserInfo(
  id=100, 
  login='my_username', 
  name='user', 
  email=None, 
  logins=7, 
  disabled=False, 
  last_login='2019-08-02T09:18:09.155Z', 
  created_at='2019-04-11T10:59:50.472Z', 
  updated_at='2019-08-04T17:06:39.414Z'
)

List all team users with corresponding roles

team = api.team.get_info_id(TEAM_ID)
members = api.user.get_team_members(team.id)
print(f"All members in team: '{team.name}'")
print(members)

Output:

All members in team 'my_team'
[
  UserInfo(
    id=4, 
    login='max', 
    name='max_k', 
    email=None, 
    logins=7, 
    disabled=False,
    last_login='2019-08-02T09:18:09.155Z',
    created_at='2019-04-11T10:59:50.472Z',
    updated_at='2019-08-05T08:42:20.463Z'
  ),

  ...

  UserInfo(
    id=31, 
    login='labeler_03',
    name='',
    email=None, 
    logins=0, 
    disabled=False,
    last_login=None,
    created_at='2019-07-20T15:12:52.779Z',
    updated_at='2019-07-20T15:12:52.779Z'
  )
]

Methods that require admin permisssion

List all registered users

Print all registered users on Supervisely instance.

users = api.user.get_list()
print('Total number of users: ', len(users))
for user in users:
    print("Id: {:<5} Login: {:<25s} logins_count: {:<5}".format(user.id, user.login, user.logins))

Output:

Total number of users:  100
Id: 1     Login: admin                     logins_count: 88   
Id: 2     Login: supervisely               logins_count: 55    
...  
Id: 99    Login: alex                      logins_count: 0    
Id: 100   Login: my_username               logins_count: 3

Get UserInfo by login

Get general information about user by name.

user_info = api.user.get_info_by_login(USER_LOGIN)
print(user_info)

Output:

UserInfo(
  id=100, 
  login='my_username', 
  name='user', 
  email=None, 
  logins=7, 
  disabled=False, 
  last_login='2019-08-02T09:18:09.155Z', 
  created_at='2019-04-11T10:59:50.472Z', 
  updated_at='2019-08-04T17:06:39.414Z'
)

List all user teams with corresponding roles

Print user teams, with user's role in them.

def print_user_teams(login):
    user = api.user.get_info_by_login(login)
    user_teams = api.user.get_teams(user.id)
    print("\nTeams of user {!r}:".format(login))
    for team in user_teams:
        print("[team_id={}] {:<25s} [role_id={}] {}".format(team.id, team.name, team.role_id, team.role))

print_user_teams(USER_LOGIN)

Output:

Teams of user 'my_username':
[team_id=7] team_x                    [role_id=1] admin
[team_id=5] my_team                   [role_id=1] admin
[team_id=3] jupyter_tutorials         [role_id=1] admin

Create new user

new_user = api.user.get_info_by_login('demo_user_451')
if new_user is None:
    new_user = api.user.create(login='demo_user_451', password='123abc', is_restricted=False)
print(new_user)

Output:

UserInfo(
  id=101, 
  login='demo_user_451',
  name='',
  email=None,
  logins=0,
  disabled=False,
  last_login=None,
  created_at='2019-07-19T09:44:45.750Z',
  updated_at='2019-08-03T16:17:15.228Z'
)

Update user info

Change user's name and password.

new_password = 'abc123'
new_name = 'Bob'
user_info = api.user.update(user_info.id, password=new_password, name=new_name)
print(user_info)

Output:

UserInfo(
  id=101, 
  login='demo_user_451',
  name='Bob',
  email=None,
  logins=0,
  disabled=False,
  last_login=None,
  created_at='2019-07-19T09:44:45.750Z',
  updated_at='2019-08-03T16:17:15.228Z'
)

Disable/Enable user

api.user.disable(new_user.id)
api.user.enable(new_user.id)

Invite user to team

user = api.user.get_info_by_login('demo_user_451')
team = api.team.get_info_by_id(TEAM_ID)
if api.user.get_team_role(user.id, team.id) is None:
    api.user.add_to_team(user.id, team.id, api.role.DefaultRole.ANNOTATOR)

Output:

Teams of user 'demo_user451':
[team_id=22] demo_user451              [role_id=1] admin
[team_id=4] my_team                    [role_id=3] annotator

Change user role in team

user = api.user.get_info_by_login('demo_user_451')
team = api.team.get_info_by_id(TEAM_ID)
api.user.change_team_role(user.id, team.id, api.role.DefaultRole.VIEWER)
print_user_teams('demo_user_451')

Output:

Teams of user 'demo_user451':
[team_id=22] demo_user451              [role_id=4] viewer
[team_id=4] max                        [role_id=1] admin

Remove user from team

team = api.team.get_info_by_id(TEAM_ID)
user = api.user.get_info_by_login('demo_user_451')
api.user.remove_from_team(user.id, team.id)
print_user_teams('demo_user_451')

Output:

Teams of user 'demo_user451':
[team_id=22] demo_user451              [role_id=4] viewer
😎
this tutorial is on GitHub
repository
Virtual Environment
Learn more here.