dagster-polytomic 0.28.12__tar.gz

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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Dagster Labs, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ include README.md
2
+ include LICENSE
3
+ include dagster_polytomic/py.typed
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: dagster_polytomic
3
+ Version: 0.28.12
4
+ Summary: Package for integrating Polytomic with Dagster.
5
+ Home-page: https://github.com/dagster-io/dagster/tree/master/python_modules/libraries/dagster-polytomic
6
+ Author: Dagster Labs
7
+ Author-email: hello@dagsterlabs.com
8
+ License: Apache-2.0
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.10,<3.15
17
+ License-File: LICENSE
18
+ Requires-Dist: dagster==1.12.12
19
+ Requires-Dist: polytomic>=1.11.3
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: classifier
23
+ Dynamic: home-page
24
+ Dynamic: license
25
+ Dynamic: license-file
26
+ Dynamic: requires-dist
27
+ Dynamic: requires-python
28
+ Dynamic: summary
@@ -0,0 +1,4 @@
1
+ # dagster-polytomic
2
+
3
+ The docs for `dagster-polytomic` can be found
4
+ [here](https://docs.dagster.io/integrations/libraries/polytomic/dagster-polytomic).
@@ -0,0 +1,6 @@
1
+ from dagster_shared.libraries import DagsterLibraryRegistry
2
+
3
+ from dagster_polytomic.component import PolytomicComponent as PolytomicComponent
4
+ from dagster_polytomic.version import __version__ as __version__
5
+
6
+ DagsterLibraryRegistry.register("dagster-polytomic", __version__)
@@ -0,0 +1,134 @@
1
+ import itertools
2
+ from collections import defaultdict
3
+ from pathlib import Path
4
+ from typing import Optional
5
+
6
+ import dagster as dg
7
+ from dagster._annotations import preview
8
+ from dagster._core.definitions.metadata.metadata_set import TableMetadataSet
9
+ from dagster._core.errors import DagsterInvalidDefinitionError
10
+ from dagster.components.component.state_backed_component import StateBackedComponent
11
+ from dagster.components.utils.defs_state import (
12
+ DefsStateConfig,
13
+ DefsStateConfigArgs,
14
+ ResolvedDefsStateConfig,
15
+ )
16
+ from pydantic import Field
17
+
18
+ from dagster_polytomic.objects import PolytomicBulkSyncEnrichedSchema, PolytomicWorkspaceData
19
+ from dagster_polytomic.translation import (
20
+ _TRANSLATOR_DATA_METADATA_KEY,
21
+ PolytomicSchemaMetadataSet,
22
+ PolytomicTranslatorData,
23
+ ResolvedPolytomicTranslationFn,
24
+ )
25
+ from dagster_polytomic.workspace import PolytomicWorkspace
26
+
27
+
28
+ @preview
29
+ class PolytomicComponent(StateBackedComponent, dg.Model, dg.Resolvable):
30
+ workspace: PolytomicWorkspace = Field(
31
+ description="Defines configuration for interacting with a Polytomic organization.",
32
+ )
33
+ translation: Optional[ResolvedPolytomicTranslationFn] = Field(
34
+ default=None,
35
+ description="Defines how to translate a Polytomic object into an AssetSpec object.",
36
+ )
37
+ defs_state: ResolvedDefsStateConfig = DefsStateConfigArgs.local_filesystem()
38
+
39
+ @property
40
+ def defs_state_config(self) -> DefsStateConfig:
41
+ default_key = f"{self.__class__.__name__}[{self.workspace.identity.organization_name}]"
42
+ return DefsStateConfig.from_args(self.defs_state, default_key=default_key)
43
+
44
+ async def write_state_to_path(self, state_path: Path) -> None:
45
+ """Fetch documents from Polytomic API and write state to path."""
46
+ state = await self.workspace.fetch_polytomic_state()
47
+ state_path.write_text(dg.serialize_value(state))
48
+
49
+ def load_state_from_path(self, state_path: Path) -> PolytomicWorkspaceData:
50
+ """Load state from path using Dagster's deserialization system."""
51
+ return dg.deserialize_value(state_path.read_text(), PolytomicWorkspaceData)
52
+
53
+ def _get_default_polytomic_spec(self, data: PolytomicTranslatorData) -> Optional[dg.AssetSpec]:
54
+ """Core function for converting a Polytomic schema into an AssetSpec object."""
55
+ if isinstance(data.obj, PolytomicBulkSyncEnrichedSchema):
56
+ enriched_schema = data.obj
57
+ return dg.AssetSpec(
58
+ key=dg.AssetKey(
59
+ [enriched_schema.destination_configuration_schema or "", enriched_schema.id]
60
+ ),
61
+ group_name=enriched_schema.destination_configuration_schema.replace("-", "_")
62
+ if enriched_schema.destination_configuration_schema
63
+ else None,
64
+ metadata={
65
+ _TRANSLATOR_DATA_METADATA_KEY: data,
66
+ **PolytomicSchemaMetadataSet.from_enriched_schema(
67
+ enriched_schema=enriched_schema
68
+ ),
69
+ **TableMetadataSet(
70
+ table_name=f"{enriched_schema.destination_configuration_schema}.{enriched_schema.id}"
71
+ if enriched_schema.destination_configuration_schema
72
+ else enriched_schema.id
73
+ ),
74
+ },
75
+ kinds={"polytomic"},
76
+ )
77
+ return None
78
+
79
+ def get_asset_spec(self, data: PolytomicTranslatorData) -> Optional[dg.AssetSpec]:
80
+ """Core function for converting a Polytomic object into an AssetSpec object."""
81
+ base_asset_spec = self._get_default_polytomic_spec(data)
82
+ if self.translation and base_asset_spec:
83
+ return self.translation(base_asset_spec, data)
84
+ else:
85
+ return base_asset_spec
86
+
87
+ def _build_asset_specs(self, workspace_data: PolytomicWorkspaceData) -> list[dg.AssetSpec]:
88
+ """Invokes the `get_asset_spec` method on all objects in the provided `workspace_data`.
89
+ Filters out any cases where the asset_spec is `None`, and provides a helpful error
90
+ message in cases where keys overlap between different documents.
91
+ """
92
+ maybe_specs = [
93
+ self.get_asset_spec(
94
+ PolytomicTranslatorData(obj=enriched_schema, workspace_data=workspace_data)
95
+ )
96
+ for enriched_schema in itertools.chain.from_iterable(
97
+ workspace_data.enriched_schemas_by_bulk_sync_id.values()
98
+ )
99
+ ]
100
+
101
+ specs_by_key: dict[dg.AssetKey, list[dg.AssetSpec]] = defaultdict(list)
102
+ for spec in filter(None, maybe_specs):
103
+ specs_by_key[spec.key].append(spec)
104
+
105
+ for key, specs in specs_by_key.items():
106
+ if len(specs) == 1:
107
+ continue
108
+
109
+ ids = [
110
+ PolytomicSchemaMetadataSet.extract(spec.metadata).bulk_sync_id or spec
111
+ for spec in specs
112
+ ]
113
+ ids_str = "\n\t".join(map(str, ids))
114
+ raise DagsterInvalidDefinitionError(
115
+ f"Multiple objects map to the same key {key}:"
116
+ f"\n\t{ids_str}\n"
117
+ "Please ensure that each object has a unique name by updating the `translation` function."
118
+ )
119
+
120
+ return list(itertools.chain.from_iterable(specs_by_key.values()))
121
+
122
+ def build_defs_from_workspace_data(
123
+ self, workspace_data: PolytomicWorkspaceData
124
+ ) -> dg.Definitions:
125
+ return dg.Definitions(assets=self._build_asset_specs(workspace_data))
126
+
127
+ def build_defs_from_state(
128
+ self, context: dg.ComponentLoadContext, state_path: Optional[Path]
129
+ ) -> dg.Definitions:
130
+ if state_path is None:
131
+ return dg.Definitions()
132
+
133
+ state = self.load_state_from_path(state_path)
134
+ return self.build_defs_from_workspace_data(state)
@@ -0,0 +1,235 @@
1
+ from collections import defaultdict
2
+ from functools import cached_property
3
+ from typing import Optional
4
+
5
+ from dagster import _check as check
6
+ from dagster_shared.record import record
7
+ from dagster_shared.serdes import whitelist_for_serdes
8
+ from polytomic import (
9
+ BulkField,
10
+ BulkSchema,
11
+ BulkSyncResponse,
12
+ ConnectionResponseSchema,
13
+ GetIdentityResponseSchema,
14
+ )
15
+
16
+
17
+ @whitelist_for_serdes
18
+ @record
19
+ class PolytomicIdentity:
20
+ """Represents a Polytomic identity."""
21
+
22
+ id: str
23
+ organization_id: str
24
+ organization_name: str
25
+
26
+ @classmethod
27
+ def from_api_response(cls, response: GetIdentityResponseSchema) -> "PolytomicIdentity":
28
+ """Create PolytomicIdentity from API response."""
29
+ return cls(
30
+ id=check.not_none(response.id, "Identity ID cannot be None"),
31
+ organization_id=check.not_none(
32
+ response.organization_id, "Organization ID cannot be None"
33
+ ),
34
+ organization_name=check.not_none(
35
+ response.organization_name, "Organization name cannot be None"
36
+ ),
37
+ )
38
+
39
+
40
+ @whitelist_for_serdes
41
+ @record
42
+ class PolytomicConnection:
43
+ """Represents a Polytomic connection."""
44
+
45
+ id: str
46
+ name: Optional[str]
47
+ type: Optional[str]
48
+ organization_id: Optional[str]
49
+ status: Optional[str]
50
+
51
+ @classmethod
52
+ def from_api_response(cls, response: ConnectionResponseSchema) -> "PolytomicConnection":
53
+ """Create PolytomicConnection from API response."""
54
+ return cls(
55
+ id=check.not_none(response.id, "Connection ID cannot be None"),
56
+ name=response.name,
57
+ type=response.type.name if response.type else None,
58
+ organization_id=response.organization_id,
59
+ status=response.status,
60
+ )
61
+
62
+
63
+ @whitelist_for_serdes
64
+ @record
65
+ class PolytomicBulkSync:
66
+ """Represents a Polytomic bulk sync."""
67
+
68
+ id: str
69
+ name: Optional[str]
70
+ active: bool
71
+ mode: Optional[str]
72
+ source_connection_id: Optional[str]
73
+ destination_connection_id: Optional[str]
74
+ organization_id: Optional[str]
75
+ destination_configuration_schema: Optional[str]
76
+
77
+ @classmethod
78
+ def from_api_response(cls, response: BulkSyncResponse) -> "PolytomicBulkSync":
79
+ """Create PolytomicBulkSync from API response."""
80
+ return cls(
81
+ id=check.not_none(response.id, "Bulk sync ID cannot be None"),
82
+ name=response.name,
83
+ active=response.active or False,
84
+ mode=response.mode,
85
+ source_connection_id=response.source_connection_id,
86
+ destination_connection_id=response.destination_connection_id,
87
+ organization_id=response.organization_id,
88
+ destination_configuration_schema=response.destination_configuration.get("schema")
89
+ if response.destination_configuration
90
+ else None,
91
+ )
92
+
93
+
94
+ @whitelist_for_serdes
95
+ @record
96
+ class PolytomicBulkField:
97
+ """Represents a field in a Polytomic bulk schema."""
98
+
99
+ id: str
100
+ enabled: bool
101
+
102
+ @classmethod
103
+ def from_api_response(cls, response: BulkField) -> "PolytomicBulkField":
104
+ """Create PolytomicBulkField from API field data."""
105
+ return cls(
106
+ id=check.not_none(response.id, "Bulk field ID cannot be None"),
107
+ enabled=response.enabled or False,
108
+ )
109
+
110
+
111
+ @whitelist_for_serdes
112
+ @record
113
+ class PolytomicBulkSyncSchema:
114
+ """Represents a schema in a Polytomic bulk sync."""
115
+
116
+ id: str
117
+ enabled: bool
118
+ output_name: Optional[str]
119
+ partition_key: Optional[str]
120
+ tracking_field: Optional[str]
121
+ fields: list[PolytomicBulkField]
122
+
123
+ @classmethod
124
+ def from_api_response(cls, response: BulkSchema) -> "PolytomicBulkSyncSchema":
125
+ """Create PolytomicBulkSyncSchema from API response."""
126
+ fields = []
127
+ if response.fields:
128
+ fields = [PolytomicBulkField.from_api_response(field) for field in response.fields]
129
+
130
+ return cls(
131
+ id=check.not_none(response.id, "Bulk sync schema ID cannot be None"),
132
+ enabled=response.enabled or False,
133
+ output_name=response.output_name,
134
+ partition_key=response.partition_key,
135
+ tracking_field=response.tracking_field,
136
+ fields=fields,
137
+ )
138
+
139
+
140
+ @whitelist_for_serdes
141
+ @record
142
+ class PolytomicBulkSyncEnrichedSchema:
143
+ """Represents an enriched schema in a Polytomic bulk sync."""
144
+
145
+ id: str
146
+ bulk_sync_id: str
147
+ enabled: bool
148
+ output_name: Optional[str]
149
+ partition_key: Optional[str]
150
+ tracking_field: Optional[str]
151
+ fields: list[PolytomicBulkField]
152
+ destination_configuration_schema: Optional[str]
153
+ source_connection_id: Optional[str]
154
+ source_connection_name: Optional[str]
155
+ destination_connection_id: Optional[str]
156
+ destination_connection_name: Optional[str]
157
+
158
+
159
+ @whitelist_for_serdes
160
+ @record
161
+ class PolytomicWorkspaceData:
162
+ """Serializable container object for recording the state of the Polytomic API at a given point in time.
163
+
164
+ Properties:
165
+ connections: list[PolytomicConnection]
166
+ bulk_syncs: list[PolytomicBulkSync]
167
+ schemas_by_bulk_sync_id: dict[str, list[PolytomicBulkSyncSchema]] - Mapping of bulk sync ID to its schemas
168
+ """
169
+
170
+ connections: list[PolytomicConnection]
171
+ bulk_syncs: list[PolytomicBulkSync]
172
+ schemas_by_bulk_sync_id: dict[str, list[PolytomicBulkSyncSchema]]
173
+
174
+ @cached_property
175
+ def enriched_schemas_by_bulk_sync_id(self) -> dict[str, list[PolytomicBulkSyncEnrichedSchema]]:
176
+ enriched_schemas_by_bulk_sync_id = defaultdict(list)
177
+ for bulk_sync_id, schemas in self.schemas_by_bulk_sync_id.items():
178
+ bulk_sync = self.get_bulk_sync(bulk_sync_id=bulk_sync_id)
179
+ source_connection = (
180
+ self.get_connection(connection_id=bulk_sync.source_connection_id)
181
+ if bulk_sync and bulk_sync.source_connection_id
182
+ else None
183
+ )
184
+ destination_connection = (
185
+ self.get_connection(connection_id=bulk_sync.destination_connection_id)
186
+ if bulk_sync and bulk_sync.destination_connection_id
187
+ else None
188
+ )
189
+
190
+ for schema in schemas:
191
+ enriched_schemas_by_bulk_sync_id[bulk_sync_id].append(
192
+ PolytomicBulkSyncEnrichedSchema(
193
+ id=schema.id,
194
+ bulk_sync_id=bulk_sync_id,
195
+ enabled=schema.enabled,
196
+ output_name=schema.output_name,
197
+ partition_key=schema.partition_key,
198
+ tracking_field=schema.tracking_field,
199
+ fields=schema.fields,
200
+ destination_configuration_schema=bulk_sync.destination_configuration_schema
201
+ if bulk_sync
202
+ else None,
203
+ source_connection_id=bulk_sync.source_connection_id if bulk_sync else None,
204
+ source_connection_name=source_connection.name
205
+ if source_connection
206
+ else None,
207
+ destination_connection_id=bulk_sync.destination_connection_id
208
+ if bulk_sync
209
+ else None,
210
+ destination_connection_name=destination_connection.name
211
+ if destination_connection
212
+ else None,
213
+ )
214
+ )
215
+ return enriched_schemas_by_bulk_sync_id
216
+
217
+ @cached_property
218
+ def _connections_by_id(self) -> dict[str, PolytomicConnection]:
219
+ return {connection.id: connection for connection in self.connections}
220
+
221
+ @cached_property
222
+ def _bulk_syncs_by_id(self) -> dict[str, PolytomicBulkSync]:
223
+ return {bulk_sync.id: bulk_sync for bulk_sync in self.bulk_syncs}
224
+
225
+ def get_connection(self, connection_id: str) -> Optional[PolytomicConnection]:
226
+ """Get a connection by ID."""
227
+ return self._connections_by_id.get(connection_id)
228
+
229
+ def get_bulk_sync(self, bulk_sync_id: str) -> Optional[PolytomicBulkSync]:
230
+ """Get a bulk sync by ID."""
231
+ return self._bulk_syncs_by_id.get(bulk_sync_id)
232
+
233
+ def get_bulk_sync_schemas(self, bulk_sync_id: str) -> list[PolytomicBulkSyncSchema]:
234
+ """Get schemas for a specific bulk sync."""
235
+ return self.schemas_by_bulk_sync_id.get(bulk_sync_id, [])
@@ -0,0 +1 @@
1
+ partial
@@ -0,0 +1,126 @@
1
+ from typing import Annotated, Optional, TypeAlias, Union
2
+
3
+ from dagster._core.definitions.assets.definition.asset_spec import AssetSpec
4
+ from dagster._core.definitions.metadata.metadata_set import NamespacedMetadataSet
5
+ from dagster.components import Resolvable, Resolver
6
+ from dagster.components.resolved.base import resolve_fields
7
+ from dagster.components.resolved.context import ResolutionContext
8
+ from dagster.components.resolved.core_models import AssetSpecUpdateKwargs
9
+ from dagster.components.utils import TranslatorResolvingInfo
10
+ from dagster.components.utils.translation import TranslationFn, TranslationFnResolver
11
+ from dagster_shared.record import record
12
+ from typing_extensions import Self
13
+
14
+ from dagster_polytomic.objects import PolytomicBulkSyncEnrichedSchema, PolytomicWorkspaceData
15
+
16
+ _TRANSLATOR_DATA_METADATA_KEY = ".dagster-polytomic/translator_data"
17
+
18
+
19
+ class PolytomicSchemaMetadataSet(NamespacedMetadataSet):
20
+ """Represents metadata that is captured from a Polytomic schema."""
21
+
22
+ id: str
23
+ bulk_sync_id: str
24
+ output_name: Optional[str] = None
25
+ partition_key: Optional[str] = None
26
+ tracking_field: Optional[str] = None
27
+ source_connection_id: Optional[str] = None
28
+ source_connection_name: Optional[str] = None
29
+ destination_connection_id: Optional[str] = None
30
+ destination_connection_name: Optional[str] = None
31
+
32
+ @classmethod
33
+ def from_enriched_schema(cls, enriched_schema: PolytomicBulkSyncEnrichedSchema) -> Self:
34
+ return cls(
35
+ id=enriched_schema.id,
36
+ bulk_sync_id=enriched_schema.bulk_sync_id,
37
+ output_name=enriched_schema.output_name,
38
+ partition_key=enriched_schema.partition_key,
39
+ tracking_field=enriched_schema.tracking_field,
40
+ source_connection_id=enriched_schema.source_connection_id,
41
+ source_connection_name=enriched_schema.source_connection_name,
42
+ destination_connection_id=enriched_schema.destination_connection_id,
43
+ destination_connection_name=enriched_schema.destination_connection_name,
44
+ )
45
+
46
+ @classmethod
47
+ def namespace(cls) -> str:
48
+ return "dagster-polytomic"
49
+
50
+
51
+ @record
52
+ class PolytomicTranslatorData:
53
+ """Container class for data required to translate an object in an
54
+ Polytomic workspace into a Dagster definition.
55
+
56
+ Properties:
57
+ obj (PolytomicBulkSyncEnrichedSchema): The object to translate.
58
+ workspace_data (PolytomicWorkspaceData): Global workspace data.
59
+ """
60
+
61
+ obj: PolytomicBulkSyncEnrichedSchema
62
+ workspace_data: PolytomicWorkspaceData
63
+
64
+
65
+ def _resolve_multilayer_translation(context: ResolutionContext, model):
66
+ """The Polytomic translation schema supports defining global transforms
67
+ as well as per-object-type transforms. This resolver composes the
68
+ per-object-type transforms with the global transforms.
69
+ """
70
+ info = TranslatorResolvingInfo(
71
+ asset_attributes=model,
72
+ resolution_context=context,
73
+ model_key="translation",
74
+ )
75
+
76
+ def _translation_fn(base_asset_spec: AssetSpec, data: PolytomicTranslatorData):
77
+ processed_spec = info.get_asset_spec(
78
+ base_asset_spec,
79
+ {
80
+ "data": data,
81
+ "spec": base_asset_spec,
82
+ },
83
+ )
84
+
85
+ nested_translation_fns = resolve_fields(
86
+ model=model,
87
+ resolved_cls=PolytomicTranslationArgs,
88
+ context=context.with_scope(
89
+ **{
90
+ "data": data,
91
+ "spec": processed_spec,
92
+ }
93
+ ),
94
+ )
95
+ for_schema = nested_translation_fns.get("for_schema")
96
+
97
+ if isinstance(data.obj, PolytomicBulkSyncEnrichedSchema) and for_schema:
98
+ return for_schema(processed_spec, data)
99
+
100
+ return processed_spec
101
+
102
+ return _translation_fn
103
+
104
+
105
+ PolytomicTranslationFn: TypeAlias = TranslationFn[PolytomicTranslatorData]
106
+
107
+ ResolvedTargetedPolytomicTranslationFn = Annotated[
108
+ PolytomicTranslationFn,
109
+ TranslationFnResolver[PolytomicTranslatorData](lambda data: {"data": data}),
110
+ ]
111
+
112
+
113
+ @record
114
+ class PolytomicTranslationArgs(AssetSpecUpdateKwargs, Resolvable):
115
+ """Model used to allow per-object-type translation of a Polytomic object."""
116
+
117
+ for_schema: Optional[ResolvedTargetedPolytomicTranslationFn] = None
118
+
119
+
120
+ ResolvedPolytomicTranslationFn = Annotated[
121
+ PolytomicTranslationFn,
122
+ Resolver(
123
+ _resolve_multilayer_translation,
124
+ model_field_type=Union[str, PolytomicTranslationArgs.model()],
125
+ ),
126
+ ]
@@ -0,0 +1 @@
1
+ __version__ = "0.28.12"
@@ -0,0 +1,92 @@
1
+ import asyncio
2
+ from functools import cached_property
3
+
4
+ import dagster as dg
5
+ from dagster import _check as check
6
+ from polytomic import AsyncPolytomic, Polytomic
7
+ from pydantic import Field
8
+
9
+ from dagster_polytomic.objects import (
10
+ PolytomicBulkSync,
11
+ PolytomicBulkSyncSchema,
12
+ PolytomicConnection,
13
+ PolytomicIdentity,
14
+ PolytomicWorkspaceData,
15
+ )
16
+
17
+ POLYTOMIC_CLIENT_VERSION = "2024-02-08"
18
+
19
+
20
+ class PolytomicWorkspace(dg.Resolvable, dg.Model):
21
+ """Handles all interactions with the Polytomic API to fetch and manage state."""
22
+
23
+ token: str = Field(
24
+ description="The API key to your Polytomic organization.",
25
+ examples=['"{{ env.POLYTOMIC_API_KEY }}"'],
26
+ repr=False,
27
+ )
28
+
29
+ @cached_property
30
+ def async_client(self) -> AsyncPolytomic:
31
+ return AsyncPolytomic(
32
+ version=POLYTOMIC_CLIENT_VERSION,
33
+ token=self.token,
34
+ )
35
+
36
+ @cached_property
37
+ def client(self) -> Polytomic:
38
+ return Polytomic(
39
+ version=POLYTOMIC_CLIENT_VERSION,
40
+ token=self.token,
41
+ )
42
+
43
+ @cached_property
44
+ def identity(self) -> PolytomicIdentity:
45
+ data = self.client.identity.get().data
46
+ return PolytomicIdentity.from_api_response(
47
+ check.not_none(data, "Identity data cannot be None")
48
+ )
49
+
50
+ async def _fetch_connections(self) -> list[PolytomicConnection]:
51
+ """Fetch all connections."""
52
+ response = await self.async_client.connections.list()
53
+ data = response.data or []
54
+ return [PolytomicConnection.from_api_response(conn) for conn in data]
55
+
56
+ async def _fetch_bulk_syncs(self) -> list[PolytomicBulkSync]:
57
+ """Fetch all bulk syncs."""
58
+ response = await self.async_client.bulk_sync.list()
59
+ data = response.data or []
60
+ return [PolytomicBulkSync.from_api_response(sync) for sync in data]
61
+
62
+ async def _fetch_bulk_sync_schemas(self, bulk_sync_id: str) -> list[PolytomicBulkSyncSchema]:
63
+ """Fetch all schemas for a specific bulk sync."""
64
+ response = await self.async_client.bulk_sync.schemas.list(id=bulk_sync_id)
65
+ data = response.data or []
66
+ return [
67
+ PolytomicBulkSyncSchema.from_api_response(schema) for schema in data if schema.enabled
68
+ ]
69
+
70
+ async def fetch_polytomic_state(self) -> PolytomicWorkspaceData:
71
+ """Fetch all connections, bulks syncs and schemas from the Polytomic API.
72
+
73
+ This is the main public method for getting complete Polytomic state.
74
+ """
75
+ connections = await self._fetch_connections()
76
+ bulk_syncs = await self._fetch_bulk_syncs()
77
+
78
+ # Fetch all schemas in parallel using asyncio.gather
79
+ schema_results = await asyncio.gather(
80
+ *[self._fetch_bulk_sync_schemas(bulk_sync_id=bulk_sync.id) for bulk_sync in bulk_syncs]
81
+ )
82
+
83
+ # Build the schemas dictionary
84
+ schemas = {
85
+ bulk_sync.id: schema_list for bulk_sync, schema_list in zip(bulk_syncs, schema_results)
86
+ }
87
+
88
+ return PolytomicWorkspaceData(
89
+ connections=connections,
90
+ bulk_syncs=bulk_syncs,
91
+ schemas_by_bulk_sync_id=schemas,
92
+ )
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: dagster_polytomic
3
+ Version: 0.28.12
4
+ Summary: Package for integrating Polytomic with Dagster.
5
+ Home-page: https://github.com/dagster-io/dagster/tree/master/python_modules/libraries/dagster-polytomic
6
+ Author: Dagster Labs
7
+ Author-email: hello@dagsterlabs.com
8
+ License: Apache-2.0
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.10,<3.15
17
+ License-File: LICENSE
18
+ Requires-Dist: dagster==1.12.12
19
+ Requires-Dist: polytomic>=1.11.3
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: classifier
23
+ Dynamic: home-page
24
+ Dynamic: license
25
+ Dynamic: license-file
26
+ Dynamic: requires-dist
27
+ Dynamic: requires-python
28
+ Dynamic: summary
@@ -0,0 +1,18 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ setup.cfg
5
+ setup.py
6
+ dagster_polytomic/__init__.py
7
+ dagster_polytomic/component.py
8
+ dagster_polytomic/objects.py
9
+ dagster_polytomic/py.typed
10
+ dagster_polytomic/translation.py
11
+ dagster_polytomic/version.py
12
+ dagster_polytomic/workspace.py
13
+ dagster_polytomic.egg-info/PKG-INFO
14
+ dagster_polytomic.egg-info/SOURCES.txt
15
+ dagster_polytomic.egg-info/dependency_links.txt
16
+ dagster_polytomic.egg-info/not-zip-safe
17
+ dagster_polytomic.egg-info/requires.txt
18
+ dagster_polytomic.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ dagster==1.12.12
2
+ polytomic>=1.11.3
@@ -0,0 +1 @@
1
+ dagster_polytomic
@@ -0,0 +1,14 @@
1
+ [metadata]
2
+ license_files = LICENSE
3
+
4
+ [check-manifest]
5
+ ignore =
6
+ .coveragerc
7
+ tox.ini
8
+ pytest.ini
9
+ dagster_polytomic_tests/**
10
+
11
+ [egg_info]
12
+ tag_build =
13
+ tag_date = 0
14
+
@@ -0,0 +1,39 @@
1
+ from pathlib import Path
2
+
3
+ from setuptools import find_packages, setup
4
+
5
+
6
+ def get_version() -> str:
7
+ version: dict[str, str] = {}
8
+ with open(Path(__file__).parent / "dagster_polytomic/version.py", encoding="utf8") as fp:
9
+ exec(fp.read(), version)
10
+
11
+ return version["__version__"]
12
+
13
+
14
+ ver = get_version()
15
+ # dont pin dev installs to avoid pip dep resolver issues
16
+ pin = "" if ver == "1!0+dev" else f"=={ver}"
17
+ setup(
18
+ name="dagster_polytomic",
19
+ version=ver,
20
+ author="Dagster Labs",
21
+ author_email="hello@dagsterlabs.com",
22
+ license="Apache-2.0",
23
+ description="Package for integrating Polytomic with Dagster.",
24
+ url="https://github.com/dagster-io/dagster/tree/master/python_modules/libraries/dagster-polytomic",
25
+ classifiers=[
26
+ "Programming Language :: Python :: 3.10",
27
+ "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "Programming Language :: Python :: 3.14",
31
+ "License :: OSI Approved :: Apache Software License",
32
+ "Operating System :: OS Independent",
33
+ ],
34
+ packages=find_packages(exclude=["dagster_polytomic_tests*"]),
35
+ include_package_data=True,
36
+ python_requires=">=3.10,<3.15",
37
+ install_requires=["dagster==1.12.12", "polytomic>=1.11.3"],
38
+ zip_safe=False,
39
+ )