This guide provides instructions for using Dagster with Tableau. Your Tableau assets, such as data sources, sheets, and dashboards, can be represented in the Dagster asset graph, allowing you to track lineage and dependencies between Tableau assets and upstream data assets you are already modeling in Dagster.
To load Tableau assets into the Dagster asset graph, you must first construct a Tableau resource, which allows Dagster to communicate with your Tableau workspace. The Tableau resource to create depends on your Tableau deployment type - use TableauCloudWorkspace if you are using Tableau Cloud or TableauServerWorkspace if you are using Tableau Server. To connect to the Tableau workspace, you'll need to configure a connected app with direct trust in Tableau, then supply your Tableau site information and connected app credentials to the resource. The Tableau resource uses the JSON Web Token (JWT) authentication to connect to the Tableau workspace.
Dagster can automatically load all data sources, sheets, and dashboards from your Tableau workspace. Call the build_defs() function, which returns a Definitions object containing all the asset definitions for these Tableau assets.
Use TableauCloudWorkspace to interact with your Tableau Cloud workspace:
from dagster_tableau import TableauCloudWorkspace
from dagster import EnvVar
# Connect to Tableau Cloud using the connected app credentials
workspace = TableauCloudWorkspace(
connected_app_client_id=EnvVar("TABLEAU_CONNECTED_APP_CLIENT_ID"),
connected_app_secret_id=EnvVar("TABLEAU_CONNECTED_APP_SECRET_ID"),
connected_app_secret_value=EnvVar("TABLEAU_CONNECTED_APP_SECRET_VALUE"),
username=EnvVar("TABLEAU_USERNAME"),
site_name=EnvVar("TABLEAU_SITE_NAME"),
pod_name=EnvVar("TABLEAU_POD_NAME"),)
defs = workspace.build_defs()
Use TableauServerWorkspace to interact with your Tableau Server workspace:
from dagster_tableau import TableauServerWorkspace
from dagster import EnvVar
# Connect to Tableau Server using the connected app credentials
workspace = TableauServerWorkspace(
connected_app_client_id=EnvVar("TABLEAU_CONNECTED_APP_CLIENT_ID"),
connected_app_secret_id=EnvVar("TABLEAU_CONNECTED_APP_SECRET_ID"),
connected_app_secret_value=EnvVar("TABLEAU_CONNECTED_APP_SECRET_VALUE"),
username=EnvVar("TABLEAU_USERNAME"),
site_name=EnvVar("TABLEAU_SITE_NAME"),
server_name=EnvVar("TABLEAU_SERVER_NAME"),)
defs = workspace.build_defs()
Customize asset definition metadata for Tableau assets#
By default, Dagster will generate asset keys for each Power BI asset based on its type and name and populate default metadata. You can further customize asset properties by using Definitions.map_asset_specs, which applies a function of your choosing to each asset.
from dagster_tableau import TableauCloudWorkspace
from dagster_tableau.translator import TableauContentData
from dagster import AssetSpec, EnvVar
workspace = TableauCloudWorkspace(
connected_app_client_id=EnvVar("TABLEAU_CONNECTED_APP_CLIENT_ID"),
connected_app_secret_id=EnvVar("TABLEAU_CONNECTED_APP_SECRET_ID"),
connected_app_secret_value=EnvVar("TABLEAU_CONNECTED_APP_SECRET_VALUE"),
username=EnvVar("TABLEAU_USERNAME"),
site_name=EnvVar("TABLEAU_SITE_NAME"),
pod_name=EnvVar("TABLEAU_POD_NAME"),)
defs = workspace.build_defs().map_asset_specs(lambda spec: spec._replace(owners=["my_team"]))
Definitions from multiple Tableau workspaces can be combined by instantiating multiple Tableau resources and merging their definitions. This lets you view all your Tableau assets in a single asset graph:
from dagster_tableau import TableauCloudWorkspace
from dagster import Definitions, EnvVar
sales_team_workspace = TableauCloudWorkspace(
connected_app_client_id=EnvVar("SALES_TABLEAU_CONNECTED_APP_CLIENT_ID"),
connected_app_secret_id=EnvVar("SALES_TABLEAU_CONNECTED_APP_SECRET_ID"),
connected_app_secret_value=EnvVar("SALES_TABLEAU_CONNECTED_APP_SECRET_VALUE"),
username=EnvVar("TABLEAU_USERNAME"),
site_name=EnvVar("SALES_TABLEAU_SITE_NAME"),
pod_name=EnvVar("SALES_TABLEAU_POD_NAME"),)
marketing_team_workspace = TableauCloudWorkspace(
connected_app_client_id=EnvVar("MARKETING_TABLEAU_CONNECTED_APP_CLIENT_ID"),
connected_app_secret_id=EnvVar("MARKETING_TABLEAU_CONNECTED_APP_SECRET_ID"),
connected_app_secret_value=EnvVar("MARKETING_TABLEAU_CONNECTED_APP_SECRET_VALUE"),
username=EnvVar("TABLEAU_USERNAME"),
site_name=EnvVar("MARKETING_TABLEAU_SITE_NAME"),
pod_name=EnvVar("MARKETING_TABLEAU_POD_NAME"),)# We use Definitions.merge to combine the definitions from both workspaces# into a single set of definitions to load
defs = Definitions.merge(
sales_team_workspace.build_defs(),
marketing_team_workspace.build_defs(),)