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()
# get the tasks in progress
user_task_in_progress = user.created_tasks(where=Task.status_as_enum == TaskStatus.In_Progress)
# 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
users
replaced bymembers
Starting with version 7.0.0 of the SDK, the
users
attribute is now deprecated.
Please usemembers
instead to specify a user account and a role.
Managing user groups require you to import additional classes:
from labelbox.schema.user_group import UserGroup, UserGroupColor, UserGroupMember
Create user groups
# Retrieve roles
roles = client.get_roles()
# Define a user group with individual roles (members)
user_group = UserGroup(
client=client,
name="User Group with Explicit Roles",
color=UserGroupColor.GREEN,
members={
UserGroupMember(user=user1, role=roles["LABELER"]),
UserGroupMember(user=user2, role=roles["REVIEWER"]),
UserGroupMember(user=user3, role=roles["LABELER"])
},
projects={project1},
description="Basic test"
)
# 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
user_group.description = "New group"
# Add new projects to the group
user_group.projects.add(project1))
## or
user_group.projects.update({project1, project2})
# Add new users to the group
user_group.members.add(UserGroupMember(user, roles["TEAM_MANAGER"]))
## or
ugm = {
UserGroupMember(user1, roles["LABELER"]),
UserGroupMember(user2, roles["TEAM MANAGER"])
}
user_group.members.update(ugm)
# Push the changes to the group
user_group.update()
## Remove all members and projects from the group
user_group.members = set()
user_group.projects = set()
# 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.get_user_groups(client)
# 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()
user_groups = UserGroup.get_user_groups(client)
example_group = next(
(group for group in user_groups if group.id == "<user_group_id>"),
None
)
# Optional - to retrieve the latest data if the group was updated
# after running the previous command
if example_group:
example_group.get()
## or
example_group = UserGroup(client)
example_group.id = ""
example_group.get()