|
1 | 1 | # tableausdk-python
|
2 | 2 |
|
3 |
| -Tableau SDK for Python. Currently this contains only the Document API. We are just getting started and this will evolve. Help us by submitting feedback, issues, and pull requests! |
| 3 | +This repo contains Python source and example files for the Tableau SDK. Currently the repo contains only the Document API. We're just getting started and have plans to expand what you find here. Help us by submitting feedback, issues, and pull requests! |
4 | 4 |
|
5 | 5 | Document API
|
6 | 6 | ---------------
|
7 |
| -This is the supported way to programmatically change Tableau files such as .twb and .tds. If you've been doing "XML hacking" this is for you too :) |
8 |
| - |
9 |
| -Check out the examples to see how to use it. |
| 7 | +The Document API provides a supported way to programmatically make updates to Tableau workbook (`.twb`) and data source (`.tds`) files. If you've been making changes to these file types by directly updating the XML--that is, by XML hacking--this SDK is for you :) |
10 | 8 |
|
11 | 9 | Currently only the following operations are supported:
|
12 | 10 |
|
13 |
| -* Modify database server |
14 |
| -* Modify database name |
15 |
| -* Modify database user |
| 11 | +- Modify database server |
| 12 | +- Modify database name |
| 13 | +- Modify database user |
| 14 | + |
| 15 | +We don't yet support creating files from scratch. In addition, support for `.twbx` and `.tdsx` files is coming. |
| 16 | + |
| 17 | + |
| 18 | +###Getting Started |
| 19 | +To use this SDK, you must have Python installed. You can use either 2.7x or 3.3x. |
| 20 | + |
| 21 | +Download the `.zip` file that contains the SDK. Unzip the file and then run the following command: |
| 22 | + |
| 23 | + pip install -e <directory containing setup.py> |
| 24 | + |
| 25 | +We plan on putting the package in PyPi to make installation easier. |
| 26 | + |
| 27 | + |
| 28 | +###Basics |
| 29 | +The following example shows the basic syntax for using the Document API to update a workbook: |
| 30 | + |
| 31 | + from tableaudocumentapi import Workbook |
| 32 | + |
| 33 | + sourceWB = Workbook('WorkbookToUpdate.twb') |
| 34 | + |
| 35 | + sourceWB.datasources[0].connection.server = "MY-NEW-SERVER" |
| 36 | + sourceWB.datasources[0].connection.dbname = "NEW-DATABASE" |
| 37 | + sourceWB.datasources[0].connection.username = "benl" |
| 38 | + |
| 39 | + sourceWB.save() |
| 40 | + |
| 41 | + |
| 42 | +**Notes** |
| 43 | + |
| 44 | +- Import the `Workbook` object from the `tableaudocumentapi` module. |
| 45 | +- To open a workbook, instantiate a `Workbook` object and pass the `.twb` file name in the constructor. |
| 46 | +- The `Workbook` object exposes a `datasources` collection. |
| 47 | +- Each datasource object has a `connection` object that supports a `server`, `dbname`, and `username` property. |
| 48 | +- Save changes to the workbook by calling the `save` or `save_as` method. |
| 49 | + |
| 50 | + |
16 | 51 |
|
17 |
| -We don't yet support creating files from scratch. Support for .twbx and .tdsx is coming. |
| 52 | +###Examples |
18 | 53 |
|
19 |
| -##### Getting Started |
20 |
| -We will put this in PyPi to make installation easier. In the meantime, install the package locally with: |
21 |
| -```python |
22 |
| -pip install -e <directory containing setup.py> |
23 |
| -``` |
| 54 | +The downloadable package contains an example named `replicateWorkbook.py` (in the folder `\Document API\Examples\Replicate Workbook`). This example reads an existing workbook and reads a .csv file that contains a list of servers, database names, and users. For each new user in the .csv file, the code copies the original workbook, updates the `server`, `dbname`, and `username` properties, and saves the workbook under a new name. |
0 commit comments