Python is a widely used general purpose programming language which provides a wide variety of statistical and machine learning techniques. Having the advantage of TabPy allows us to use Python together with Tableau and tremendously increase our available data analysis functionalities.

What is TabPy?

TabPy is an external service implementation which expands Tableau’s capabilities by allowing users to execute Python scripts and saved functions via Tableau’s table calculations. Allowing TabPy to interact with tableau enables us to use dimensions and measures of our connected data directly in a python script and execute it on the fly. We then have the ability to use the script results and display them immediately using Tableau.

Under the Hood: External Services Workflow

Tableau is connecting and passing data to an External Analytic Engine through script functions. These functions allow us to write python scripts, call out models, and bring back the data just like any other Table Calculations. The new flow of data insights can be be now fully integrated and rendered within Tableau.

The ability to connect with external engines is not limited to python and we can easily connect to other external services such as R and MATLAB.

Installing TabPy

For the installation of TabPy on a Mac we would need to download the latest Python version. Setting Python on a Mac can be a bit tricky, and we have to be cautious not to mess with the pre-installed Python 2.7 on the OS. You can find out more about how to set up python on your mac in the link.

For this installation, I will use PyCharm for handling most things. I have installed Python as explained in Setting Python on a Mac and will use PyCharm virtual environment.

Let’s open a new project for the TabPy installation:

Next, we’ll go to PyCharm tab Python Packages, search TabPy Package and install it. It will take a minute or two and that’s it! Yes, it is as easy as that… and PyCharm will handle the rest.

After installing TabPy, we’ll check the Terminal tab on PyCharm where we will simply type tabpy and press Enter.

We can quickly check the port where TabPy server usually runs in. Opening the browser by going to the following address: http://localhost:9004. It will show the TabPy instance we just created.

Configure Tableau

Once we have the TabPy instance up and running we can easily configure Tableau to use this service for evaluating Python code. Under Tableau’s Help > Setting and Performance > Manage External Service Connection we’ll open a dialogue box like so:

In our case Hostname would be localhost and the Port is 9004, since we have a local TabPy Server on our machine. After filling in the hostname and port, testing the connection should be successful.

Happy Days! We are ready to use Python in Tableau.

If you experience any kind of trouble, don’t hesitate to check out the official documentation here:

Check our site The Information Lab NL for more blog posts, upcoming trainings and consultancy services regarding Tableau, Alteryx and Snowflake.