Tableau Automation with Python: A Comprehensive Guide 101

• March 21st, 2022

Tableau Automation_FI

Visual Analytics is the union of Data Analytics and Visualisations. This problem-solving approach is concerned with effectively facilitating high-level, complex activities such as reasoning and data-driven decision-making by integrating interactive visual representations with underlying analytical processes. Tableau is a Visual Analytics Engine that simplifies the creation of interactive visual analytics in the form of dashboards. These dashboards facilitate the conversion of data into intelligible, interactive visualizations for non-technical analysts and end-users.

In this article, you will gain information about Tableau Automation with Python. You will also gain a holistic understanding of Tableau, Python, their key features, adding Python Scripts in Tableau using Python & TabPy & Tableau Automation using Python & Tabcmd. Read along to find out in-depth information about Tableau Automation with Python.

Table of Contents


The prerequisites for undergoing Tableau automation with Python are as follows:

  • Download & install the most recent version of Python.
  • Download & install the Tableau Python server (TabPy). Install TabPy by following the installation and configuration instructions.
  • Install Pandas library in Python.
  • To use the integrations effectively, the Tableau workbook(s) must be available on Tableau Server or Tableau Online.

What is Tableau?

Tableau Automation: Tableau logo
Image Source

Tableau is a modern Data Analytics and Business Intelligence platform. It is an easy-to-use tool, hence, it offers a smooth experience to its users. Some of Its amazing features include real-time analytics, quick responsiveness, and interactive dashboards. 

It also offers simple yet appealing graphics/visualizations that you can use to present your data pictorially. It comes with all the features needed for data extraction, data processing, and generating reports and dashboards. 

It also offers a drag-and-drop functionality that makes it faster than other BI tools. It is also a very scalable tool, which gives it the capability to adapt to both individual and enterprise needs. You can also connect it to multiple data sources without the need to purchase a license. It is mobile compatible and it comes with an online version. 

It can be used by all kinds of users and no specific skill or knowledge is needed to work with the tool. Users from any department in your company can use it for Data Analysis and Data Visualization. 

Key Features of Tableau

Tableau is a powerful tool and is widely used by a lot of industries. To understand Tableau better let’s look at some of its key features:

1) Supports Multiple Data Sources

Since every task is performed on data in Tableau, it allows you to integrate your data from a large variety of data sources like:

  • Microsoft Excel
  • CSV files
  • MS SQL Server
  • Oracle
  • IBM DB2
  • Google BigQuery
  • Windows Azure
  • ODBC/JDBC, etc

You can make use of these integrations to stream your data to Tableau and analyze it seamlessly.

2) Houses a Wide Range of Visualizations

Tableau also provides a large number of simple tools for its users (both for technical and non-technical people) and empowers them to create different types of visualizations using their data. You can use these tools and create simple or complex visualizations using Tableau. Its key visualizations include:

  • Scatter plot
  • Line plot
  • Pie Chart 
  • Bar Chart 
  • Bullet Chart
  • Highlight Tables
  • Gantt Chart
  • Boxplot, etc. 

Tableau’s Map features allow you to visualize your data on a geographical map. It is very useful if your data needs to be categorized region-wise or across various countries to help you analyze the performance of each region.

Tableau Automation -Tableau Visualisation
Image Source

3) Allows Data Filtering

With the help of Tableau, you can filter data from a single source or multiple sources. But the only condition that needs to be satisfied for filtering data from multiple Data Sources is that the data must have the same dimensions. Once this is satisfied, Tableau automatically updates the required changes to all your worksheets using the same Data Sources and the same filters that you set previously.

4) Dynamic and Real-time Dashboards

Tableau Automation -Tableau dashboards
Image Source

You can build dynamic and interactive Dashboards using Tableau. Building Reports and Dashboards is made very simple by Tableau. You can make them more informative by adding colorful charts and diagrams. Using these real-time Dashboards, you can monitor everything in absolute depth for your organization. Tableau also houses a feature that allows you to share your Dashboards and Reports with other employees in the organization.

