I am going to use the Tableau Server Client and Python Pandas using Miniconda in WSL2 with Ubuntu. If you need more information about the installation I left a guide in this previous post
There are two ways to connect to the Tableau Server:
- With a local admin user created directly in Tableau Server
- Or using Personal Access Token (PAT)
As the documentation said, REST API and TabCmd cannot use SAML for Single Sign-On (SSO) for example using Office 365 Azure Active Directory. If It is your case, you must use PAT that is available from Tableau Server 2019.4
In both cases, you need to provide the full URL address and the Site plus the login identification.
If you have many sites, to connect to the default let the site empty like this:
site = ''
Connecting to Tableau Server with local user
With the next Python code, you will be available to connect to Tableau Server
Using Personal Access Token (PAT)
First, you need to create a PAT in the User Settings you will need the Token Secret and Token Name
With the following code, you will connect using PAT to Tableau Server
Getting the users list with REST API
Using PAT, I created two functions one for validating the email with a regular expression and others to get the list of Tableau Server users adding some cleansing for the text:
Comparing with your local list
Using Python Pandas and Jupyter Lab the next section will show you how to compare and export to an Excel file. The result should be Anir doesn’t exist and Elliot is Unlicensed.
My Tableau Server list Users look like this
And I am going to use a comma-separated values (CSV) file with the list of emails to find.
The next step is creating a Pandas DataFrame with the list of users from the Tableau Server with the previous functions.
And I check if any user has an invalid email in the username
Next, I loaded the CSV file into a second DataFrame
And I validate if any user from the CSV has an invalid email to be fixed.
Then I do left join with both DataFrames to keep all emails from the CSV file
I created outputs to split who have licenses, are Unlicensed or does not exist
And save the results into an Excel file using openpyxl
To install openpyxl use the following commands:
conda install openpyxl
conda update openpyxl