Users
albert.collections.users.UserCollection
Bases: BaseCollection
Manage Users in the Albert platform.
A User is an Albert user account: a person who can log in and act in the
platform. Each user has a name and email, a set of
Role objects that govern what they can do,
an optional home Location, and an ACL
class level (UserClass) that sets a broad
permission tier.
Users are grouped into teams (see
TeamCollection), and are referenced
throughout the platform: Tasks can be assigned to a user, and entities carry
ACLs that reference users and their roles. A user is identified by its User
ID (format USR..., e.g. "USR12").
This collection is accessed as client.users.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base API route for user requests. |
Methods:
| Name | Description |
|---|---|
get_current_user |
Get the user account for the currently authenticated session. |
get_by_id |
Get a single fully populated user by its ID. |
search |
Fast, lightweight search returning partial users (best for lookups). |
get_all |
Same idea as search, but returns fully populated users (slower). |
create |
Create a new user account. |
update |
Update an existing user. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Source code in src/albert/collections/users.py
get_current_user
get_current_user() -> User
Get the user account for the currently authenticated session.
Use this to find out who the active credentials belong to, for example to set yourself as the assignee of a Task or to check your own roles.
Returns:
| Type | Description |
|---|---|
User
|
The fully populated user for the authenticated session. |
Source code in src/albert/collections/users.py
get_by_id
Get a single, fully populated user by its ID.
To find users without knowing their IDs, use search or
get_all.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
UserId
|
The User ID (format |
required |
Returns:
| Type | Description |
|---|---|
User
|
The fully populated user. |
Source code in src/albert/collections/users.py
search
search(
*,
text: str | None = None,
sort_by: str | None = None,
order_by: OrderBy = DESCENDING,
roles: list[str] | None = None,
teams: list[str] | None = None,
locations: list[str] | None = None,
status: list[Status] | None = None,
user_id: list[UserId] | None = None,
subscription: list[str] | None = None,
search_fields: list[str] | None = None,
facet_text: str | None = None,
facet_field: str | None = None,
contains_field: list[str] | None = None,
contains_text: list[str] | None = None,
mentions: bool | None = None,
additional_field: list[str] | None = None,
custom_fields: dict[str, Any] | None = None,
metadata_filters: dict[str, Any] | None = None,
source_field: list[str] | None = None,
witnesser: list[str] | None = None,
offset: int = 0,
max_items: int | None = None,
) -> Iterator[UserSearchItem]
Search for users matching the given filters.
This returns lightweight, partial results (UserSearchItem) and
is the fastest way to look users up by name, role, team, or location.
For fully populated User entities, use get_all, or call
hydrate() on a search item.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Free-text search across multiple user fields (e.g. name, email). |
None
|
sort_by
|
str
|
Field to sort results by. |
None
|
order_by
|
OrderBy
|
Sort direction, ascending or descending. Defaults to descending. |
DESCENDING
|
roles
|
list[str]
|
Restrict to users holding any of these role names. |
None
|
teams
|
list[str]
|
Restrict to members of any of these teams. |
None
|
locations
|
list[str]
|
Restrict to users at any of these location IDs. |
None
|
status
|
list[Status]
|
Restrict to users with any of these statuses (e.g. active, inactive). |
None
|
user_id
|
list[UserId]
|
Restrict to these specific User IDs. |
None
|
subscription
|
list[str]
|
Restrict to users with any of these subscription types. |
None
|
search_fields
|
list[str]
|
The fields that |
None
|
facet_text
|
str
|
Text to match within a facet, used together with |
None
|
facet_field
|
str
|
The facet field that |
None
|
contains_field
|
list[str]
|
Field names to apply "contains" filtering on, paired positionally
with |
None
|
contains_text
|
list[str]
|
Substrings to match within the corresponding |
None
|
mentions
|
bool
|
When True, restrict to users who are mentioned. |
None
|
additional_field
|
list[str]
|
Request additional columns from the search index. |
None
|
custom_fields
|
dict[str, Any]
|
Filter by custom field values. |
None
|
metadata_filters
|
dict[str, Any]
|
Filter by custom field (metadata) values. |
None
|
source_field
|
list[str]
|
Restrict which fields are returned in the response. |
None
|
witnesser
|
list[str]
|
Filter by witnesser status. |
None
|
max_items
|
int
|
Maximum total number of users to return. If None, returns all matches. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[UserSearchItem]
|
An iterator of partial users matching the filters. |
Source code in src/albert/collections/users.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
get_all
get_all(
*,
status: Status | None = None,
type: UserFilterType | None = None,
id: list[UserId] | None = None,
start_key: str | None = None,
max_items: int | None = None,
) -> Iterator[User]
Get fully populated users, with optional filters.
Each result is fetched individually via get_by_id, so this is
convenient but slower than search. Prefer search when
you only need lightweight, partial results.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
Status
|
Restrict to users with this status (e.g. active, inactive). |
None
|
type
|
UserFilterType
|
The attribute that |
None
|
id
|
list[UserId]
|
The values to filter on for the chosen |
None
|
start_key
|
str
|
Pagination cursor marking where the next page of results begins. |
None
|
max_items
|
int
|
Maximum total number of users to return. If None, returns all matches. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[User]
|
An iterator of fully populated users. Preserves |
Source code in src/albert/collections/users.py
create
Create a new user account.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
User
|
The user to create. |
required |
Returns:
| Type | Description |
|---|---|
User
|
The newly created user, populated with its assigned User ID. |
Source code in src/albert/collections/users.py
update
Update an existing user.
Fetch the user (e.g. via get_by_id), modify the updatable
fields, then pass it here. Only the fields listed in Notes are applied;
changes to other fields are ignored.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
User
|
The user with desired changes applied. Must carry a valid |
required |
Returns:
| Type | Description |
|---|---|
User
|
The updated user. |
Notes
The following fields can be updated: email, metadata, name,
status.