Skip to content

Commit

Permalink
[dagster-fivetran][docs] Migrate Fivetran docs to new doc site (#26485)
Browse files Browse the repository at this point in the history
## Summary & Motivation

Copy and migrate new Fivetran docs to new site, see original PR #26026

Removing `docs-to-migrate` tag from the original PR

## How I Tested These Changes

BK.
  • Loading branch information
maximearmstrong authored Dec 16, 2024
1 parent 8e79df1 commit d32aab7
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 29 deletions.
63 changes: 53 additions & 10 deletions docs/docs-beta/docs/integrations/libraries/fivetran.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
layout: Integration
status: published
name: Fivetran
title: Dagster & Fivetran
title: Using Dagster with Fivetran
sidebar_label: Fivetran
excerpt: Orchestrate Fivetran connectors and schedule syncs with upstream or downstream dependencies.
excerpt: Orchestrate Fivetran connectors syncs with upstream or downstream dependencies.
date: 2022-11-07
apireflink: https://docs.dagster.io/_apidocs/libraries/dagster-fivetran
docslink: https://docs.dagster.io/integrations/fivetran
Expand All @@ -17,20 +17,63 @@ enables:
tags: [dagster-supported, etl]
---

This guide provides instructions for using Dagster with Fivetran using the `dagster-fivetran` library. Your Fivetran connector tables can be represented as assets in the Dagster asset graph, allowing you to track lineage and dependencies between Fivetran assets and data assets you are already modeling in Dagster. You can also use Dagster to orchestrate Fivetran connectors, allowing you to trigger syncs for these on a cadence or based on upstream data changes.

## What you'll learn

The Dagster-Fivetran integration enables you to orchestrate data ingestion as part of a larger pipeline. Programmatically interact with the Fivetran REST API to initiate syncs and monitor their progress.
- How to represent Fivetran assets in the Dagster asset graph, including lineage to other Dagster assets.
- How to customize asset definition metadata for these Fivetran assets.
- How to materialize Fivetran connector tables from Dagster.
- How to customize how Fivetran connector tables are materialized.

### Installation
<details>
<summary>Prerequisites</summary>

```bash
pip install dagster-fivetran
```
- The `dagster` and `dagster-fivetran` libraries installed in your environment
- Familiarity with asset definitions and the Dagster asset graph
- Familiarity with Dagster resources
- Familiarity with Fivetran concepts, like connectors and connector tables
- A Fivetran workspace
- A Fivetran API key and API secret. For more information, see [Getting Started](https://fivetran.com/docs/rest-api/getting-started) in the Fivetran REST API documentation.

### Example
</details>

<CodeExample filePath="integrations/fivetran.py" language="python" />
## Represent Fivetran assets in the asset graph

To load Fivetran assets into the Dagster asset graph, you must first construct a <PyObject module="dagster_fivetran" object="FivetranWorkspace" /> resource, which allows Dagster to communicate with your Fivetran workspace. You'll need to supply your account ID, API key and API secret. See [Getting Started](https://fivetran.com/docs/rest-api/getting-started) in the Fivetran REST API documentation for more information on how to create your API key and API secret.

Dagster can automatically load all connector tables from your Fivetran workspace as asset specs. Call the <PyObject module="dagster_fivetran" method="load_fivetran_asset_specs" /> function, which returns list of <PyObject object="AssetSpec" />s representing your Fivetran assets. You can then include these asset specs in your <PyObject object="Definitions" /> object:

<CodeExample filePath="integrations/fivetran/representing_fivetran_assets.py" language="python" />

### Sync and materialize Fivetran assets

You can use Dagster to sync Fivetran connectors and materialize Fivetran connector tables. You can use the <PyObject module="dagster_fivetran" method="build_fivetran_assets_definitions" /> factory to create all assets definitions for your Fivetran workspace.

<CodeExample filePath="integrations/fivetran/sync_and_materialize_fivetran_assets.py" language="python" />

### Customize the materialization of Fivetran assets

If you want to customize the sync of your connectors, you can use the <PyObject module="dagster_fivetran" method="fivetran_assets" /> decorator to do so. This allows you to execute custom code before and after the call to the Fivetran sync.

<CodeExample filePath="integrations/fivetran/customize_fivetran_asset_defs.py" language="python" />

### Customize asset definition metadata for Fivetran assets

By default, Dagster will generate asset specs for each Fivetran asset and populate default metadata. You can further customize asset properties by passing an instance of the custom <PyObject module="dagster_fivetran" object="DagsterFivetranTranslator" /> to the <PyObject module="dagster_fivetran" method="load_fivetran_asset_specs" /> function.

<CodeExample filePath="integrations/fivetran/customize_fivetran_translator_asset_spec.py" language="python" />

Note that `super()` is called in each of the overridden methods to generate the default asset spec. It is best practice to generate the default asset spec before customizing it.

You can pass an instance of the custom <PyObject module="dagster_fivetran" object="DagsterFivetranTranslator" /> to the <PyObject module="dagster_fivetran" method="fivetran_assets" /> decorator or the <PyObject module="dagster_fivetran" method="build_fivetran_assets_definitions" /> factory.

### Load Fivetran assets from multiple workspaces

Definitions from multiple Fivetran workspaces can be combined by instantiating multiple <PyObject module="dagster_fivetran" object="FivetranWorkspace" /> resources and merging their specs. This lets you view all your Fivetran assets in a single asset graph:

<CodeExample filePath="integrations/fivetran/multiple_fivetran_workspaces.py" language="python" />

### About Fivetran

**Fivetran** ingests data from SaaS applications, databases, and servers. The data is stored and typically used for analytics.
**Fivetran** ingests data from SaaS applications, databases, and servers. The data is stored and typically used for analytics.

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from dagster_fivetran import FivetranWorkspace, fivetran_assets

import dagster as dg

fivetran_workspace = FivetranWorkspace(
account_id=dg.EnvVar("FIVETRAN_ACCOUNT_ID"),
api_key=dg.EnvVar("FIVETRAN_API_KEY"),
api_secret=dg.EnvVar("FIVETRAN_API_SECRET"),
)


@fivetran_assets(
connector_id="fivetran_connector_id",
name="fivetran_connector_id",
group_name="fivetran_connector_id",
workspace=fivetran_workspace,
)
def fivetran_connector_assets(
context: dg.AssetExecutionContext, fivetran: FivetranWorkspace
):
# Do something before the materialization...
yield from fivetran.sync_and_poll(context=context)
# Do something after the materialization...


defs = dg.Definitions(
assets=[fivetran_connector_assets],
resources={"fivetran": fivetran_workspace},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from dagster_fivetran import (
DagsterFivetranTranslator,
FivetranConnectorTableProps,
FivetranWorkspace,
load_fivetran_asset_specs,
)

import dagster as dg

fivetran_workspace = FivetranWorkspace(
account_id=dg.EnvVar("FIVETRAN_ACCOUNT_ID"),
api_key=dg.EnvVar("FIVETRAN_API_KEY"),
api_secret=dg.EnvVar("FIVETRAN_API_SECRET"),
)


# A translator class lets us customize properties of the built
# Fivetran assets, such as the owners or asset key
class MyCustomFivetranTranslator(DagsterFivetranTranslator):
def get_asset_spec(self, props: FivetranConnectorTableProps) -> dg.AssetSpec:
# We create the default asset spec using super()
default_spec = super().get_asset_spec(props)
# We customize the metadata and asset key prefix for all assets
return default_spec.replace_attributes(
key=default_spec.key.with_prefix("prefix"),
).merge_attributes(metadata={"custom": "metadata"})


fivetran_specs = load_fivetran_asset_specs(
fivetran_workspace, dagster_fivetran_translator=MyCustomFivetranTranslator()
)

defs = dg.Definitions(assets=fivetran_specs, resources={"fivetran": fivetran_workspace})
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from dagster_fivetran import FivetranWorkspace, load_fivetran_asset_specs

import dagster as dg

sales_fivetran_workspace = FivetranWorkspace(
account_id=dg.EnvVar("FIVETRAN_SALES_ACCOUNT_ID"),
api_key=dg.EnvVar("FIVETRAN_SALES_API_KEY"),
api_secret=dg.EnvVar("FIVETRAN_SALES_API_SECRET"),
)
marketing_fivetran_workspace = FivetranWorkspace(
account_id=dg.EnvVar("FIVETRAN_MARKETING_ACCOUNT_ID"),
api_key=dg.EnvVar("FIVETRAN_MARKETING_API_KEY"),
api_secret=dg.EnvVar("FIVETRAN_MARKETING_API_SECRET"),
)

sales_fivetran_specs = load_fivetran_asset_specs(sales_fivetran_workspace)
marketing_fivetran_specs = load_fivetran_asset_specs(marketing_fivetran_workspace)

# Merge the specs into a single set of definitions
defs = dg.Definitions(
assets=[*sales_fivetran_specs, *marketing_fivetran_specs],
resources={
"marketing_fivetran": marketing_fivetran_workspace,
"sales_fivetran": sales_fivetran_workspace,
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dagster_fivetran import FivetranWorkspace, load_fivetran_asset_specs

import dagster as dg

fivetran_workspace = FivetranWorkspace(
account_id=dg.EnvVar("FIVETRAN_ACCOUNT_ID"),
api_key=dg.EnvVar("FIVETRAN_API_KEY"),
api_secret=dg.EnvVar("FIVETRAN_API_SECRET"),
)

fivetran_specs = load_fivetran_asset_specs(fivetran_workspace)
defs = dg.Definitions(assets=fivetran_specs, resources={"fivetran": fivetran_workspace})
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from dagster_fivetran import FivetranWorkspace, build_fivetran_assets_definitions

import dagster as dg

fivetran_workspace = FivetranWorkspace(
account_id=dg.EnvVar("FIVETRAN_ACCOUNT_ID"),
api_key=dg.EnvVar("FIVETRAN_API_KEY"),
api_secret=dg.EnvVar("FIVETRAN_API_SECRET"),
)

all_fivetran_assets = build_fivetran_assets_definitions(workspace=fivetran_workspace)

defs = dg.Definitions(
assets=all_fivetran_assets,
resources={"fivetran": fivetran_workspace},
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
f"{snippets_folder}/sdf.py",
f"{snippets_folder}/airbyte.py",
f"{snippets_folder}/dlt.py",
f"{snippets_folder}/fivetran.py",
f"{snippets_folder}/fivetran/customize_fivetran_asset_defs.py",
f"{snippets_folder}/fivetran/customize_fivetran_translator_asset_spec.py",
f"{snippets_folder}/fivetran/multiple_fivetran_workspaces.py",
f"{snippets_folder}/fivetran/representing_fivetran_assets.py",
f"{snippets_folder}/fivetran/sync_and_materialize_fivetran_assets.py",
# FIXME: this breaks on py3.8 and seems related to the non-dagster dependencies
f"{snippets_folder}/pandera.py",
}
Expand Down

1 comment on commit d32aab7

@github-actions
Copy link

@github-actions github-actions bot commented on d32aab7 Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for dagster-docs-beta ready!

✅ Preview
https://dagster-docs-beta-2ra5pkvxy-elementl.vercel.app

Built with commit d32aab7.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.