Code Sample: Find out which users are logged onto the Dataiku instance

As a Dataiku administrator, you might need to restart Dataiku and want to know which users are logged onto the instance.

You can use the list_users() method in the Dataiku Python API. The list_users method returns a value for activeWebSocketSesssions which indicates the number of Dataiku sessions a user is logged on. Anything other than 0 indicates that a user is connected to the Dataiku instance.

Here is a code snippet you can use:

import dataiku
client = dataiku.api_client()
dss_users = client.list_users()

user_list = []
# Grab list of users where they have active web socket sessions
for user in dss_users:
    if user['activeWebSocketSesssions'] != 0:
        user_list.append(user['displayName'])
print(user_list)