> ## Documentation Index
> Fetch the complete documentation index at: https://docs.labelbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# User

> Developer guide for managing team members using the Python SDK.

# Client

```python theme={null}
import labelbox as lb
client = lb.Client(api_key="<YOUR_API_KEY>")
```

# Get the current user

```python theme={null}
user = client.get_user()
```

# Methods

## Update an organization role

```python theme={null}
# 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

```python theme={null}
# 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

```python theme={null}
# get the project
project = client.get_project("<project_id>")

# remove from the project
user_to_remove.remove_from_project(project)
```

# Attributes

## Get the basics

```python theme={null}
# 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

```python theme={null}
# 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

```python theme={null}
# 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

<Note>
  `users` replaced by `members`

  Starting with version 7.0.0 of the SDK, the `users` attribute is now deprecated. Please use `members` instead in order to specify a user account and a role.
</Note>

Managing user groups requires you to import additional classes:

```python theme={null}
from labelbox.schema.user_group import UserGroup, UserGroupColor, UserGroupMember
```

## Create user groups

```python theme={null}
# 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

```python theme={null}
# 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()
```

## Search for and get info on user groups

<CodeGroup>
  ```python From name theme={null}
  group_name = "example_name"

  # 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 == group_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()
  ```

  ```python From id theme={null}
  # Search for a user group by its id
  group_id = "<group id>" # Example af4ff010-cb4c-11f0-a929-8300a55d380
  group = UserGroup(client, id=group_id).get()
  ```
</CodeGroup>
