Python API to get the list of login users from Administration/Security/Users

Dominic-S
Dominic-S Registered Posts: 17

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,

Tagged:

Best Answer

  • Miguel Angel
    Miguel Angel Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 118 Dataiker
    edited July 17 Answer ✓

    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

  • Dominic-S
    Dominic-S Registered Posts: 17

    Thanks, that is exactly what I am looking for.

  • marwa
    marwa Registered Posts: 3
    edited July 17

    it doesnt work for me , i have this error :

    AttributeError: type object 'datetime.datetime' has no attribute 'datetime'

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,138 Neuron
    edited July 17

    Add this:

    import datetime
  • marwa
    marwa Registered Posts: 3

    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)

Setup Info
    Tags
      Help me…