Tableau Document API

raw JSON →
0.11 verified Fri May 01 auth: no python

A Python module for working with Tableau workbook (TWB) and datasource (TDS) files, including packaged formats (TWBX, TDSX). It allows programmatic editing of connections, fields, dashboards, sheets, and custom SQL. Current version 0.11, with occasional releases.

pip install tableaudocumentapi
error ModuleNotFoundError: No module named 'tableaudocumentapi'
cause Package not installed or installed in wrong environment.
fix
Run 'pip install tableaudocumentapi' in the correct Python environment.
error AttributeError: 'Workbook' object has no attribute 'save_as'
cause Using older version (<0.5) without save_as method, or imported wrong module.
fix
Upgrade to latest version (pip install -U tableaudocumentapi) and ensure you import Workbook from tableaudocumentapi.
error xml.etree.ElementTree.ParseError: not well-formed (invalid token)
cause Attempting to open a corrupt or non-Tableau XML file, or the file is not a valid TWB/TDS.
fix
Verify file is a valid Tableau workbook/datasource. Try opening in Tableau Desktop to confirm integrity.
error PermissionError: [Errno 13] Permission denied: '/tmp/tmpxxx/...'
cause Insufficient permissions to write to the temporary directory (common on restrictive systems).
fix
Set TMPDIR environment variable to a writable directory, or run with appropriate privileges.
breaking Saving a workbook modifies namespaces; if you open and save a file without changes, the XML namespace may change, causing Tableau to treat it as a different version. Always test saved files.
fix Upgrade to 0.7+ which fixed namespace preservation, or verify saved file opens correctly in Tableau.
gotcha Packaged (twbx/tdsx) files are zipped; the library extracts them to a temporary directory. Ensure sufficient disk space and that the temporary directory is writable.
fix Monitor temp space; use tempfile.gettempdir() to check location.
gotcha The library does not support editing of dashboard layout or worksheet calculations. Attempting to modify dashboard objects may silently fail.
fix Only use documented properties (see class attributes).

Open a Tableau packaged workbook, inspect and modify database connections, then save as a new file.

from tableaudocumentapi import Workbook

wb = Workbook('sample.twbx')
for ds in wb.datasources:
    for conn in ds.connections:
        print(f'DB: {conn.dbname}, Server: {conn.server}')
        conn.server = 'new-server.example.com'
wb.save_as('output.twbx')