5) Powerful Collaboration

Every person can work a lot more efficiently if they understand their data and make informed decisions which are critical to success in any organization. Tableau was initially built to enable collaboration among employees. Using Tableau, all the members in a team can share their work, make follow-up queries with fellow peers, and share visualizations with any employee in the organization, allowing them to gain valuable insights easily.

Tableau gives its users the ability to work and understand the data they need from web editing and authoring to Data Source recommendations. You can easily publish your Dashboard to Tableau Server or Tableau Online within seconds and as a result, everyone in your organization can see your insights, ask various questions, and make the right decisions.

What is Python?

Tableau Automation: Python Logo
Image Source

Python is a versatile general-purpose Programming Language. Its small learning curve coupled with its robustness has made it one of the most popular Programming Languages ​​today. It is the go-to choice of developers for Website and Software Development, Automation, Data Analysis, Data Visualization, and much more. Moreover, its straightforward syntax allows Accountants, Scientists to utilize it for daily tasks. The Python Programming Language serves as the key integral tool in the field of Data Science for performing complex Statistical Calculations, creating Machine Learning Algorithms, etc. 

Python Programming Language is also renowned for its ability to generate a variety of Data Visualizations like Bar Charts, Column Charts, Pie Charts,  and 3D Charts. Furthermore, it offers a rich set of libraries that facilitates advanced Machine Learning programs in a faster and simpler manner. 

Key Features of Python

Tableau Automation: Python Features
Image Source

The following features are responsible for Python Programming Language’s popularity today:

  • Beginner Friendly: The Python Programming Language offers a hassle-free environment for developers. Its straightforward workflow is suitable for everyone and entry-level coders are drawn to it. Moreover, you can use and distribute its open-source codes for commercial purposes free of cost.
  • Robust Applications: Its simple syntax operates on natural human-readable language making it the go-to choice of projects on Python Programming Language, which is faster as compared to other Programming Languages. Furthermore, its versatile nature makes it the ideal choice for Web Development and Machine Learning projects.
  • Large Communities: Due to Python’s immense popularity, a huge active community of programmers is available online that contributes to this language’s modules and libraries. Moreover, this vast support community is ready to help in case you or any other coder gets stuck in a programming issue. You can easily get suggestions and solutions by posting your issue on these community pages.

You can understand more about the Python Programming Language by visiting here.

Simplify Tableau ETL with Hevo’s No-code Data Pipeline

A fully managed No-code Data Pipeline platform like Hevo Data helps you integrate and load data from 100+ Data Sources (including 40+ Free Sources) such as Tableau to a Data Warehouse/Destination of your choice in real-time in an effortless manner. Hevo with its minimal learning curve can be set up in just a few minutes allowing the users to load data without having to compromise performance. In addition to the 100+ data sources, Hevo also allows integrating data from non-native sources using Hevo’s in-built Webhooks Connector.

Get Started with Hevo for Free

Its strong integration with umpteenth sources allows users to bring in data of different kinds in a smooth fashion without having to code a single line. 

Check out some of the cool features of Hevo:

  • Completely Automated: The Hevo platform can be set up in just a few minutes and requires minimal maintenance.
  • Connectors: Hevo supports 100+ Integrations to SaaS platforms, Files, Databases, BI tools such as Tableau, and Native REST API & Webhooks Connectors. It supports various destinations including Google BigQuery, Amazon Redshift, Snowflake Data Warehouses; Amazon S3 Data Lakes; Databricks (Connector Live Soon!); and MySQL, SQL Server, TokuDB, DynamoDB, PostgreSQL Databases to name a few.  
  • Real-Time Data Transfer: Hevo provides real-time data migration, so you can have analysis-ready data always.
  • 100% Complete & Accurate Data Transfer: Hevo’s robust infrastructure ensures reliable data transfer with zero data loss.
  • Scalable Infrastructure: Hevo has in-built integrations for 100+ sources (Including 40+ Free Sources) such as Tableau that can help you scale your data infrastructure as required.
  • 24/7 Live Support: The Hevo team is available round the clock to extend exceptional support to you through chat, email, and support calls.
  • Schema Management: Hevo takes away the tedious task of schema management & automatically detects the schema of incoming data and maps it to the destination schema.
  • Live Monitoring: Hevo allows you to monitor the data flow so you can check where your data is at a particular point in time.
