Tableau Prep Python Integration – Installing and Setting Up TabPy
Tableau Prep Python integration was added in 2019.3 and this post shows how to install and setup TabPy for Tableau Prep. Tableau recommends to run TabPy in a virtual environment and we will use Anaconda to manage our virtual environment.
1. Downloading and Installing Anaconda
You can download Anaconda for free from this link. Please remember to choose the correct distribution and architecture. Below image shows Windows 64 bit Python 3.7 download link and minimum version required by Tabpy is Python 3.6.
Once the installer is downloaded, double click on it to start the installation. Default options are fine and the installation process will take about 10 minutes.
2. Creating Virtual Environment
From start menu, Search for Anaconda Prompt and open it. Execute following commands in order to create a virtual environment called ‘tpy’ and then to activate it.
conda create -n tpy python=3.7
3. Installing TabPy
From the activated ‘tpy’ environment, execute following commands:
pip install tabpy
pip install pandas
The first two lines will install TabPy and pandas (required for Prep) and the third line will start the tabpy server at port 9004.
4. Tableau Prep Python Integration
In Order to use Python code in the flow, we need to use ‘Add Script’ step. We will use a simple function to sort the output data in descending order of sales. Save the below lines of code in a file with .py extension.
"""Sorts the dataframe in descending order of sales."""
return df.sort_values(by=['Sales'], ascending=False)
Below screen grab shows the entire process. You can download the packaged flow file here.
5. TabPy Additional Configurations
TabPy is highly configurable and the configurations can be controlled using a configuration file. Common configuration settings include Changing port number, enabling HTTPS, Enabling Authentication, Change Logging Levels, etc.
Download this sample configuration file (use right click and save link as) and you can start TabPy server using the configuration using below command:
Describing all configuration settings are beyond the scope of this post, but you can find details at this link.
If you have any questions, please feel free to ask in the comments and I will try my best to answer.