tableau / document-api-python

Create and modify Tableau workbook and datasource files
https://tableau.github.io/document-api-python/
MIT License
331 stars 177 forks source link

Replace Datasource #35

Open benlower opened 8 years ago

benlower commented 8 years ago

(via beta feedback)

Replace data source -- we have QA and prod data sources and it would be good to be able to change the data source a worksheet uses programmatically

graysonarts commented 8 years ago

This is significantly non-trivial.

benlower commented 8 years ago

do we need a "SNT" label for items like this then? :)

jessebikman commented 7 years ago

So wait, it's not a matter of using a conditional on the datasource? I couldn't just modify the below example to change the server name and save the workbook whenever the script is run?


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()
t8y8 commented 7 years ago

@jessebikman it depends on what the original ask meant to cover for 'Replace Data Source' -- Tableau Desktop has a feature by that name that re-targets all worksheets (including calculations and table calcs) to use the new data source (which may have slightly different properties, like comments on fields).

That's 'SNT'

Just changing the connection information ('sql-dev' to 'sql-prod') is pretty easy, and as you point out, possible today.

jessebikman commented 7 years ago

Oh yes, the feature named that! Ok - thanks for making that more clear. Obvious in hindsight now.

ebolz commented 7 years ago

I've run the sample code to modify and save a workbook. I can change the Server name, the Database name, the User name, and the Port, but there does not seem to be any way to change the database table. Hardly seems useful without that. Am I missing something?

t8y8 commented 7 years ago

@ebolz please open a new issue with a quick example.

Right now the connection object doesn't expose table name (not all connection types have table) but it would be easy to add!

mattdotgreenlake commented 7 years ago

What I'd like is a merge option. if you add a datasource or sheet+datasource, if datasource with same connection details exists, add all customizations and calculated fields from new source to existing. log report for merge conflicts where there are name collisions, etc...

scenario (assumes you know what logshark is or will go look it up now):

  1. logshark makes standard 'canned' twb files
  2. individual cases cause me to make dashboards I'd love to use in future logshark twb files for new log sets
  3. currently I have to copy/paste those dashboards manually and manually replace datasource for pasted dashboard to use new logshark twb's datasource
  4. preference would be to run a script of my design that takes twb (better...tbm!) and a. adds the flippin sweet twb sheets to the new logshark output twb files b. merges the connections so that the workbook still only has one connection for vanilla logshark sheets and my own added sheets with all their lovely aliases and calcs included for all sheets
Naiana-Tableau commented 7 years ago
YEM-1 commented 6 years ago

In this code: sourceWB.datasources[0].connections[0].server = "MY-NEW-SERVER" sourceWB.datasources[0].connections[0].dbname = "NEW-DATABASE" sourceWB.datasources[0].connections[0].username = "benl"

It does not seem like Document API allows a way for the user to give the password for the database. Does it assume the password is the same in "NEW-DATABSE" as it was in the old database? I don't understand how it can ask for a database user but not password.

gmkey69 commented 6 years ago

Hi guys, Sorry but rookie to Python and API syntax... Though I did manage to adapt the TSC API codes to my own stuff (server, site, db, etc...), I couldn't find a way to make these 3 lines of code from document API to work fine !!

First, I have not been able to make this code find my workbook from its name !! Server problem ? Name ? What is wrong ? Does it need the whole path to the physical file ? assumed it was working n the server, then try full path but didn't work either.

As a resume : I am lost ;) THANKS in advance for your help.

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()

andymiller-og commented 5 years ago

@benlower Hi! I am surprised this is of more interest - or maybe I am missing something. I would imagine MANY would like to have two published data sources (exactly the same with the exception of the connection string) - call them "stg" and "prod". Those data sources are likely being refreshed regularly. Now, I as the admin have a .twb with connections to the published data sources (which are federated btw). What I would like to do is take the ONE .twb workbook which is using the "stg" data source on server. Id like to save over the existing workbook, then switch the "stg" to "prod" datasource (which are exactly the same besides the connection details) and publish. What am i missing? I would think (while dangerous in many circumstances) I could replace a "datasource".

pjcpjc commented 4 years ago

@YEM-1 (or anyone else that is interested) I'm fairly confident that a .twbx/.twb file does not store a password. I would assume this was a deliberate security decision by the Tableau team. It certainly seems like a wise decision to me.

YEM-1 commented 4 years ago

@YEM-1 (or anyone else that is interested) I'm fairly confident that a .twbx/.twb file does not store a password. I would assume this was a deliberate security decision by the Tableau team. It certainly seems like a wise decision to me.

Published data sources contain embedded passwords.

pjcpjc commented 4 years ago

@YEM-1 (or anyone else that is interested) I'm fairly confident that a .twbx/.twb file does not store a password. I would assume this was a deliberate security decision by the Tableau team. It certainly seems like a wise decision to me.

Published data sources contain embedded passwords.

Well, I suppose that is easy to say. Do you have any evidence the password is present in the .twb/.twbx file? The .twb file is simply XML, its easy to examine. There is also the behavior of Tableau itself, which seems to repeatedly request passwords in a manner indicating that the .twb/.twbx files aren't archiving them.

graysonarts commented 4 years ago

Hi @YEM-1 the twb/twbx/tds/tdsx does not contain the password so the document api does not provide a way to embed the password. Embedded passwords are only a concept in the context of Tableau Server, and they are stored in a secure manner separate from the datasource documents as you would expect from any secure application that needs to store and handle user provided credentials.

pjcpjc commented 4 years ago

@RussTheAerialist Thanks! So say we all.

Trones21 commented 1 year ago

I'm currently looking for a way to replace one published datasource with another. I'm not sure if this is currently possible (just started exploring the Document API)... but anyway I think an API contract like this would be nice to have:

WB = Workbook('..\data\myDownloadedWB.twbx') newDS = Datasource.from_file('..\data\myDownloadedDS.tdsx') WB.datasources[0].save(newDS)

An even better solution would be to let us do this directly on the server! Currently I'm using the REST API to download/publish