Sign up here for a 14-Day Free Trial!

Adding Python Scripts in Tableau: Python & TabPy

To incorporate Python scripts into your flow, you must first establish a connection between Tableau and a TabPy server. Then, using a pandas data frame, you can use Python scripts to apply supported functions to data from your flow.

The steps to be carried out are as follows:

1) Configure the Tableau Python (TabPy) server for Tableau Server

To publish, create, edit, and run flows with script steps in Tableau Server, you’ll need to connect your TabPy server to Tableau Server.

  • Step 1: Navigate to the TSM command line/shell.
  • Step 2: To set the host address, port values, and connect timeout, you can use the following commands:
  • tsm security maestro-tabpy-ssl enable --connection-type {maestro-tabpy-secure/maestro-tabpy} --tabpy-host <TabPy IP address or host name> --tabpy-port <TabPy port> --tabpy-username <TabPy username> --tabpy-password <TabPy password> --tabpy-connect-timeout-ms <TabPy connect timeout>
    • Choose {maestro-tabpy-secure} for a secure connection or {maestro-tabpy} for an unsecured connection.
    • If you choose {maestro-tabpy-secure}, specify the certificate file in the command line with -cf<certificate file path>.
    • Set the –tabpy-connect-timeout-ms <TabPy connect timeout> in milliseconds. For example –tabpy-connect-timeout-ms 800000.
  • Step 3: Enter the command tsm security maestro-tabpy-ssl disable to disable the TabPy connection.

2) Create your Python script

When writing your script, include a function that takes pandas, pd.DataFrame as an argument. This will fetch data from Tableau Prep Builder. You must also return the results in pandas, pd.DataFrame with supported data types.

To add encoding to a set of fields in a flow, for example, you could write the following script:

def encode(input):     
  le = preprocessing.LabelEncoder()
  Return pd.DataFrame({
    'Opportunity Number' : input['Opportunity Number'],
    'Supplies Subgroup Encoded' : le.fit_transform(input['Supplies Subgroup']),
    'Region Encoded' : le.fit_transform(input['Region']),
    'Route To Market Encoded' : le.fit_transform(input['Route To Market']),
    'Opportunity Result Encoded' : le.fit_transform(input['Opportunity Result']),
    'Competitor Type Encoded' : le.fit_transform(input['Competitor Type']),
    'Supplies Group Encoded' : le.fit_transform(input['Supplies Group']),

Note: Date and DateTime must always be returned as a valid string.

If you want to return a different set of fields than what you entered, you must include a get_output_schema function in your script that defines the output and data types. Otherwise, the fields from the input data will be used in the output, which is taken from the step prior to the script step in the flow.

The get_output_schema function was added to the field encoding python script in the following example:

def get_output_schema():       
  return pd.DataFrame({
    'Opportunity Number' : prep_int(),
    'Supplies Subgroup Encoded' : prep_int(),
    'Region Encoded' : prep_int(),
    'Route To Market Encoded' : prep_int (),
    'Opportunity Result Encoded' : prep_int (),
    'Competitor Type Encoded' : prep_int()
    'Supplies Group Encoded' : prep_int()

3) Connect to your Tableau Python (TabPy) server

The steps to be carried out to connect Tableau with TabPy Server are as follows:

  • Click on the “Help” option. Then, select the “Settings and Performance” option. Now, select the “Manage Analytics Extension Connection” option.
  • Select “Tableau Python (TabPy) Server” from the “Select an Analytics Extension” drop-down list.
Tableau Automation: Analytics Extension
  • Enter the following credentials:
    • The default port for TabPy is 9004.
    • Enter a username and password if the server requires them.
    • Select the Require SSL check box, then click the Custom configuration file. Link to specify a certificate for the connection if the server uses SSL encryption.

4) Add a script to your flow

Start your TabPy server then complete the following steps:

  • Step 1: Open the Tableau Prep Builder. Now, click the “Add connection button.
  • Step 2: In web authoring, from the Home page, click the “Create” option. Then select the “Flow” option. Or, from the Explore page, click the “New” option. Then, select the “Flow” option. Then click on the “Connect to Data” option.
  • Step 3: Choose the file type or server that hosts your data from the list of connectors. Enter the information required to sign in and access your data if prompted.
  • Step 4: Select “Add Script” from the context menu after clicking the plus icon.
Tableau Automation: Script
Image Source
  • Step 5: Select “Tableau Python (TabPy) Server” in the Connection type section of the Script pane.
Tableau Automation:  TabPy Server
Image Source
  • Step 6: To select your script file, click the “Browse” option in the File Name section.
  • Step 7: To run your script, enter the “Function Name” and press the Enter key.

Automating Analytics in Tableau: Python & Tabcmd

For automating Analytics in Tableau, the steps to be carried out are as follows:

1) Authentication

> tabcmd login -s -t my_website -u -p 123

Each credential parameter is passed as a flag to the shell.

The output would be the same as given below:

===== redirecting to
===== Signed out
===== Creating new session
=====     Server:
=====     Username:
=====     Site:     my_website
===== Connecting to the server...
===== Signing in...
===== Succeeded

Note: In the event of a failed authentication in either route, you can consult with a Tableau Server administrator about your user privileges/user authorization.

2) Fetch & Download a Workbook

