Working with Users
Users are represented by the User class, which is a
high-level abstraction over the user data returned by the API. It contains
information about the user, such as their identifier, username, and whether
they are administrator or not.
You can retrieve users from the EternalTwin API in three different ways:
- By following the authorization flow (see OAuth2 Authorization for more details).
- Using their identifier.
- Searching for users by their username.
You can use
User.aget()instead for asynchronous requests.
If you have the user's ID (usually in the form of an UUID4), you can directly
retrieve it without following the authorization flow with this method. It will
return an instance of User.
from eternaltwin.users import User
user_id = "12345678-1234-1234-1234-123456789012"
user = User.get(user_id)
assert user.identifier == user_id
Searching by username
search(query: str | None = None, limit: int = 20, offset: int = 0, using: str | None = None) -> list[Self]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | None
|
An optional query to use against the user's username, default to |
None
|
limit
|
int
|
The maximum number of users to return, default to |
20
|
offset
|
int
|
The offset to start returning users from, default to |
0
|
You can use
User.asearch()instead for asynchronous requests.
If don't have the user's ID, but you know their username, you can search for them using this method instead.
Note that the return list might be empty, or containis multiple users with
a username containing "Bob".