This code example uses Tableau APIs to illustrate how to accomplish the following:
- Fetch data from a PostgreSQL table
- Generate a .hyper file
- Publish the .hyper file to Tableau Cloud/Server
Creating extracts programatically is a requirement that manifests itself into many real-world use-cases. Tableau customers continue to need automation capabilities as their business & security requirements evolve.
For example, a business may wish to allow external users the ability to upload data to an external-facing web application (customer portal/partner app/etc.) they manage and make that data available in Tableau Embedded Analytics for consumption seamlessly without forcing the end user to toggle between multiple applications.
Or another example, many Embedded Analytics scenarios involve Single Tenant data architectures where each customer/client/tenant's data is stored in its own data store/set of database tables, aka physical or logical partitioning. You will need a mechanism to take each tenant's data and publish it for use in Tableau and update it as the source data changes. One way to accomplish this is to take advantage of Tableau's hyper fast SQL engine and APIs.
At a high level, you will need to run through the following steps:
- Install all dependencies including PostgreSQL, psycopg2, Tableau Hyper API, Tableau Server Client
- Create a database in PostgreSQL & import Superstore.csv into a database table named "Superstore"
- Create a database user and asign them reading permissions on the database table
- Generate a Tableau Personal Access Token
- Make code edits to the build-extract.py file in the following places (enter your information):
- line 15 - database name
- line 15 - database username
- line 15 - database password
- line 85 - tableau personal access token name
- line 85 - tableau personal access token secret
- line 85 - tableau server/cloud site name
- line 86 - tableau server/cloud domain
- line 96 - tableau project name
IMPORTANT: The code provided in this repository is by no means production-ready code and is only intended to be used for testing/demo purposes.