dagster-omni 0.27.9__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.
Potentially problematic release.
This version of dagster-omni might be problematic. Click here for more details.
- dagster_omni-0.27.9/LICENSE +201 -0
- dagster_omni-0.27.9/MANIFEST.in +3 -0
- dagster_omni-0.27.9/PKG-INFO +26 -0
- dagster_omni-0.27.9/README.md +4 -0
- dagster_omni-0.27.9/dagster_omni/__init__.py +6 -0
- dagster_omni-0.27.9/dagster_omni/component.py +149 -0
- dagster_omni-0.27.9/dagster_omni/objects.py +130 -0
- dagster_omni-0.27.9/dagster_omni/py.typed +1 -0
- dagster_omni-0.27.9/dagster_omni/version.py +1 -0
- dagster_omni-0.27.9/dagster_omni/workspace.py +129 -0
- dagster_omni-0.27.9/dagster_omni.egg-info/PKG-INFO +26 -0
- dagster_omni-0.27.9/dagster_omni.egg-info/SOURCES.txt +17 -0
- dagster_omni-0.27.9/dagster_omni.egg-info/dependency_links.txt +1 -0
- dagster_omni-0.27.9/dagster_omni.egg-info/not-zip-safe +1 -0
- dagster_omni-0.27.9/dagster_omni.egg-info/requires.txt +2 -0
- dagster_omni-0.27.9/dagster_omni.egg-info/top_level.txt +1 -0
- dagster_omni-0.27.9/setup.cfg +14 -0
- dagster_omni-0.27.9/setup.py +41 -0
|
@@ -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 2023 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,26 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dagster_omni
|
|
3
|
+
Version: 0.27.9
|
|
4
|
+
Summary: Package for integrating Omni with Dagster.
|
|
5
|
+
Home-page: https://github.com/dagster-io/dagster/tree/master/python_modules/libraries/dagster-omni
|
|
6
|
+
Author: Dagster Labs
|
|
7
|
+
Author-email: hello@dagsterlabs.com
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: dagster==1.11.9
|
|
18
|
+
Requires-Dist: aiohttp
|
|
19
|
+
Dynamic: author
|
|
20
|
+
Dynamic: author-email
|
|
21
|
+
Dynamic: classifier
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: license
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: summary
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
from collections import defaultdict
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional, Union
|
|
5
|
+
|
|
6
|
+
import dagster as dg
|
|
7
|
+
from dagster._annotations import preview
|
|
8
|
+
from dagster._core.definitions.metadata.metadata_set import NamespacedMetadataSet
|
|
9
|
+
from dagster._core.definitions.metadata.metadata_value import UrlMetadataValue
|
|
10
|
+
from dagster._core.errors import DagsterInvalidDefinitionError
|
|
11
|
+
from dagster.components.component.state_backed_component import StateBackedComponent
|
|
12
|
+
from dagster.components.utils.translation import ResolvedTranslationFn
|
|
13
|
+
from dagster_shared.record import record
|
|
14
|
+
from pydantic import Field
|
|
15
|
+
from typing_extensions import Self
|
|
16
|
+
|
|
17
|
+
from dagster_omni.objects import OmniDocument, OmniQuery, OmniWorkspaceData
|
|
18
|
+
from dagster_omni.workspace import OmniWorkspace
|
|
19
|
+
|
|
20
|
+
_TRANSLATOR_DATA_METADATA_KEY = ".dagster-omni/translator_data"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class OmniDocumentMetadataSet(NamespacedMetadataSet):
|
|
24
|
+
url: Optional[UrlMetadataValue] = None
|
|
25
|
+
document_name: str
|
|
26
|
+
document_type: str
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def from_document(cls, workspace: OmniWorkspace, document: OmniDocument) -> Self:
|
|
30
|
+
url_str = f"{workspace.base_url.rstrip('/')}/dashboards/{document.identifier}"
|
|
31
|
+
return cls(
|
|
32
|
+
url=UrlMetadataValue(url_str) if document.has_dashboard else None,
|
|
33
|
+
document_name=document.name,
|
|
34
|
+
document_type=document.type,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
@classmethod
|
|
38
|
+
def namespace(cls) -> str:
|
|
39
|
+
return "dagster-omni"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@record
|
|
43
|
+
class OmniTranslatorData:
|
|
44
|
+
"""Container class for data required to translate an object in an
|
|
45
|
+
Omni workspace into a Dagster definition.
|
|
46
|
+
|
|
47
|
+
Properties:
|
|
48
|
+
obj (Union[OmniDocument, OmniQuery]): The object to translate.
|
|
49
|
+
workspace_data (OmniWorkspaceData): Global workspace data.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
obj: Union[OmniDocument, OmniQuery]
|
|
53
|
+
workspace_data: OmniWorkspaceData
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@preview
|
|
57
|
+
class OmniComponent(StateBackedComponent, dg.Model, dg.Resolvable):
|
|
58
|
+
workspace: OmniWorkspace = Field(
|
|
59
|
+
description="Defines configuration for interacting with an Omni instance.",
|
|
60
|
+
)
|
|
61
|
+
translation: Optional[ResolvedTranslationFn[OmniTranslatorData]] = Field(
|
|
62
|
+
default=None,
|
|
63
|
+
description="Defines how to translate an Omni object into an AssetSpec object.",
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
async def write_state_to_path(self, state_path: Path) -> None:
|
|
67
|
+
"""Fetch documents from Omni API and write state to path."""
|
|
68
|
+
state = await self.workspace.fetch_omni_state()
|
|
69
|
+
state_path.write_text(dg.serialize_value(state))
|
|
70
|
+
|
|
71
|
+
def load_state_from_path(self, state_path: Path) -> OmniWorkspaceData:
|
|
72
|
+
"""Load state from path using Dagster's deserialization system."""
|
|
73
|
+
return dg.deserialize_value(state_path.read_text(), OmniWorkspaceData)
|
|
74
|
+
|
|
75
|
+
def _get_default_asset_spec(self, data: OmniTranslatorData) -> dg.AssetSpec:
|
|
76
|
+
"""Core function for converting an Omni document into an AssetSpec object."""
|
|
77
|
+
if isinstance(data.obj, OmniDocument):
|
|
78
|
+
doc = data.obj
|
|
79
|
+
deps = [
|
|
80
|
+
self.get_asset_spec(
|
|
81
|
+
OmniTranslatorData(obj=query, workspace_data=data.workspace_data)
|
|
82
|
+
)
|
|
83
|
+
for query in doc.queries
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
prefix = doc.folder.path.split("/") if doc.folder else []
|
|
87
|
+
return dg.AssetSpec(
|
|
88
|
+
key=dg.AssetKey([*prefix, doc.name]),
|
|
89
|
+
group_name=prefix[0].replace("-", "_") if prefix else None,
|
|
90
|
+
tags={label.name: "" for label in doc.labels},
|
|
91
|
+
deps=deps,
|
|
92
|
+
metadata={
|
|
93
|
+
**OmniDocumentMetadataSet.from_document(self.workspace, doc),
|
|
94
|
+
_TRANSLATOR_DATA_METADATA_KEY: data,
|
|
95
|
+
},
|
|
96
|
+
kinds={"omni"},
|
|
97
|
+
)
|
|
98
|
+
elif isinstance(data.obj, OmniQuery):
|
|
99
|
+
return dg.AssetSpec(key=dg.AssetKey([data.obj.query_config.table]))
|
|
100
|
+
else:
|
|
101
|
+
raise ValueError(f"Unsupported object type: {type(data.obj)}")
|
|
102
|
+
|
|
103
|
+
def get_asset_spec(self, data: OmniTranslatorData) -> dg.AssetSpec:
|
|
104
|
+
"""Core function for converting an Omni document into an AssetSpec object."""
|
|
105
|
+
base_asset_spec = self._get_default_asset_spec(data)
|
|
106
|
+
if self.translation:
|
|
107
|
+
return self.translation(base_asset_spec, data)
|
|
108
|
+
else:
|
|
109
|
+
return base_asset_spec
|
|
110
|
+
|
|
111
|
+
def _build_asset_specs(self, workspace_data: OmniWorkspaceData) -> list[dg.AssetSpec]:
|
|
112
|
+
"""Invokes the `get_asset_spec` method on all objects in the provided `workspace_data`.
|
|
113
|
+
Filters out any cases where the asset_spec is `None`, and provides a helpful error
|
|
114
|
+
message in cases where keys overlap between different documents.
|
|
115
|
+
"""
|
|
116
|
+
maybe_specs = [
|
|
117
|
+
self.get_asset_spec(OmniTranslatorData(obj=doc, workspace_data=workspace_data))
|
|
118
|
+
for doc in workspace_data.documents
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
specs_by_key: dict[dg.AssetKey, list[dg.AssetSpec]] = defaultdict(list)
|
|
122
|
+
for spec in filter(None, maybe_specs):
|
|
123
|
+
specs_by_key[spec.key].append(spec)
|
|
124
|
+
|
|
125
|
+
for key, specs in specs_by_key.items():
|
|
126
|
+
if len(specs) == 1:
|
|
127
|
+
continue
|
|
128
|
+
|
|
129
|
+
ids = [OmniDocumentMetadataSet.extract(spec.metadata).url or spec for spec in specs]
|
|
130
|
+
ids_str = "\n\t".join(map(str, ids))
|
|
131
|
+
raise DagsterInvalidDefinitionError(
|
|
132
|
+
f"Multiple objects map to the same key {key}:"
|
|
133
|
+
f"\n\t{ids_str}\n"
|
|
134
|
+
"Please ensure that each object has a unique name by updating the `translation` function."
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
return list(itertools.chain.from_iterable(specs_by_key.values()))
|
|
138
|
+
|
|
139
|
+
def build_defs_from_workspace_data(self, workspace_data: OmniWorkspaceData) -> dg.Definitions:
|
|
140
|
+
return dg.Definitions(assets=self._build_asset_specs(workspace_data))
|
|
141
|
+
|
|
142
|
+
def build_defs_from_state(
|
|
143
|
+
self, context: dg.ComponentLoadContext, state_path: Optional[Path]
|
|
144
|
+
) -> dg.Definitions:
|
|
145
|
+
if state_path is None:
|
|
146
|
+
return dg.Definitions()
|
|
147
|
+
|
|
148
|
+
state = self.load_state_from_path(state_path)
|
|
149
|
+
return self.build_defs_from_workspace_data(state)
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
from typing import Any, Optional
|
|
2
|
+
|
|
3
|
+
from dagster_shared.record import record
|
|
4
|
+
from dagster_shared.serdes import whitelist_for_serdes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@whitelist_for_serdes
|
|
8
|
+
@record
|
|
9
|
+
class OmniFolder:
|
|
10
|
+
id: str
|
|
11
|
+
name: str
|
|
12
|
+
path: str
|
|
13
|
+
scope: str
|
|
14
|
+
|
|
15
|
+
@classmethod
|
|
16
|
+
def from_json(cls, data: dict[str, Any]) -> "OmniFolder":
|
|
17
|
+
"""Create OmniFolder from JSON response data."""
|
|
18
|
+
return cls(id=data["id"], name=data["name"], path=data["path"], scope=data["scope"])
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@whitelist_for_serdes
|
|
22
|
+
@record
|
|
23
|
+
class OmniLabel:
|
|
24
|
+
name: str
|
|
25
|
+
verified: bool
|
|
26
|
+
|
|
27
|
+
@classmethod
|
|
28
|
+
def from_json(cls, data: dict[str, Any]) -> "OmniLabel":
|
|
29
|
+
"""Create OmniLabel from JSON response data."""
|
|
30
|
+
return cls(name=data["name"], verified=data["verified"])
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@whitelist_for_serdes
|
|
34
|
+
@record
|
|
35
|
+
class OmniOwner:
|
|
36
|
+
id: str
|
|
37
|
+
name: str
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
def from_json(cls, data: dict[str, Any]) -> "OmniOwner":
|
|
41
|
+
"""Create OmniOwner from JSON response data."""
|
|
42
|
+
return cls(id=data["id"], name=data["name"])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@whitelist_for_serdes
|
|
46
|
+
@record
|
|
47
|
+
class OmniDocument:
|
|
48
|
+
identifier: str
|
|
49
|
+
name: str
|
|
50
|
+
scope: str
|
|
51
|
+
connection_id: str
|
|
52
|
+
deleted: bool
|
|
53
|
+
has_dashboard: bool
|
|
54
|
+
type: str
|
|
55
|
+
updated_at: str
|
|
56
|
+
owner: OmniOwner
|
|
57
|
+
folder: Optional[OmniFolder]
|
|
58
|
+
labels: list[OmniLabel]
|
|
59
|
+
queries: list["OmniQuery"]
|
|
60
|
+
|
|
61
|
+
@classmethod
|
|
62
|
+
def from_json(cls, data: dict[str, Any], queries: list["OmniQuery"]) -> "OmniDocument":
|
|
63
|
+
"""Create OmniDocument from JSON response data."""
|
|
64
|
+
folder = None
|
|
65
|
+
if data.get("folder"):
|
|
66
|
+
folder = OmniFolder.from_json(data["folder"])
|
|
67
|
+
|
|
68
|
+
labels = [OmniLabel.from_json(label_data) for label_data in data.get("labels", [])]
|
|
69
|
+
owner = OmniOwner.from_json(data["owner"])
|
|
70
|
+
|
|
71
|
+
return cls(
|
|
72
|
+
identifier=data["identifier"],
|
|
73
|
+
name=data["name"],
|
|
74
|
+
scope=data["scope"],
|
|
75
|
+
connection_id=data["connectionId"],
|
|
76
|
+
deleted=data["deleted"],
|
|
77
|
+
has_dashboard=data["hasDashboard"],
|
|
78
|
+
type=data.get("type", "document"),
|
|
79
|
+
updated_at=data["updatedAt"],
|
|
80
|
+
owner=owner,
|
|
81
|
+
folder=folder,
|
|
82
|
+
labels=labels,
|
|
83
|
+
queries=queries,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@whitelist_for_serdes
|
|
88
|
+
@record
|
|
89
|
+
class OmniQueryConfig:
|
|
90
|
+
"""Represents the essential query configuration needed for asset creation."""
|
|
91
|
+
|
|
92
|
+
table: str
|
|
93
|
+
fields: list[str]
|
|
94
|
+
|
|
95
|
+
@classmethod
|
|
96
|
+
def from_json(cls, data: dict[str, Any]) -> "OmniQueryConfig":
|
|
97
|
+
"""Create OmniQueryConfig from JSON query configuration data."""
|
|
98
|
+
return cls(
|
|
99
|
+
table=data["table"],
|
|
100
|
+
fields=data["fields"],
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@whitelist_for_serdes
|
|
105
|
+
@record
|
|
106
|
+
class OmniQuery:
|
|
107
|
+
id: str
|
|
108
|
+
name: str
|
|
109
|
+
query_config: OmniQueryConfig
|
|
110
|
+
|
|
111
|
+
@classmethod
|
|
112
|
+
def from_json(cls, data: dict[str, Any]) -> "OmniQuery":
|
|
113
|
+
"""Create OmniQuery from JSON response data."""
|
|
114
|
+
return cls(
|
|
115
|
+
id=data["id"],
|
|
116
|
+
name=data["name"],
|
|
117
|
+
query_config=OmniQueryConfig.from_json(data["query"]),
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@whitelist_for_serdes
|
|
122
|
+
@record
|
|
123
|
+
class OmniWorkspaceData:
|
|
124
|
+
"""Serializable container object for recording the state of the Omni API at a given point in time.
|
|
125
|
+
|
|
126
|
+
Properties:
|
|
127
|
+
documents: list[OmniDocument]
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
documents: list[OmniDocument]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
partial
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.27.9"
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import urllib.parse
|
|
3
|
+
from typing import Any, Optional
|
|
4
|
+
|
|
5
|
+
import aiohttp
|
|
6
|
+
import dagster as dg
|
|
7
|
+
from aiohttp.client_exceptions import ClientResponseError
|
|
8
|
+
from dagster._utils.backoff import async_backoff, exponential_delay_generator
|
|
9
|
+
from pydantic import Field
|
|
10
|
+
|
|
11
|
+
from dagster_omni.objects import OmniDocument, OmniQuery, OmniWorkspaceData
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class OmniWorkspace(dg.Resolvable, dg.Model):
|
|
15
|
+
"""Handles all interactions with the Omni API to fetch and manage state."""
|
|
16
|
+
|
|
17
|
+
base_url: str = Field(
|
|
18
|
+
description="The base URL to your Omni instance.", examples=["https://acme.omniapp.co"]
|
|
19
|
+
)
|
|
20
|
+
api_key: str = Field(
|
|
21
|
+
description="The API key to your Omni instance.",
|
|
22
|
+
examples=['"{{ env.OMNI_API_KEY }}"'],
|
|
23
|
+
repr=False,
|
|
24
|
+
)
|
|
25
|
+
max_retries: int = Field(
|
|
26
|
+
default=5, description="The maximum number of retries to make when rate-limited."
|
|
27
|
+
)
|
|
28
|
+
base_delay: float = Field(
|
|
29
|
+
default=4.0,
|
|
30
|
+
description="The base delay for exponential backoff between retries in seconds.",
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def base_api_url(self) -> str:
|
|
35
|
+
return f"{self.base_url.rstrip('/')}/api/v1"
|
|
36
|
+
|
|
37
|
+
def _get_session(self) -> aiohttp.ClientSession:
|
|
38
|
+
"""Create configured session with Bearer token authentication."""
|
|
39
|
+
headers = {
|
|
40
|
+
"Accept": "application/json",
|
|
41
|
+
"Content-Type": "application/json",
|
|
42
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
43
|
+
}
|
|
44
|
+
return aiohttp.ClientSession(headers=headers)
|
|
45
|
+
|
|
46
|
+
def _should_retry(self, exc: BaseException) -> bool:
|
|
47
|
+
"""Determine if an exception should trigger a retry."""
|
|
48
|
+
if isinstance(exc, ClientResponseError):
|
|
49
|
+
return exc.status == 429 or 500 <= exc.status < 600
|
|
50
|
+
return isinstance(exc, aiohttp.ClientError)
|
|
51
|
+
|
|
52
|
+
def _build_url(self, endpoint: str) -> str:
|
|
53
|
+
return f"{self.base_url.rstrip('/')}/api/v1/{endpoint.lstrip('/')}"
|
|
54
|
+
|
|
55
|
+
async def make_request(
|
|
56
|
+
self,
|
|
57
|
+
endpoint: str,
|
|
58
|
+
params: Optional[dict[str, Any]] = None,
|
|
59
|
+
headers: Optional[dict[str, str]] = None,
|
|
60
|
+
) -> dict[str, Any]:
|
|
61
|
+
"""Make a GET request to the API with retry logic."""
|
|
62
|
+
url = self._build_url(endpoint)
|
|
63
|
+
if params:
|
|
64
|
+
url = f"{url}?{urllib.parse.urlencode(params)}"
|
|
65
|
+
|
|
66
|
+
async def _make_request():
|
|
67
|
+
async with self._get_session() as session:
|
|
68
|
+
request_headers = headers or {}
|
|
69
|
+
async with session.get(url, headers=request_headers) as response:
|
|
70
|
+
response.raise_for_status()
|
|
71
|
+
return await response.json()
|
|
72
|
+
|
|
73
|
+
return await async_backoff(
|
|
74
|
+
_make_request,
|
|
75
|
+
retry_on=self._should_retry,
|
|
76
|
+
max_retries=self.max_retries,
|
|
77
|
+
delay_generator=exponential_delay_generator(base_delay=self.base_delay),
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
async def _fetch_document_queries(self, document_identifier: str) -> list[OmniQuery]:
|
|
81
|
+
"""Fetch all queries for a specific document."""
|
|
82
|
+
endpoint = f"documents/{document_identifier}/queries"
|
|
83
|
+
try:
|
|
84
|
+
response = await self.make_request(endpoint)
|
|
85
|
+
return [OmniQuery.from_json(query_data) for query_data in response.get("queries", [])]
|
|
86
|
+
except ClientResponseError as e:
|
|
87
|
+
# When a document has no queries, this will return 404
|
|
88
|
+
if e.status == 404:
|
|
89
|
+
return []
|
|
90
|
+
raise
|
|
91
|
+
|
|
92
|
+
async def _fetch_document_with_queries(self, document_data: dict[str, Any]) -> OmniDocument:
|
|
93
|
+
"""Returns an OmniDocument with its queries embedded."""
|
|
94
|
+
queries = await self._fetch_document_queries(document_data["identifier"])
|
|
95
|
+
return OmniDocument.from_json(document_data, queries)
|
|
96
|
+
|
|
97
|
+
async def _fetch_documents(self) -> list[OmniDocument]:
|
|
98
|
+
"""Fetch all documents from the Omni API with their queries embedded."""
|
|
99
|
+
base_params = {"pageSize": "100"}
|
|
100
|
+
documents = []
|
|
101
|
+
next_cursor = None
|
|
102
|
+
|
|
103
|
+
while True:
|
|
104
|
+
params = base_params.copy()
|
|
105
|
+
if next_cursor:
|
|
106
|
+
params["cursor"] = next_cursor
|
|
107
|
+
|
|
108
|
+
response = await self.make_request("documents", params)
|
|
109
|
+
|
|
110
|
+
# Fan out the requests to fetch queries for each document in parallel
|
|
111
|
+
coroutines = [
|
|
112
|
+
self._fetch_document_with_queries(doc_data)
|
|
113
|
+
for doc_data in response.get("records", [])
|
|
114
|
+
]
|
|
115
|
+
documents.extend(await asyncio.gather(*coroutines))
|
|
116
|
+
|
|
117
|
+
next_cursor = response.get("pageInfo", {}).get("nextCursor")
|
|
118
|
+
if not next_cursor:
|
|
119
|
+
break
|
|
120
|
+
|
|
121
|
+
return documents
|
|
122
|
+
|
|
123
|
+
async def fetch_omni_state(self) -> OmniWorkspaceData:
|
|
124
|
+
"""Fetch all documents from the Omni API with queries embedded.
|
|
125
|
+
|
|
126
|
+
This is the main public method for getting complete Omni state.
|
|
127
|
+
"""
|
|
128
|
+
documents = await self._fetch_documents()
|
|
129
|
+
return OmniWorkspaceData(documents=documents)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dagster_omni
|
|
3
|
+
Version: 0.27.9
|
|
4
|
+
Summary: Package for integrating Omni with Dagster.
|
|
5
|
+
Home-page: https://github.com/dagster-io/dagster/tree/master/python_modules/libraries/dagster-omni
|
|
6
|
+
Author: Dagster Labs
|
|
7
|
+
Author-email: hello@dagsterlabs.com
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: dagster==1.11.9
|
|
18
|
+
Requires-Dist: aiohttp
|
|
19
|
+
Dynamic: author
|
|
20
|
+
Dynamic: author-email
|
|
21
|
+
Dynamic: classifier
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: license
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: summary
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
setup.cfg
|
|
5
|
+
setup.py
|
|
6
|
+
dagster_omni/__init__.py
|
|
7
|
+
dagster_omni/component.py
|
|
8
|
+
dagster_omni/objects.py
|
|
9
|
+
dagster_omni/py.typed
|
|
10
|
+
dagster_omni/version.py
|
|
11
|
+
dagster_omni/workspace.py
|
|
12
|
+
dagster_omni.egg-info/PKG-INFO
|
|
13
|
+
dagster_omni.egg-info/SOURCES.txt
|
|
14
|
+
dagster_omni.egg-info/dependency_links.txt
|
|
15
|
+
dagster_omni.egg-info/not-zip-safe
|
|
16
|
+
dagster_omni.egg-info/requires.txt
|
|
17
|
+
dagster_omni.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dagster_omni
|
|
@@ -0,0 +1,41 @@
|
|
|
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_omni/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_omni",
|
|
19
|
+
version=get_version(),
|
|
20
|
+
author="Dagster Labs",
|
|
21
|
+
author_email="hello@dagsterlabs.com",
|
|
22
|
+
license="Apache-2.0",
|
|
23
|
+
description="Package for integrating Omni with Dagster.",
|
|
24
|
+
url=("https://github.com/dagster-io/dagster/tree/master/python_modules/libraries/dagster-omni"),
|
|
25
|
+
classifiers=[
|
|
26
|
+
"Programming Language :: Python :: 3.9",
|
|
27
|
+
"Programming Language :: Python :: 3.10",
|
|
28
|
+
"Programming Language :: Python :: 3.11",
|
|
29
|
+
"Programming Language :: Python :: 3.12",
|
|
30
|
+
"Programming Language :: Python :: 3.13",
|
|
31
|
+
"License :: OSI Approved :: Apache Software License",
|
|
32
|
+
"Operating System :: OS Independent",
|
|
33
|
+
],
|
|
34
|
+
packages=find_packages(exclude=["dagster_omni_tests*"]),
|
|
35
|
+
include_package_data=True,
|
|
36
|
+
install_requires=[
|
|
37
|
+
"dagster==1.11.9",
|
|
38
|
+
"aiohttp",
|
|
39
|
+
],
|
|
40
|
+
zip_safe=False,
|
|
41
|
+
)
|