| title | Get Started |
|---|---|
| layout | docs |
To use this SDK, you must have Python installed. You can use either 2.7.X or 3.3 and later.
- TOC {:toc}
pip install tableaudocumentapiDownload the .zip file that contains the SDK. Unzip the file and then run the following command:
pip install -e <directory containing setup.py>Only do this if you know you want the development version, no guarantee that we won't break APIs during development
pip install git+https://github.com/tableau/document-api-python.git@developmentIf you go this route, but want to switch back to the non-development version, you need to run the following command before installing the stable version:
pip uninstall tableaudocumentapiThe following example shows the basic syntax for using the Document API to update a workbook:
from tableaudocumentapi import Workbook
sourceWB = Workbook('WorkbookToUpdate.twb')
sourceWB.datasources[0].connections[0].server = "MY-NEW-SERVER"
sourceWB.datasources[0].connections[0].dbname = "NEW-DATABASE"
sourceWB.datasources[0].connections[0].username = "benl"
sourceWB.save()With Data Integration in Tableau 10, a data source can have multiple connections. To access the connections simply index them like you would datasources.
from tableaudocumentapi import Workbook
sourceWB = Workbook('WorkbookToUpdate.twb')
sourceWB.datasources[0].connections[0].server = "MY-NEW-SERVER"
sourceWB.datasources[0].connections[0].dbname = "NEW-DATABASE"
sourceWB.datasources[0].connections[0].username = "benl"
sourceWB.datasources[0].connections[1].server = "MY-NEW-SERVER"
sourceWB.datasources[0].connections[1].dbname = "NEW-DATABASE"
sourceWB.datasources[0].connections[1].username = "benl"
sourceWB.save()Notes
- Import the
Workbookobject from thetableaudocumentapimodule. - To open a workbook, instantiate a
Workbookobject and pass the file name as the first argument. - The
Workbookobject exposes a list ofdatasourcesin the workbook - Each data source object has a
connectionobject that supports aserver,dbname, andusernameproperty. - Save changes to the workbook by calling the
saveorsave_asmethod.
Note: This call was added in version Tableau 10.3, XSDv2.5
The downloadable package contains several example scripts that show more detailed usage of the Document API.