TabPy: Integrating Python with Tableau

TabPy (Tableau Python Server) is an extension with the Tableau Desktop program that allows you to integrate and execute python scripts directly within Tableau itself via calculated fields and table calculations.

This integration builds on Tableau’s existing functions, like SUM() and FLOAT(), while enabling more advanced analyses such as predictive modeling with scikit-learn and natural language processing using libraries like nltk or spaCy. In essence, TabPy allows you to access Python’s powerful libraries and capabilities right within Tableau, opening up a whole new level of analytics.

How can I get started with TabPy?

  1. Ensure you have Python installed on your machine. The download link along with instructions and support can be here - https://www.python.org/downloads/. You can test if Python is already installed by entering and running the following command within your command line or terminal (Windows PowerShell for example):
python --version

If python is installed it should return the version number like this:

  1. From within your command line or terminal (Windows PowerShell for example) , install TabPy using pip by entering and running the following command
pip install tabpy
  1. Now you can start getting connected in Tableau by first launching Tableau desktop.
  2. Next we can start to configure the TabPy connection in Tableau by first navigating to the the “Manage Analytics Extension Connection…” selection via Help → Settings and Performance → Manage Analytics Extension Connection…
  1. Select TabPy as the connection type
  1. Now fill out your relevant connection details
    1. Enter localhost as the Hostname, or the IP address where the TabPy server is running.
    2. For the port the default is 9004, unless you have set this up differently.
  1. Test the connection to ensure it works and then save it. It should now be ready to go when you open up your next workbook!

How to use TabPy withing a Tableau workbook

  1. Next we’ll be using an example to show how it works in Tableau using a linear regression as an example and the Sample Superstore dataset.
  2. Open up a calculated field
  1. Enter your script into the calculated field - for this example the script is
SCRIPT_REAL("
from sklearn.linear_model import LinearRegression
import numpy as np

model = LinearRegression().fit(np.array(_arg1).reshape(-1, 1), np.array(_arg2))

prediction = model.predict(np.array(_arg1).reshape(-1, 1))

return prediction.tolist()

", SUM([Profit]), SUM([Sales]))

This script fits the linear regression model using the Profit field (_arg1) as the independent variable and Sales field (_arg2) as the dependent variable. It predicts the Sales based on the trained model with model.predict and returns the results.



TabPy allows you to integrate Python with Tableau, giving you access to Python's libraries for more advanced analytics and calculations. With the steps outlined, you can set it up and start using it within your Tableau workbooks, enabling you to apply techniques like predictive modeling and complex analysis.

Now that you have the basics, you can begin experimenting with Python in Tableau and see how it can enhance your data work.

Author:
Trea McElhone
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2025 The Information Lab