user
User endpoint handlers.
UserEndpoint
¶
Bases: BaseEndpoint
Handles user-related API endpoints.
Provides access to user information, history, and usage statistics.
change_password(request)
async
¶
Change the authenticated user's password.
The change ends every session issued before it. The client carries on with the new session the answer returns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChangePasswordRequest
|
Current password (for verification) and the new password |
required |
Returns:
| Type | Description |
|---|---|
PasswordChanged
|
The confirmation, and the new session |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If not authenticated |
ValidationError
|
If the current password is wrong or the new one does not meet complexity requirements |
create_api_key(request)
async
¶
Create an API key; the response carries the secret exactly once.
The account must have been enabled for keys by an administrator, and the request carries the account password again, and a current code from an account with a second factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ApiKeyCreate
|
Name, scopes, optional description and lifetime, password, and the code if the account has a second factor |
required |
Returns:
| Type | Description |
|---|---|
ApiKeyCreated
|
The key with its secret — store it now, it is not shown again |
Raises:
| Type | Description |
|---|---|
ForbiddenError
|
If the account may not create keys, or the client is itself authenticated with a key |
ValidationError
|
If a scope is refused or the lifetime exceeds the server's maximum |
Example
from yousleep_common.models import ApiKeyCreate
from yousleep_common.types import Permission
created = await client.user.create_api_key(
ApiKeyCreate(
name="Nightly pipeline",
scopes=[Permission.RECORDING_CREATE, Permission.ANALYSIS_CREATE],
expires_in_days=90,
password="…",
)
)
secret_manager.store("YOUSLEEP_API_KEY", created.secret)
delete(password, *, code=None)
async
¶
Delete the current user account.
This is a permanent action that deletes all user data, so it is confirmed with the account password, and a current code from an account with a second factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
The account password |
required |
code
|
str | None
|
The authenticator app's current code, from an account with a second factor |
None
|
Returns:
| Type | Description |
|---|---|
MessageResponse
|
Message confirming deletion |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If not authenticated |
ValidationError
|
If the password or the code is wrong |
export_audit(filters=None)
async
¶
Return your own audit trail as CSV text, oldest first.
get_current()
async
¶
Get information about the currently authenticated user.
Returns:
| Type | Description |
|---|---|
UserOut
|
User information |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If not authenticated |
get_organization()
async
¶
Get the caller's organization and their role in it.
Every project, credit balance and storage figure belongs to it.
Returns:
| Type | Description |
|---|---|
UserOrganizationOut
|
The organization overview. |
history(*, since_num_days=None, analysis_config_id=None, project_name=None, study_name=None, status=None, analysis_type=None, order=None, offset=None, limit=None)
async
¶
Get one page of the user's analysis history.
The history covers every analysis in every project the user can
open, deleted ones included, ordered by the time each was queued.
The server returns the newest first and a bounded page by default;
total on the response counts every match, so page with
offset until it is reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
since_num_days
|
int | None
|
Only analyses from the last |
None
|
analysis_config_id
|
str | None
|
Only analyses of this configuration |
None
|
project_name
|
str | None
|
Only analyses in the project with this name |
None
|
study_name
|
str | None
|
Only analyses in studies with this name |
None
|
status
|
AnalysisStatus | None
|
Only analyses in this status |
None
|
analysis_type
|
AnalysisType | None
|
Only analyses of this type |
None
|
order
|
Literal['asc', 'desc'] | None
|
|
None
|
offset
|
int | None
|
Analyses to skip |
None
|
limit
|
int | None
|
Maximum analyses to return; the server's default when omitted |
None
|
Returns:
| Type | Description |
|---|---|
HistoryResponse
|
Analysis history with list of analyses and total count |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If not authenticated |
list_api_keys()
async
¶
List the account's API keys — everything except the secret.
Expired keys stay listed until deleted, so the owner can see what needs rotating.
Returns:
| Type | Description |
|---|---|
list[ApiKeyOut]
|
The keys, newest first |
list_audit(filters=None, *, offset=0, limit=50)
async
¶
Return your own audit trail, newest first.
Events about your account and membership, and what you did in
projects. filters narrows by event types, a time window or an item.
Returns:
| Type | Description |
|---|---|
AuditEventListResponse
|
One page of events ( |
revoke_api_key(key_id)
async
¶
Revoke an API key; it stops authenticating on its next request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_id
|
UUID | str
|
The key's id, from the listing |
required |
Returns:
| Type | Description |
|---|---|
MessageResponse
|
A confirmation message |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If the account holds no such key |
update_profile(request)
async
¶
Update the authenticated user's own profile (name/position).
Omitted fields are left unchanged. Email/password changes go through
their dedicated flows; usage_type changes are admin-mediated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
UserProfileUpdate
|
The profile fields to change |
required |
Returns:
| Type | Description |
|---|---|
UserOut
|
The updated user |
usage_detailed()
async
¶
Get the caller's own usage.
What the caller's account holds now (active) and has created in
all, deleted items included (all_time). The organization's usage,
which its ceilings are measured against, is
client.organizations.get_usage.
Returns:
| Type | Description |
|---|---|
ResourceUsage
|
Resource usage with project, study, recording, and storage counts |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If not authenticated |