Note: The workbook ‘Superstore‘ is available as a sample in all Tableau distributions. It will be the default workbook in the following code snippet demonstrations.

You can find and download the workbook as a .twbx file using the following code in tabcmd.

tabcmd get “/workbooks/Superstore.twbx”

3) Apply a Filter to a View & Download as a File

Within the workbook, you can query a specific view and apply a filter to it.

In the process, you make a view request with filters as parameters. The API processes the request against the view and returns a snapshot to the requesting client.

Before Filter (with all regions):

Tableau Automation: Before Filter

After Filter for (Region = West):

Tableau Automation: After Filter

The export command accepts the URL of the specified view as well as optional download parameters.

tabcmd export -t my_site "Superstore/Overview?refresh=yes&Region=West" --pdf --pagesize a4 --pagelayout landscape -f "Overview.pdf"

The view can be exported as a PNG or CSV too.

The URL on the browser would be for the same command as given below:

4) Data Sources & Connections

The data source object, like the workbook or view objects, can be filtered or paginated.

tabcmd refreshextracts --datasource sales_ds


In this article, you have learned about Tableau Automation with Python. This article also provided information on Tableau, Python, their key features, adding Python Scripts in Tableau using Python & TabPy & Tableau Automation using Python & Tabcmd.

Hevo Data, a No-code Data Pipeline provides you with a consistent and reliable solution to manage data transfer between a variety of sources and a wide variety of Desired Destinations with a few clicks.

Visit our Website to Explore Hevo

Hevo Data with its strong integration with 100+ Data Sources (including 40+ Free Sources) such as Tableau allows you to not only export data from your desired data sources & load it to the destination of your choice but also transform & enrich your data to make it analysis-ready. Hevo also allows integrating data from non-native sources using Hevo’s in-built REST API & Webhooks Connector. You can then focus on your key business needs and perform insightful analysis using BI tools. 

Want to give Hevo a try? Sign Up for a 14-day free trial and experience the feature-rich Hevo suite first hand. You may also have a look at the amazing price, which will assist you in selecting the best plan for your requirements.

Share your experience of understanding Tableau Automation with Python in the comment section below! We would love to hear your thoughts.

No-code Data Pipeline for Tableau