Users
albert.collections.users
AlbertHTTPError
Bases: AlbertException
Base class for all erors due to HTTP responses.
Source code in src/albert/exceptions.py
AlbertSession
AlbertSession(
*,
base_url: str,
token: str | None = None,
client_credentials: ClientCredentials | 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 requests. (e.g., "https://sandbox.albertinvent.com") |
required |
retries
|
int
|
The number of retries for failed requests. Defaults to 3. |
None
|
client_credentials
|
ClientCredentials | None
|
The client credentials for programmatic authentication. Optional if token is provided. |
None
|
token
|
str | None
|
The JWT token for authentication. Optional if client credentials are provided. |
None
|
Methods:
Name | Description |
---|---|
request |
|
Source code in src/albert/session.py
request
Source code in src/albert/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
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_by_id |
Retrieves a User by its ID. |
get_current_user |
Retrieves the current authenticated user. |
list |
Lists Users based on 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_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
list
list(
*,
limit: int = 50,
offset: int | None = None,
text: str | None = None,
status: Status | None = None,
search_fields: str | None = None,
) -> Iterator[User]
Lists Users based on criteria
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
Optional[str]
|
text to search against, by default None |
None
|
Returns:
Type | Description |
---|---|
Generator
|
Generator of matching Users or None |
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. |