Users
albert.collections.users
AlbertHTTPError
Bases: AlbertException
Base class for all erors due to HTTP responses.
Source code in src/albert/exceptions.py
AlbertPaginator
AlbertPaginator(
*,
path: str,
mode: PaginationMode,
session: AlbertSession,
deserialize: Callable[
[Iterable[dict]], Iterable[ItemType]
],
params: dict[str, str] | None = None,
)
Bases: Iterator[ItemType]
Helper class for pagination through Albert endpoints.
Two pagination modes are possible:
- Offset-based via by the offset query parameter
- Key-based via by the startKey query parameter and 'lastKey' response field
A custom deserialize function is provided when additional logic is required to load
the raw items returned by the search listing, e.g., making additional Albert API calls.
Source code in src/albert/core/pagination.py
AlbertSession
AlbertSession(
*,
base_url: str,
token: str | None = None,
auth_manager: AlbertClientCredentials
| AlbertSSOClient
| None = None,
retries: int | None = None,
)
Bases: Session
A session that has a base URL, which is prefixed to all request URLs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The base URL to prefix to all relative request paths (e.g., "https://app.albertinvent.com"). |
required |
token
|
str | None
|
A static JWT token for authentication. Ignored if |
None
|
auth_manager
|
AlbertClientCredentials | AlbertSSOClient
|
An authentication manager used to dynamically fetch and refresh tokens.
If provided, it overrides |
None
|
retries
|
int
|
The number of automatic retries on failed requests (default is 3). |
None
|
Methods:
| Name | Description |
|---|---|
request |
|
Source code in src/albert/core/session.py
request
Source code in src/albert/core/session.py
BaseCollection
BaseCollection(*, session: AlbertSession)
BaseCollection is the base class for all collection classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The Albert API Session instance. |
required |
Source code in src/albert/collections/base.py
PaginationMode
Status
User
Bases: BaseResource
Represents a User on the Albert Platform
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the user. |
id |
str | None
|
The Albert ID of the user. Set when the user is retrieved from Albert. |
location |
Location | None
|
The location of the user. |
email |
EmailStr | None
|
The email of the user. |
roles |
list[Role]
|
The roles of the user. |
user_class |
UserClass
|
The ACL class level of the user. |
metadata |
dict[str, str | list[EntityLink] | EntityLink] | None
|
|
Methods:
| Name | Description |
|---|---|
to_note_mention |
Convert the user to a note mention string. |
location
class-attribute
instance-attribute
location: SerializeAsEntityLink[Location] | None = Field(
default=None, alias="Location"
)
metadata
class-attribute
instance-attribute
roles
class-attribute
instance-attribute
roles: list[SerializeAsEntityLink[Role]] = Field(
max_length=1, default_factory=list, alias="Roles"
)
user_class
class-attribute
instance-attribute
UserCollection
UserCollection(*, session: AlbertSession)
Bases: BaseCollection
UserCollection is a collection class for managing User entities in the Albert platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The Albert session instance. |
required |
Methods:
| Name | Description |
|---|---|
create |
Create a new User |
get_all |
Retrieve fully hydrated User entities with optional filters. |
get_by_id |
Retrieves a User by its ID. |
get_current_user |
Retrieves the current authenticated user. |
search |
Searches for Users matching the provided criteria. |
update |
Update a User entity. |
Source code in src/albert/collections/users.py
create
Create a new User
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
User
|
The user to create |
required |
Returns:
| Type | Description |
|---|---|
User
|
The created User |
Source code in src/albert/collections/users.py
get_all
get_all(
*,
limit: int = 100,
status: Status | None = None,
type: UserFilterType | None = None,
id: list[str] | None = None,
start_key: str | None = None,
) -> Iterator[User]
Retrieve fully hydrated User entities with optional filters.
This method uses get_by_id to hydrate the results for convenience.
Use :meth:search for better performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Max results per page. |
100
|
status
|
Status
|
Filter by user status. |
None
|
type
|
UserFilterType
|
Attribute name to filter by (e.g., 'role'). |
None
|
id
|
list[str]
|
Values of the attribute to filter on. |
None
|
start_key
|
Optional[str]
|
The starting point for the next set of results, by default None. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[User]
|
Fully hydrated User entities. |
Source code in src/albert/collections/users.py
get_by_id
get_current_user
get_current_user() -> User
Retrieves the current authenticated user.
Returns:
| Type | Description |
|---|---|
User
|
The current User object. |
Source code in src/albert/collections/users.py
search
search(
*, params: UserFilterParams | None = None
) -> Iterator[UserSearchItem]
Searches for Users matching the provided criteria.
⚠️ This method returns partial (unhydrated) search results for performance.
To retrieve fully detailed objects, use :meth:get_all instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
UserFilterParams
|
Structured search filters for user listing. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[User]
|
An iterator of partial User entities. |
Source code in src/albert/collections/users.py
update
Update a User entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
User
|
The updated User entity. |
required |
Returns:
| Type | Description |
|---|---|
User
|
The updated User entity as returned by the server. |
Source code in src/albert/collections/users.py
UserFilterParams
pydantic-model
Bases: BaseAlbertModel
Structured filters for searching users, with API-compatible query parameter names.
Show JSON schema:
{
"$defs": {
"OrderBy": {
"enum": [
"desc",
"asc"
],
"title": "OrderBy",
"type": "string"
},
"Status": {
"description": "The status of a resource",
"enum": [
"active",
"inactive"
],
"title": "Status",
"type": "string"
}
},
"description": "Structured filters for searching users, with API-compatible query parameter names.",
"properties": {
"limit": {
"default": 50,
"maximum": 1000,
"minimum": 1,
"title": "Limit",
"type": "integer"
},
"offset": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Offset"
},
"text": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Text"
},
"sortBy": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Sortby"
},
"order": {
"$ref": "#/$defs/OrderBy",
"default": "desc"
},
"roles": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Roles"
},
"teams": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Teams"
},
"locations": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Locations"
},
"status": {
"anyOf": [
{
"items": {
"$ref": "#/$defs/Status"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Status"
},
"userId": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Userid"
},
"subscription": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Subscription"
},
"searchFields": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Searchfields"
},
"facetText": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Facettext"
},
"facetField": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Facetfield"
},
"containsField": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Containsfield"
},
"containsText": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Containstext"
},
"mentions": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Mentions"
}
},
"title": "UserFilterParams",
"type": "object"
}
Fields:
-
limit(int) -
offset(int | None) -
text(str | None) -
sort_by(str | None) -
order_by(OrderBy) -
roles(list[str] | None) -
teams(list[str] | None) -
locations(list[str] | None) -
status(list[Status] | None) -
user_id(list[str] | None) -
subscription(list[str] | None) -
search_fields(list[str] | None) -
facet_text(str | None) -
facet_field(str | None) -
contains_field(list[str] | None) -
contains_text(list[str] | None) -
mentions(bool | None)
UserSearchItem
pydantic-model
Bases: BaseAlbertModel, HydrationMixin[User]
Partial user entity as returned by the search.
Show JSON schema:
{
"$defs": {
"UserClass": {
"description": "The ACL class level of the user",
"enum": [
"guest",
"standard",
"trusted",
"privileged",
"admin"
],
"title": "UserClass",
"type": "string"
},
"UserSearchRoleItem": {
"properties": {
"roleId": {
"title": "Roleid",
"type": "string"
},
"roleName": {
"title": "Rolename",
"type": "string"
}
},
"required": [
"roleId",
"roleName"
],
"title": "UserSearchRoleItem",
"type": "object"
}
},
"description": "Partial user entity as returned by the search.",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"albertId": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Albertid"
},
"email": {
"anyOf": [
{
"format": "email",
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Email"
},
"userClass": {
"$ref": "#/$defs/UserClass",
"default": "standard"
},
"lastLoginTime": {
"anyOf": [
{
"format": "date-time",
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Lastlogintime"
},
"location": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Location"
},
"locationId": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Locationid"
},
"role": {
"items": {
"$ref": "#/$defs/UserSearchRoleItem"
},
"maxItems": 1,
"title": "Role",
"type": "array"
},
"subscription": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Subscription"
}
},
"required": [
"name"
],
"title": "UserSearchItem",
"type": "object"
}
Fields:
-
_collection(BaseCollection | None) -
name(str) -
id(UserId | None) -
email(EmailStr | None) -
user_class(UserClass) -
last_login_time(datetime | None) -
location(str | None) -
location_id(str | None) -
roles(list[UserSearchRoleItem]) -
subscription(str | None)