In this next blog post we will be digging deeper into the API.With the release of the Script step in Tableau Prep 2019.3, it’s possible to integrate Python with Tableau Prep to fetch data from web APIs, use Google’s Geocoding API to fetch postcodes, or deploy predictive models on your data, to give just a few examples. This was just a basic example of using the Document API to extract fields from your data source. The full code to write the output to a file:Ĭongratulations, you’ve just successfully written a Python script to query Tableau’s Document API. Another element you can add is the default field aggregation or the description of the field. You can also add for example, field.calculation in the for loop, which will return a boolean if the field is a calculation. This will return the names of the fields and the field types. The next thing we can do is break this down by individual fields with a for loop. Print ' total fields in your data source'.format(len(sourceTDS.fields)) However, this is not very clear if you run it because the output will just be a bunch of numbers. Once done, we can now extract the first piece of information from our datasource, the total number of fields. I navigated to the file location before I started the script, if you haven’t you need to add the path of the file to the filename. The next step is to load the Tableau Data Source (.tds) file by creating a variable. Once installed we can start importing the Document API Library in order to find information on our data source (scroll down if you can’t wait to see the complete script).įrom tableaudocumentapi import Datasource You can either clone the repo from Github or use pip in your command line (read more on pip here) tds file but first we need to install the Document API library. In this blog we will look at extracting fields from a. Basically everything you would drag and drop, colour or alias in Tableau is documented in the XML and now you can use the Document API to query this.Ī couple of things you can do are: getting information from your workbook (for example detailed information about your fields) and update data connections in a published workbook. You can literally extract everything out of the XML, from your data source connection information to field aliases and calculations. What all these documents have in common is that they are XML files, which means you can open them in any text editor and make changes. The latter two are zipped files, which contain more files (such as TDEs). tds file, which is just a plain file containing your data source connection information, the TWB file, which also contains workbook information, and then you have the. Tableau has several so-called ‘Documents’. With the Document API, Tableau gives you the opportunity to programatically update your Tableau workbooks and data sources. All you need in order to work with the Document API is some knowledge of Python, but wait – don’t click away – I will walk you through setting up a basic Python script in this blog. However, we can put this method to bed now, thanks to the Document API.īut now you are wondering, what precisely can I do with the Document API? This API is part of the Developer toolkit, which also includes the JavaScript API, Extract API and the REST API. This sounds scary but it isn’t, and many have blogged about it. Have you ever had the issue that you downloaded a workbook from Tableau Public and you get an error message saying that your Tableau version is not compatible with the workbook? Well, I think many of us have, and one way of solving this is to ‘hack the XML’. In Part One of this two-parter I will go through the basics of the Document API, what you can do with it and we are going to create a Python script to extract information from a Tableau data source. Who knew that Tableau had a Document API? I guess some of you, but to be fair, Tableau only released the Document API as part of their Developer tools together with the release of version 10. | Andre de Vries Tableau’s Document API & Python: Part l
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |