Tableau Server Client (TSC)

0.40 · active · verified Sun Mar 29

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

Install

Imports

Quickstart

This quickstart demonstrates how to connect to Tableau Server or Tableau Cloud using a Personal Access Token (PAT) and retrieve a list of all workbooks on a specified site. It uses environment variables for sensitive credentials and includes basic error handling.

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}")

view raw JSON →