User

Developer guide for managing team members using the Python SDK.

Client

import labelbox as lb client = lb.Client(api_key="<YOUR_API_KEY>")

Get the current user

user = client.get_user()

Methods

Update an organization role

# get the available roles roles = client.get_roles() # update the role (in this case, the user is granted labeler permissions) user_to_update.update_org_role(roles["LABELER"])

Upsert a project-based role

# get the available roles roles = client.get_roles() # get the project project = client.get_project("<project_id>") # update the project-based role (in this case, the user is granted reviewer permissions) user_to_update.upsert_project_role( project=project, role=roles["REVIEWER"] )

Remove from a project

# get the project project = client.get_project("<project_id>") # remove from the project user_to_remove.remove_from_project(project)

Attributes

Get the basics

# name (str) user.name # nickname (str) user.nickname # email (str) user.email # created at (datetime) user.created_at # updated at (datetime) user.updated_at # role (relationship to OrgRole object) role = user.org_role() # organization (relationship to Organization object) organization = user.organization()

Get the projects

# get the projects (relationship to Project objects) projects = user.projects() # inspect one project next(projects) # inspect all projects for project in projects: print(project) # for ease of use, you can convert the paginated collection to a list list(projects)

Get the created tasks

# get the tasks (relationship to Task objects) tasks = user.created_tasks() # inspect one project next(tasks) # inspect all projects for task in tasks: print(task) # for ease of use, you can convert the paginated collection to a list list(tasks)

Manage user groups

Managing user groups require you to import additional classes:

from labelbox.schema.user_group import UserGroup, UserGroupColor

Create user groups

# Define a user group user_group = UserGroup( client=client, name="New User Group", color=UserGroupColor.BLUE users=set(user, user1, user2), projects=set(project) ) # Create the defined user group created_group = user_group.create()

Update a user group

# Define the user group properties to be updated user_group.name = "Updated User Group Name" user_group.color = UserGroupColor.GREEN # Add new projects to the group projects = [] projects.append(user_group.projects) projects.append([project_1, project_2]) user_group.projects = projects # Add new users to the group users = user_group.users users.append([new_user_1, new_user_2]) user_group.users = users # Push the changes to the group user_group.update()
## Remove all members and projects from the group user_group.users = [] user_group.projects = [] user_group.update() # Push the changes to the group user_group.update()
user_group.delete()

Search for and get info on user groups

You can search for user groups by name or directly retrieve information about a group if you have its ID.

# Get all user groups in your workspace user_groups = UserGroup(client).get_user_groups() # Search for a user group by its name example_group = next((group for group in user_groups if group.name == "example_name"), None) if example_group: print(f"Found user group 'example_name' with ID: {example_group.id}") else: print("No user group named 'example_name' found") # Get info of the user group found example_group.get()
example_group = UserGroup(client) example_group.id = "" example_group.get()