Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: retrieve user by ID #5044

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
11 changes: 9 additions & 2 deletions argilla/src/argilla/client/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(
" advance in Argilla, unless you are creating a new one."
)
if id is not None:
error_msg += f" As the `id` argument is not None, you should use `User.from_id('{id}')` instead."
error_msg += f" As the `id` argument is not None, you should use `User.from_id(UUID('{id}'))` instead."
if name is not None:
error_msg += f" As the `name` argument is not None, you should use `User.from_name('{name}')` instead."
raise Exception(error_msg)
Expand Down Expand Up @@ -285,9 +285,16 @@ def from_id(cls, id: UUID) -> "User":

Examples:
>>> from argilla import rg
>>> user = rg.User.from_id("my-user")
>>> from uuid import UUID
>>> user = rg.User.from_id(UUID("my-user"))
"""
client = cls.__active_client()

try:
if not isinstance(id, UUID):
id = UUID(id)
except BaseClientError as e:
raise RuntimeError(f"Error while converting id=`{id}` to UUID. Is it a valid UUID?") from e
try:
users = users_api.list_users(client).parsed
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ You can get a user by id using the `from_id` classmethod in the `User` class.

```python
import argilla as rg

from uuid import UUID
rg.init(api_url="<ARGILLA_API_URL>", api_key="<ARGILLA_API_KEY>")

user = rg.User.from_id("00000000-0000-0000-0000-000000000000")
user = rg.User.from_id(UUID("00000000-0000-0000-0000-000000000000"))
```

### Assign a `User` to a `Workspace`
Expand Down
Loading