Tableau Server Client (TSC)
Tableau Server Client (TSC) is a Python library that enables programmatic interaction with the Tableau Server REST API. It allows users to manage and modify various Tableau Server and Tableau Cloud resources, such as publishing workbooks and data sources, creating users and groups, and querying projects and sites. The library is actively maintained, with the latest version being 0.40 and frequent releases including new features and bug fixes.
Warnings
- breaking The TSC library version must be compatible with the Tableau Server REST API version it is connecting to. Incompatible versions can lead to unexpected behavior or `ServerError` exceptions.
- breaking Minor version upgrades of `tableauserverclient` can sometimes introduce subtle breaking changes or stricter validation, particularly around authentication. Users reported `NotSignedInError` issues when upgrading from v0.28 to v0.29.
- gotcha It is generally not possible to change the authentication *method* (e.g., from username/password to SAML IDP or OAuth) for existing data source connections via `tableauserverclient` or the underlying Tableau REST API.
Install
-
pip install tableauserverclient
Imports
- TSC
import tableauserverclient as TSC
- Server
from tableauserverclient import Server
- TableauAuth
from tableauserverclient import TableauAuth
- PersonalAccessTokenAuth
from tableauserverclient import PersonalAccessTokenAuth
Quickstart
import tableauserverclient as TSC
import os
TABLEAU_SERVER_URL = os.environ.get('TABLEAU_SERVER_URL', 'https://your-tableau-server.com')
TABLEAU_SITE_ID = os.environ.get('TABLEAU_SITE_ID', '') # Use '' for Default site
TABLEAU_PAT_NAME = os.environ.get('TABLEAU_PAT_NAME', 'your_pat_name')
TABLEAU_PAT_SECRET = os.environ.get('TABLEAU_PAT_SECRET', 'your_pat_secret')
# 1. Authenticate using Personal Access Token (PAT)
tableau_auth = TSC.PersonalAccessTokenAuth(
token_name=TABLEAU_PAT_NAME,
personal_access_token=TABLEAU_PAT_SECRET,
site_id=TABLEAU_SITE_ID
)
# 2. Initialize the Server object and set API version handling
# It's recommended to use the server's version for compatibility.
server = TSC.Server(TABLEAU_SERVER_URL, use_server_version=True)
try:
# 3. Sign in to Tableau Server
with server.auth.sign_in(tableau_auth):
print(f"Successfully signed in to Tableau Server: {TABLEAU_SERVER_URL}, Site: {TABLEAU_SITE_ID if TABLEAU_SITE_ID else 'Default'}")
# 4. Example: Query all workbooks on the site
all_workbooks, pagination_item = server.workbooks.get()
print(f"\nFound {pagination_item.total_available} workbooks:")
for workbook in all_workbooks:
print(f" - {workbook.name} (ID: {workbook.id})")
except TSC.ServerError as e:
print(f"Tableau Server Error: {e.code}: {e.message}")
except Exception as e:
print(f"An unexpected error occurred: {e}")