Skip to content

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.

activate_user #

activate_user(user_id: int) -> AdminUser

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: int

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: int

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_user(user_id: int) -> AdminUser | None

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 AdminUser.id.

TYPE: int

RETURNS DESCRIPTION
AdminUser | None

The AdminUser object, or None if no user with this id exists.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.

get_user_by_email #

get_user_by_email(email: str) -> AdminUser | None

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: str

RETURNS DESCRIPTION
AdminUser | None

The AdminUser object, or None if no user with this email exists.

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_users() -> list[AdminUser]

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: str

first_name

Given name of the new user.

TYPE: str

last_name

Surname of the new user.

TYPE: str

password

Initial password for the new account. If not provided, the backend generates a temporary one, returned on the password attribute of the resulting AdminUser.

TYPE: str | None DEFAULT: None

max_num_projects

Maximum number of projects the new user is allowed to own. Defaults to the backend-configured default when not set.

TYPE: int | None DEFAULT: None

role

Platform role to assign, one of HOPS_ADMIN, HOPS_USER, HOPS_SERVICE_USER.

TYPE: _ROLE_ARG DEFAULT: 'HOPS_USER'

status

Initial account status, one of NEW_MOBILE_ACCOUNT, VERIFIED_ACCOUNT, ACTIVATED_ACCOUNT, DEACTIVATED_ACCOUNT, BLOCKED_ACCOUNT, LOST_MOBILE, SPAM_ACCOUNT, TEMP_PASSWORD. Defaults to TEMP_PASSWORD, requiring the user to set a new password on first login.

TYPE: _REGISTER_STATUS_ARG | None DEFAULT: None

RETURNS DESCRIPTION
AdminUser

The newly registered AdminUser.

RAISES DESCRIPTION
ValueError

If role or status is not one of the supported values.

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_user(user_id: int) -> AdminUser

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: int

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_confirmation_email(user_id: int) -> AdminUser

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: int

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 #

set_role(user_id: int, role: _ROLE_ARG) -> AdminUser

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: int

role

New platform role, one of HOPS_ADMIN, HOPS_USER, HOPS_SERVICE_USER.

TYPE: _ROLE_ARG

RETURNS DESCRIPTION
AdminUser

The updated AdminUser.

RAISES DESCRIPTION
ValueError

If role is not one of the supported values.

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 #

update_user(
    user_id: int, max_num_projects: int
) -> AdminUser

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: int

max_num_projects

New maximum number of projects the user may own.

TYPE: int

RETURNS DESCRIPTION
AdminUser

The updated AdminUser.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If the backend encounters an error when handling the request.