dagster-airbyte 0.24.3__py3-none-any.whl → 0.28.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,12 @@
1
- from dagster._core.libraries import DagsterLibraryRegistry
1
+ from dagster_shared.libraries import DagsterLibraryRegistry
2
+
3
+ from dagster_airbyte.components.workspace_component.component import (
4
+ AirbyteCloudWorkspaceComponent as AirbyteCloudWorkspaceComponent,
5
+ AirbyteWorkspaceComponent as AirbyteWorkspaceComponent,
6
+ )
2
7
 
3
8
  try:
4
- from .managed import (
9
+ from dagster_airbyte.managed import (
5
10
  AirbyteConnection as AirbyteConnection,
6
11
  AirbyteDestination as AirbyteDestination,
7
12
  AirbyteDestinationNamespace as AirbyteDestinationNamespace,
@@ -14,20 +19,32 @@ try:
14
19
  except ImportError:
15
20
  pass
16
21
 
17
- from .asset_defs import (
22
+ from dagster_airbyte.asset_decorator import airbyte_assets as airbyte_assets
23
+ from dagster_airbyte.asset_defs import (
18
24
  build_airbyte_assets as build_airbyte_assets,
25
+ build_airbyte_assets_definitions as build_airbyte_assets_definitions,
19
26
  load_assets_from_airbyte_instance as load_assets_from_airbyte_instance,
20
- load_assets_from_airbyte_project as load_assets_from_airbyte_project,
21
27
  )
22
- from .ops import airbyte_sync_op as airbyte_sync_op
23
- from .resources import (
28
+ from dagster_airbyte.legacy_resources import (
24
29
  AirbyteCloudResource as AirbyteCloudResource,
25
30
  AirbyteResource as AirbyteResource,
26
- AirbyteState as AirbyteState,
27
31
  airbyte_cloud_resource as airbyte_cloud_resource,
28
32
  airbyte_resource as airbyte_resource,
29
33
  )
30
- from .types import AirbyteOutput as AirbyteOutput
31
- from .version import __version__ as __version__
34
+ from dagster_airbyte.ops import airbyte_sync_op as airbyte_sync_op
35
+ from dagster_airbyte.resources import (
36
+ AirbyteCloudWorkspace as AirbyteCloudWorkspace,
37
+ AirbyteWorkspace as AirbyteWorkspace,
38
+ load_airbyte_asset_specs as load_airbyte_asset_specs,
39
+ load_airbyte_cloud_asset_specs as load_airbyte_cloud_asset_specs,
40
+ )
41
+ from dagster_airbyte.translator import (
42
+ AirbyteConnectionTableProps as AirbyteConnectionTableProps,
43
+ AirbyteJobStatusType as AirbyteJobStatusType,
44
+ AirbyteState as AirbyteState,
45
+ DagsterAirbyteTranslator as DagsterAirbyteTranslator,
46
+ )
47
+ from dagster_airbyte.types import AirbyteOutput as AirbyteOutput
48
+ from dagster_airbyte.version import __version__ as __version__
32
49
 
33
50
  DagsterLibraryRegistry.register("dagster-airbyte", __version__)
@@ -0,0 +1,123 @@
1
+ from collections.abc import Callable
2
+ from typing import Any, Optional, Union
3
+
4
+ from dagster import AssetsDefinition, multi_asset
5
+ from dagster._annotations import beta
6
+ from dagster._core.errors import DagsterInvariantViolationError
7
+
8
+ from dagster_airbyte.resources import AirbyteCloudWorkspace, AirbyteWorkspace
9
+ from dagster_airbyte.translator import AirbyteMetadataSet, DagsterAirbyteTranslator
10
+
11
+
12
+ @beta
13
+ def airbyte_assets(
14
+ *,
15
+ connection_id: str,
16
+ workspace: Union[AirbyteWorkspace, AirbyteCloudWorkspace],
17
+ name: Optional[str] = None,
18
+ group_name: Optional[str] = None,
19
+ dagster_airbyte_translator: Optional[DagsterAirbyteTranslator] = None,
20
+ ) -> Callable[[Callable[..., Any]], AssetsDefinition]:
21
+ """Create a definition for how to sync the tables of a given Airbyte connection.
22
+
23
+ Args:
24
+ connection_id (str): The Airbyte Connection ID.
25
+ workspace (Union[AirbyteWorkspace, AirbyteCloudWorkspace]): The Airbyte workspace to fetch assets from.
26
+ name (Optional[str], optional): The name of the op.
27
+ group_name (Optional[str], optional): The name of the asset group.
28
+ dagster_airbyte_translator (Optional[DagsterAirbyteTranslator], optional): The translator to use
29
+ to convert Airbyte content into :py:class:`dagster.AssetSpec`.
30
+ Defaults to :py:class:`DagsterAirbyteTranslator`.
31
+
32
+ Examples:
33
+ Sync the tables of an Airbyte connection:
34
+
35
+ .. code-block:: python
36
+
37
+ from dagster_airbyte import AirbyteCloudWorkspace, airbyte_assets
38
+
39
+ import dagster as dg
40
+
41
+ airbyte_workspace = AirbyteCloudWorkspace(
42
+ workspace_id=dg.EnvVar("AIRBYTE_CLOUD_WORKSPACE_ID"),
43
+ client_id=dg.EnvVar("AIRBYTE_CLOUD_CLIENT_ID"),
44
+ client_secret=dg.EnvVar("AIRBYTE_CLOUD_CLIENT_SECRET"),
45
+ )
46
+
47
+
48
+ @airbyte_assets(
49
+ connection_id="airbyte_connection_id",
50
+ workspace=airbyte_workspace,
51
+ )
52
+ def airbyte_connection_assets(context: dg.AssetExecutionContext, airbyte: AirbyteCloudWorkspace):
53
+ yield from airbyte.sync_and_poll(context=context)
54
+
55
+
56
+ defs = dg.Definitions(
57
+ assets=[airbyte_connection_assets],
58
+ resources={"airbyte": airbyte_workspace},
59
+ )
60
+
61
+ Sync the tables of an Airbyte connection with a custom translator:
62
+
63
+ .. code-block:: python
64
+
65
+ from dagster_airbyte import (
66
+ DagsterAirbyteTranslator,
67
+ AirbyteConnectionTableProps,
68
+ AirbyteCloudWorkspace,
69
+ airbyte_assets
70
+ )
71
+
72
+ import dagster as dg
73
+
74
+ class CustomDagsterAirbyteTranslator(DagsterAirbyteTranslator):
75
+ def get_asset_spec(self, props: AirbyteConnectionTableProps) -> dg.AssetSpec:
76
+ default_spec = super().get_asset_spec(props)
77
+ return default_spec.merge_attributes(
78
+ metadata={"custom": "metadata"},
79
+ )
80
+
81
+ airbyte_workspace = AirbyteCloudWorkspace(
82
+ workspace_id=dg.EnvVar("AIRBYTE_CLOUD_WORKSPACE_ID"),
83
+ client_id=dg.EnvVar("AIRBYTE_CLOUD_CLIENT_ID"),
84
+ client_secret=dg.EnvVar("AIRBYTE_CLOUD_CLIENT_SECRET"),
85
+ )
86
+
87
+
88
+ @airbyte_assets(
89
+ connection_id="airbyte_connection_id",
90
+ workspace=airbyte_workspace,
91
+ dagster_airbyte_translator=CustomDagsterAirbyteTranslator()
92
+ )
93
+ def airbyte_connection_assets(context: dg.AssetExecutionContext, airbyte: AirbyteCloudWorkspace):
94
+ yield from airbyte.sync_and_poll(context=context)
95
+
96
+
97
+ defs = dg.Definitions(
98
+ assets=[airbyte_connection_assets],
99
+ resources={"airbyte": airbyte_workspace},
100
+ )
101
+ """
102
+ dagster_airbyte_translator = dagster_airbyte_translator or DagsterAirbyteTranslator()
103
+
104
+ specs = [
105
+ spec
106
+ for spec in workspace.load_asset_specs(
107
+ dagster_airbyte_translator=dagster_airbyte_translator
108
+ )
109
+ if AirbyteMetadataSet.extract(spec.metadata).connection_id == connection_id
110
+ ]
111
+
112
+ if any([spec for spec in specs if spec.group_name]) and group_name:
113
+ raise DagsterInvariantViolationError(
114
+ f"Cannot set group_name parameter on airbyte_assets with connection ID {connection_id} - "
115
+ f"one or more of the Airbyte asset specs have a group_name defined."
116
+ )
117
+
118
+ return multi_asset(
119
+ name=name,
120
+ group_name=group_name,
121
+ can_subset=True,
122
+ specs=specs,
123
+ )