prefect-client 3.1.13__py3-none-any.whl → 3.1.15__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.
- prefect/__main__.py +4 -0
- prefect/_experimental/lineage.py +92 -11
- prefect/_internal/concurrency/services.py +1 -1
- prefect/_version.py +3 -3
- prefect/artifacts.py +408 -105
- prefect/blocks/core.py +1 -1
- prefect/blocks/notifications.py +5 -0
- prefect/cache_policies.py +50 -2
- prefect/client/orchestration/_automations/client.py +4 -0
- prefect/client/orchestration/_deployments/client.py +3 -3
- prefect/client/schemas/actions.py +11 -1
- prefect/client/schemas/schedules.py +4 -4
- prefect/context.py +16 -6
- prefect/deployments/base.py +13 -16
- prefect/deployments/runner.py +117 -4
- prefect/events/clients.py +39 -0
- prefect/events/filters.py +34 -34
- prefect/flow_engine.py +274 -114
- prefect/flows.py +253 -10
- prefect/logging/configuration.py +2 -5
- prefect/logging/loggers.py +1 -2
- prefect/runner/runner.py +79 -58
- prefect/runtime/task_run.py +37 -9
- prefect/tasks.py +45 -7
- prefect/types/__init__.py +6 -5
- prefect/types/_datetime.py +19 -0
- prefect/utilities/render_swagger.py +1 -1
- prefect/utilities/templating.py +7 -0
- {prefect_client-3.1.13.dist-info → prefect_client-3.1.15.dist-info}/METADATA +1 -1
- {prefect_client-3.1.13.dist-info → prefect_client-3.1.15.dist-info}/RECORD +33 -31
- {prefect_client-3.1.13.dist-info → prefect_client-3.1.15.dist-info}/LICENSE +0 -0
- {prefect_client-3.1.13.dist-info → prefect_client-3.1.15.dist-info}/WHEEL +0 -0
- {prefect_client-3.1.13.dist-info → prefect_client-3.1.15.dist-info}/top_level.txt +0 -0
prefect/__main__.py
ADDED
prefect/_experimental/lineage.py
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Sequence, Union
|
2
2
|
|
3
|
+
from typing_extensions import TypeAlias
|
4
|
+
|
3
5
|
from prefect.events.related import related_resources_from_run_context
|
4
|
-
from prefect.events.schemas.events import RelatedResource
|
6
|
+
from prefect.events.schemas.events import RelatedResource
|
5
7
|
from prefect.events.utilities import emit_event
|
6
8
|
from prefect.settings import get_current_settings
|
7
9
|
|
8
10
|
if TYPE_CHECKING:
|
9
11
|
from prefect.results import ResultStore
|
10
12
|
|
11
|
-
|
12
|
-
DownstreamResources = Sequence[Union[Resource, dict[str, str]]]
|
13
|
+
LineageResources: TypeAlias = Sequence[Union[RelatedResource, dict[str, str]]]
|
13
14
|
|
14
15
|
# Map block types to their URI schemes
|
15
16
|
STORAGE_URI_SCHEMES = {
|
@@ -47,8 +48,8 @@ def get_result_resource_uri(
|
|
47
48
|
|
48
49
|
async def emit_lineage_event(
|
49
50
|
event_name: str,
|
50
|
-
upstream_resources: Optional[
|
51
|
-
downstream_resources: Optional[
|
51
|
+
upstream_resources: Optional[LineageResources] = None,
|
52
|
+
downstream_resources: Optional[LineageResources] = None,
|
52
53
|
direction_of_run_from_event: Literal["upstream", "downstream"] = "downstream",
|
53
54
|
) -> None:
|
54
55
|
"""Emit lineage events showing relationships between resources.
|
@@ -73,7 +74,14 @@ async def emit_lineage_event(
|
|
73
74
|
downstream_resources = list(downstream_resources) if downstream_resources else []
|
74
75
|
|
75
76
|
async with get_client() as client:
|
76
|
-
|
77
|
+
context_resources = await related_resources_from_run_context(client)
|
78
|
+
|
79
|
+
tag_resources = [
|
80
|
+
res for res in context_resources if res.get("prefect.resource.role") == "tag"
|
81
|
+
]
|
82
|
+
context_resources = [
|
83
|
+
res for res in context_resources if res.get("prefect.resource.role") != "tag"
|
84
|
+
]
|
77
85
|
|
78
86
|
# NOTE: We handle adding run-related resources to the event here instead of in
|
79
87
|
# the EventsWorker because not all run-related resources are upstream from
|
@@ -82,9 +90,9 @@ async def emit_lineage_event(
|
|
82
90
|
# lineage-related events, tracks upstream resources only. For downstream
|
83
91
|
# resources, we need to emit an event for each downstream resource.
|
84
92
|
if direction_of_run_from_event == "downstream":
|
85
|
-
downstream_resources.extend(
|
93
|
+
downstream_resources.extend(context_resources)
|
86
94
|
else:
|
87
|
-
upstream_resources.extend(
|
95
|
+
upstream_resources.extend(context_resources)
|
88
96
|
|
89
97
|
# We want to consider all resources upstream and downstream of the event as
|
90
98
|
# lineage-related, including flows, flow runs, etc., so we add the label to
|
@@ -101,7 +109,7 @@ async def emit_lineage_event(
|
|
101
109
|
emit_kwargs: Dict[str, Any] = {
|
102
110
|
"event": event_name,
|
103
111
|
"resource": resource,
|
104
|
-
"related": upstream_resources,
|
112
|
+
"related": upstream_resources + tag_resources,
|
105
113
|
}
|
106
114
|
|
107
115
|
emit_event(**emit_kwargs)
|
@@ -110,7 +118,7 @@ async def emit_lineage_event(
|
|
110
118
|
async def emit_result_read_event(
|
111
119
|
store: "ResultStore",
|
112
120
|
result_key: str,
|
113
|
-
downstream_resources: Optional[
|
121
|
+
downstream_resources: Optional[LineageResources] = None,
|
114
122
|
cached: bool = False,
|
115
123
|
) -> None:
|
116
124
|
"""
|
@@ -150,7 +158,7 @@ async def emit_result_read_event(
|
|
150
158
|
async def emit_result_write_event(
|
151
159
|
store: "ResultStore",
|
152
160
|
result_key: str,
|
153
|
-
upstream_resources: Optional[
|
161
|
+
upstream_resources: Optional[LineageResources] = None,
|
154
162
|
) -> None:
|
155
163
|
"""
|
156
164
|
Emit a lineage event showing a task or flow result was written.
|
@@ -178,3 +186,76 @@ async def emit_result_write_event(
|
|
178
186
|
downstream_resources=downstream_resources,
|
179
187
|
direction_of_run_from_event="upstream",
|
180
188
|
)
|
189
|
+
|
190
|
+
|
191
|
+
async def emit_external_resource_lineage(
|
192
|
+
event_name: str = "prefect.lineage.event",
|
193
|
+
upstream_resources: Optional[LineageResources] = None,
|
194
|
+
downstream_resources: Optional[LineageResources] = None,
|
195
|
+
context_resources: Optional[LineageResources] = None,
|
196
|
+
) -> None:
|
197
|
+
"""Emit lineage events connecting external resources to Prefect context resources.
|
198
|
+
|
199
|
+
This function emits events that place the current Prefect context resources
|
200
|
+
(like flow runs, task runs) as:
|
201
|
+
1. Downstream of any provided upstream external resources
|
202
|
+
2. Upstream of any provided downstream external resources
|
203
|
+
|
204
|
+
Args:
|
205
|
+
upstream_resources: Optional sequence of resources that are upstream of the
|
206
|
+
current Prefect context
|
207
|
+
downstream_resources: Optional sequence of resources that are downstream of
|
208
|
+
the current Prefect context
|
209
|
+
"""
|
210
|
+
from prefect.client.orchestration import get_client
|
211
|
+
|
212
|
+
if not get_current_settings().experiments.lineage_events_enabled:
|
213
|
+
return
|
214
|
+
|
215
|
+
upstream_resources = list(upstream_resources) if upstream_resources else []
|
216
|
+
downstream_resources = list(downstream_resources) if downstream_resources else []
|
217
|
+
|
218
|
+
# Get the current Prefect context resources (flow runs, task runs, etc.)
|
219
|
+
if not context_resources:
|
220
|
+
async with get_client() as client:
|
221
|
+
context_resources = await related_resources_from_run_context(client)
|
222
|
+
|
223
|
+
tag_resources = [
|
224
|
+
res for res in context_resources if res.get("prefect.resource.role") == "tag"
|
225
|
+
]
|
226
|
+
context_resources = [
|
227
|
+
res for res in context_resources if res.get("prefect.resource.role") != "tag"
|
228
|
+
]
|
229
|
+
|
230
|
+
# Add lineage group label to all resources
|
231
|
+
for res in upstream_resources + downstream_resources + context_resources:
|
232
|
+
if "prefect.resource.lineage-group" not in res:
|
233
|
+
res["prefect.resource.lineage-group"] = "global"
|
234
|
+
|
235
|
+
# For each context resource, emit an event showing it as downstream of upstream resources
|
236
|
+
if upstream_resources:
|
237
|
+
for context_resource in context_resources:
|
238
|
+
emit_kwargs: Dict[str, Any] = {
|
239
|
+
"event": "prefect.lineage.upstream-interaction",
|
240
|
+
"resource": context_resource,
|
241
|
+
"related": upstream_resources + tag_resources,
|
242
|
+
}
|
243
|
+
emit_event(**emit_kwargs)
|
244
|
+
|
245
|
+
# For each downstream resource, emit an event showing it as downstream of context resources
|
246
|
+
for downstream_resource in downstream_resources:
|
247
|
+
emit_kwargs: Dict[str, Any] = {
|
248
|
+
"event": "prefect.lineage.downstream-interaction",
|
249
|
+
"resource": downstream_resource,
|
250
|
+
"related": context_resources + tag_resources,
|
251
|
+
}
|
252
|
+
emit_event(**emit_kwargs)
|
253
|
+
|
254
|
+
# For each downstream resource, emit an event showing it as downstream of upstream resources
|
255
|
+
if upstream_resources:
|
256
|
+
direct_emit_kwargs = {
|
257
|
+
"event": event_name,
|
258
|
+
"resource": downstream_resource,
|
259
|
+
"related": upstream_resources + tag_resources,
|
260
|
+
}
|
261
|
+
emit_event(**direct_emit_kwargs)
|
@@ -65,7 +65,7 @@ class _QueueServiceBase(abc.ABC, Generic[T]):
|
|
65
65
|
# failure to process items. This is particularly relevant for services
|
66
66
|
# which use an httpx client. See related issue at
|
67
67
|
# https://github.com/python/cpython/issues/86813
|
68
|
-
threading._register_atexit(self._at_exit) # pyright: ignore[
|
68
|
+
threading._register_atexit(self._at_exit) # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue]
|
69
69
|
|
70
70
|
def _at_exit(self) -> None:
|
71
71
|
self.drain(at_exit=True)
|
prefect/_version.py
CHANGED
@@ -8,11 +8,11 @@ import json
|
|
8
8
|
|
9
9
|
version_json = '''
|
10
10
|
{
|
11
|
-
"date": "2025-01-
|
11
|
+
"date": "2025-01-30T11:31:29-0800",
|
12
12
|
"dirty": true,
|
13
13
|
"error": null,
|
14
|
-
"full-revisionid": "
|
15
|
-
"version": "3.1.
|
14
|
+
"full-revisionid": "3ac3d54885a6157989efd79cbfc0d681b4bb7e0c",
|
15
|
+
"version": "3.1.15"
|
16
16
|
}
|
17
17
|
''' # END VERSION_JSON
|
18
18
|
|