1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Get all users of specified groups from Tableau Server using TableauServerClient

Discussão em 'Python' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    I would like to get a list of all users for 3 AD groups on our Tableau server site using the TSC package. Based on some resources out there, I have the below using Python.

    The first snippet of code returns all users on our site and exports the list to an Excel. The second snippet is my attempt to apply a filter that returns just the users in the 3 AD groups, but it returns 0 users.

    Our site uses AD groups to provision access. I need to validate whether the members of these 3 groups have access to the data source the dashboard uses. The plan is to get the list of users from Tableau server and merge the group list with the list of users with access to the data source to return an output that would flag instances where I get a left only in _merge.

    Any input would be much appreciated.

    Returns all users on site.

    import tableauserverclient as TSC
    import pandas as pd

    tableau_auth = TSC.PersonalAccessTokenAuth('Y14_Dashboard_Update','access-token-xyz',site_id = 'site-name')
    server = TSC.Server('https://tableau-site/',use_server_version=True)

    with server.auth.sign_in(tableau_auth):

    request_options = TSC.RequestOptions(pagesize=1000)

    all_users, pagination_item = server.users.get(request_options)



    print("\nThere are {} user on site: ".format(pagination_item.total_available))

    all_users_on_site = pd.DataFrame({'Users': [user.name for user in all_users]})

    all_users_on_site.to_excel(r"C:\\Users\TABLEAU_User_ME\Documents\Projects\Tableau_Users.xlsx", index = False)


    Modified to filter on 3 groups; returns 0 users.

    import tableauserverclient as TSC
    import pandas as pd

    tableau_auth = TSC.PersonalAccessTokenAuth('Y14_Dashboard_Update','access-token-xyz',site_id = 'site-name')
    server = TSC.Server('https://tableau-server-site/',use_server_version=True)

    with server.auth.sign_in(tableau_auth):

    request_options = TSC.RequestOptions(pagesize=1000)
    request_options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
    TSC.RequestOptions.Operator.In,
    ["AD-Group1","AD-Group2", "AD-Group3"],)
    )
    matching_groups, pagination_item = server.users.get(request_options)

    print("\nThere are {} user on site: ".format(pagination_item.total_available))
    all_users_on_site = pd.DataFrame({'Users': [user.name for user in matching_groups]})

    all_users_on_site.to_excel(r"C:\\Users\TABLEAU_User_ME\Documents\Projects\Tableau_Users.xlsx", index = False)

    Continue reading...

Compartilhe esta Página