hopsworks.core.users_api #
UsersApi #
API for administering platform users in Hopsworks.
This is an admin-only capability, distinct from per-project membership (see ProjectMembersApi): the calling account must hold the HOPS_ADMIN platform role.
Use hopsworks.get_users_api to get an instance of this class.
Returned by
activate_user #
Activate a pending platform user account.
If the account has no platform role assigned yet, it is granted HOPS_USER.
Example
import hopsworks
hopsworks.login()
users_api = hopsworks.get_users_api()
users_api.activate_user(42)
| PARAMETER | DESCRIPTION |
|---|---|
user_id | Id of the platform user to activate. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
AdminUser | The updated AdminUser. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
delete_user #
delete_user(user_id: int) -> None
Delete a platform user account.
Potentially dangerous operation
This permanently removes the user account. The backend rejects the request if the user still owns any projects; remove or transfer those projects first.
Example
import hopsworks
hopsworks.login()
users_api = hopsworks.get_users_api()
users_api.delete_user(42)
| PARAMETER | DESCRIPTION |
|---|---|
user_id | Id of the platform user to delete. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request, for example if the user still owns projects. |
get_user #
Get a single platform user by id.
Example
import hopsworks
hopsworks.login()
users_api = hopsworks.get_users_api()
user = users_api.get_user(42)
| PARAMETER | DESCRIPTION |
|---|---|
user_id | Id of the platform user, as returned on TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
AdminUser | None | The AdminUser object, or |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
get_user_by_email #
Get a single platform user by email address.
An email address is usually what you know about a user, whereas the id has to be looked up first. The backend has no lookup by email, so this scans the full user list; prefer get_user when the id is at hand.
Example
import hopsworks
hopsworks.login()
users_api = hopsworks.get_users_api()
user = users_api.get_user_by_email("alice@example.com")
| PARAMETER | DESCRIPTION |
|---|---|
email | Email address of the platform user, matched regardless of case. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
AdminUser | None | The AdminUser object, or |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request, for example if the caller is not a platform admin. |
get_users #
Get all registered platform users.
Example
import hopsworks
hopsworks.login()
users_api = hopsworks.get_users_api()
for user in users_api.get_users():
print(user.email, user.roles)
| RETURNS | DESCRIPTION |
|---|---|
list[AdminUser] | List of all platform users known to this Hopsworks instance. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request, for example if the caller is not a platform admin. |
register_user #
register_user(
email: str,
first_name: str,
last_name: str,
password: str | None = None,
max_num_projects: int | None = None,
role: _ROLE_ARG = "HOPS_USER",
status: _REGISTER_STATUS_ARG | None = None,
) -> AdminUser
Register a new platform user account.
Only email/password accounts are supported; SSO/remote account registration is not exposed through this method.
Example
import hopsworks
hopsworks.login()
users_api = hopsworks.get_users_api()
new_user = users_api.register_user(
email="alice@example.com",
first_name="Alice",
last_name="Smith",
role="HOPS_USER",
status="ACTIVATED_ACCOUNT",
)
if new_user.password:
# Hand this off securely (e.g. a secrets manager); never log or print it.
temporary_password = new_user.password
| PARAMETER | DESCRIPTION |
|---|---|
email | Email address of the new user, used as their login. TYPE: |
first_name | Given name of the new user. TYPE: |
last_name | Surname of the new user. TYPE: |
password | Initial password for the new account. If not provided, the backend generates a temporary one, returned on the TYPE: |
max_num_projects | Maximum number of projects the new user is allowed to own. Defaults to the backend-configured default when not set. TYPE: |
role | Platform role to assign, one of TYPE: |
status | Initial account status, one of TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
AdminUser | The newly registered AdminUser. |
| RAISES | DESCRIPTION |
|---|---|
ValueError | If |
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request, for example if the email is already registered. |
reject_user #
Reject a platform user's registration request.
Marks the account as spam; the user is no longer able to log in.
Example
import hopsworks
hopsworks.login()
users_api = hopsworks.get_users_api()
users_api.reject_user(42)
| PARAMETER | DESCRIPTION |
|---|---|
user_id | Id of the platform user to reject. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
AdminUser | The updated AdminUser. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
resend_confirmation_email #
Resend the account confirmation email to a platform user.
Only works while the account is still in its initial unconfirmed state; it does not change the status of an already-confirmed account.
Example
import hopsworks
hopsworks.login()
users_api = hopsworks.get_users_api()
users_api.resend_confirmation_email(42)
| PARAMETER | DESCRIPTION |
|---|---|
user_id | Id of the platform user. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
AdminUser | The updated AdminUser. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request, for example if the account is already confirmed. |
set_role #
Change a platform user's role.
Example
import hopsworks
hopsworks.login()
users_api = hopsworks.get_users_api()
users_api.set_role(42, "HOPS_ADMIN")
| PARAMETER | DESCRIPTION |
|---|---|
user_id | Id of the platform user. TYPE: |
role | New platform role, one of TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
AdminUser | The updated AdminUser. |
| RAISES | DESCRIPTION |
|---|---|
ValueError | If |
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request, for example if a platform admin tries to change their own role. |
update_user #
Change the maximum number of projects a platform user is allowed to own.
Example
import hopsworks
hopsworks.login()
users_api = hopsworks.get_users_api()
users_api.update_user(42, max_num_projects=10)
| PARAMETER | DESCRIPTION |
|---|---|
user_id | Id of the platform user to update. TYPE: |
max_num_projects | New maximum number of projects the user may own. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
AdminUser | The updated AdminUser. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |