Introduction
In modern data workflows, automating Tableau Server tasks is essential for saving time and reducing manual effort. One of the most common automation needs is downloading Tableau dashboards (workbooks) programmatically.
In this article, you will learn how to:
- Connect to Tableau Server using Python
- Authenticate securely
- Find workbook IDs
- Download Tableau dashboards/workbooks programmatically
- Automate the entire process using
tableauserverclient
This guide uses the official Tableau Server Client (TSC) library, which is the recommended way to interact with Tableau Server via Python.
π§° Prerequisites
Before starting, ensure you have the following installed:
1. Install required libraries
pip install tableauserverclient pandas
2. Python environment
- Python 3.7+
- Access to Tableau Server or Tableau Cloud
- Valid username/password or token credentials
π Step 1: Connect to Tableau Server
The first step is authentication with Tableau Server using TableauAuth.
from datetime import datetime
import tableauserverclient as TSC
import pandas as pd# Authentication
tableau_auth = TSC.TableauAuth('your_username', 'your_password')# Server connection
server = TSC.Server('https://your-tableau-server.com')
π Step 2: Sign in to Tableau Server
Use the auth.sign_in() method to establish a session:
with server.auth.sign_in(tableau_auth):
print("Successfully connected to Tableau Server")
π₯ Step 3: Download Tableau Workbook (Dashboard)
If you already know the workbook ID, you can directly download it.
with server.auth.sign_in(tableau_auth): workbook = server.workbooks.get_by_id("YOUR_WORKBOOK_ID") file_path = server.workbooks.download(
workbook.id,
include_extract=False
) print("Downloaded file:", file_path)
β Output
Downloaded file: C:\Users\YourName\Downloads\WorkbookName.twbx
π Step 4: Find Workbook ID (If Unknown)
If you donβt know the workbook ID, you can retrieve all workbooks available on the server.
with server.auth.sign_in(tableau_auth): all_workbooks = list(TSC.Pager(server.workbooks)) for wb in all_workbooks:
print("Workbook Name:", wb.name)
print("Workbook ID:", wb.id)
print("-" * 40)
This helps you identify the correct workbook before downloading.
π Step 5: Save File to Custom Location
You can define a custom download path:
filepath = r"C:/Users/YourName/Downloads/tableau_workbook.twbx"
Then move or rename the downloaded file if needed:
import shutilshutil.move(file_path, filepath)
print("File saved at:", filepath)
β± Step 6: Log Execution Time (Optional)
Tracking execution time helps in automation pipelines:
print("Downloaded at:", datetime.today())
π Full Working Script (Complete Example)
from datetime import datetime
import tableauserverclient as TSCtableau_auth = TSC.TableauAuth('your_username', 'your_password')
server = TSC.Server('https://your-tableau-server.com')with server.auth.sign_in(tableau_auth): # Get workbook (replace ID)
workbook = server.workbooks.get_by_id("YOUR_WORKBOOK_ID") # Download workbook
file_path = server.workbooks.download(
workbook.id,
include_extract=False
) print("Downloaded file:", file_path)print("Process completed at:", datetime.today())
π₯ Key Features of This Approach
- Fully automated Tableau dashboard download
- No manual UI interaction required
- Works for scheduled ETL pipelines
- Supports integration with Airflow, cron jobs, or CI/CD systems
β οΈ Best Practices
- Use Personal Access Tokens (PAT) instead of username/password in production
- Avoid hardcoding credentials
- Handle exceptions for production scripts
- Use logging instead of print statements
- Validate workbook permissions before downloading
π Common Use Cases
- Automated reporting systems
- Data backup from Tableau Server
- DevOps analytics pipelines
- Scheduled dashboard exports
- Data warehouse integration workflows
π― Conclusion
Downloading Tableau dashboards programmatically using Python is simple and powerful with the tableauserverclient library. With just a few lines of code, you can automate workbook extraction and integrate Tableau into your data engineering pipelines.
If youβre working with Tableau at scale, this approach can save hours of manual work every week.
