Python API to get the list of login users from Administration/Security/Users
![Dominic-S](https://us.v-cdn.net/6038231/uploads/Dataiku/nAvatar13.png)
Hi,
Is there a way to use Dataiku's Python API to get the list of login users info (Login, Type, Groups, etc) posted in Administration/Security/Users?
Thanks,
Best Answer
-
Miguel Angel Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 118 Dataiker
Hi,
You can indeed use the Python API to access user related information.
There is a specific section for users and groups that you can check here: https://developer.dataiku.com/latest/api-reference/python/users-groups.html#users-and-groups
For example:
import dataiku client=dataiku.api_client() users=client.list_users() for i in users: print("----------") myuser=client.get_user(i['login']) print("Login name: ",i['login']) print("Display name: ",i['displayName']) print("Type: ",i['sourceType']) try: print("Email: ",i['email']) except: print("Email: N/A") print("Groups :",i['groups']) print("Last successful login: ", myuser.get_activity().last_successful_login)
Feel free to modify this example snippet to suit your business requirements. Please note that depending on your DSS version the exact commands syntax may vary.
Answers
-
Thanks, that is exactly what I am looking for.
-
it doesnt work for me , i have this error :
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,876 Neuron
Add this:
import datetime
-
hi , i already added import datetime
here my code
import dataiku
import datetime
client=dataiku.api_client()
users=client.list_users()
for i in users:
print("----------")
myuser=client.get_user(i['login'])
print("Login name: ",i['login'])
print("Display name: ",i['displayName'])
print("Type: ",i['sourceType'])
try: print("Email: ",i['email'])
except: print("Email: N/A")
print("Groups :",i['groups'])
print("Last successful login: ", myuser.get_activity().last_successful_login)