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.

 

Downloading Anaconda For Windows

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.

 

Installing Anaconda

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
activate tpy

 

Anaconda Prompt
Anaconda Prompt

3. Installing TabPy

From the activated ‘tpy’ environment, execute following commands:

pip install tabpy
pip install pandas
tabpy

The first two lines will install TabPy and pandas (required for Prep) and the third line will start the tabpy server at port 9004.

Installing and Running Tabpy
Installing and Running Tabpy

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.

def sort_descending(df):
    """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.

Tableau Prep Python Integration
Tableau Prep Python Integration

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:

tabpy --config=path_to_the_downloaded_file

Describing all configuration settings are beyond the scope of this post, but you can find details at this link.

Running Tabpy with Configuration File
Running Tabpy with Configuration File

If you have any questions, please feel free to ask in the comments and I will try my best to answer.

One thought on “Tableau Prep Python Integration – Installing and Setting Up TabPy”
  1. So after installing TabPy and being able to connect Desktop to it, I applied SSL. I can successfully connect via Desktop , but I’m unable to connect to the same server via Prep. Have you ever come across this?

Leave a Reply

Your email address will not be published. Required fields are marked *