prefect-client 3.1.4__py3-none-any.whl → 3.1.6__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.
Files changed (96) hide show
  1. prefect/__init__.py +3 -0
  2. prefect/_internal/compatibility/migration.py +1 -1
  3. prefect/_internal/concurrency/api.py +52 -52
  4. prefect/_internal/concurrency/calls.py +59 -35
  5. prefect/_internal/concurrency/cancellation.py +34 -18
  6. prefect/_internal/concurrency/event_loop.py +7 -6
  7. prefect/_internal/concurrency/threads.py +41 -33
  8. prefect/_internal/concurrency/waiters.py +28 -21
  9. prefect/_internal/pydantic/v1_schema.py +2 -2
  10. prefect/_internal/pydantic/v2_schema.py +10 -9
  11. prefect/_internal/schemas/bases.py +10 -11
  12. prefect/_internal/schemas/validators.py +2 -1
  13. prefect/_version.py +3 -3
  14. prefect/automations.py +53 -47
  15. prefect/blocks/abstract.py +12 -10
  16. prefect/blocks/core.py +4 -2
  17. prefect/cache_policies.py +11 -11
  18. prefect/client/__init__.py +3 -1
  19. prefect/client/base.py +36 -37
  20. prefect/client/cloud.py +26 -19
  21. prefect/client/collections.py +2 -2
  22. prefect/client/orchestration.py +366 -277
  23. prefect/client/schemas/__init__.py +24 -0
  24. prefect/client/schemas/actions.py +132 -120
  25. prefect/client/schemas/filters.py +5 -0
  26. prefect/client/schemas/objects.py +113 -85
  27. prefect/client/schemas/responses.py +21 -18
  28. prefect/client/schemas/schedules.py +136 -93
  29. prefect/client/subscriptions.py +28 -14
  30. prefect/client/utilities.py +32 -36
  31. prefect/concurrency/asyncio.py +6 -9
  32. prefect/concurrency/services.py +3 -0
  33. prefect/concurrency/sync.py +35 -5
  34. prefect/context.py +39 -31
  35. prefect/deployments/flow_runs.py +3 -5
  36. prefect/docker/__init__.py +1 -1
  37. prefect/events/schemas/events.py +25 -20
  38. prefect/events/utilities.py +1 -2
  39. prefect/filesystems.py +3 -3
  40. prefect/flow_engine.py +755 -138
  41. prefect/flow_runs.py +3 -3
  42. prefect/flows.py +214 -170
  43. prefect/logging/configuration.py +1 -1
  44. prefect/logging/highlighters.py +1 -2
  45. prefect/logging/loggers.py +30 -20
  46. prefect/main.py +17 -24
  47. prefect/runner/runner.py +43 -21
  48. prefect/runner/server.py +30 -32
  49. prefect/runner/submit.py +3 -6
  50. prefect/runner/utils.py +6 -6
  51. prefect/runtime/flow_run.py +7 -0
  52. prefect/settings/constants.py +2 -2
  53. prefect/settings/legacy.py +1 -1
  54. prefect/settings/models/server/events.py +10 -0
  55. prefect/settings/sources.py +9 -2
  56. prefect/task_engine.py +72 -19
  57. prefect/task_runners.py +2 -2
  58. prefect/tasks.py +46 -33
  59. prefect/telemetry/bootstrap.py +15 -2
  60. prefect/telemetry/run_telemetry.py +107 -0
  61. prefect/transactions.py +14 -14
  62. prefect/types/__init__.py +20 -3
  63. prefect/utilities/_engine.py +96 -0
  64. prefect/utilities/annotations.py +25 -18
  65. prefect/utilities/asyncutils.py +126 -140
  66. prefect/utilities/callables.py +87 -78
  67. prefect/utilities/collections.py +278 -117
  68. prefect/utilities/compat.py +13 -21
  69. prefect/utilities/context.py +6 -5
  70. prefect/utilities/dispatch.py +23 -12
  71. prefect/utilities/dockerutils.py +33 -32
  72. prefect/utilities/engine.py +126 -239
  73. prefect/utilities/filesystem.py +18 -15
  74. prefect/utilities/hashing.py +10 -11
  75. prefect/utilities/importtools.py +40 -27
  76. prefect/utilities/math.py +9 -5
  77. prefect/utilities/names.py +3 -3
  78. prefect/utilities/processutils.py +121 -57
  79. prefect/utilities/pydantic.py +41 -36
  80. prefect/utilities/render_swagger.py +22 -12
  81. prefect/utilities/schema_tools/__init__.py +2 -1
  82. prefect/utilities/schema_tools/hydration.py +50 -43
  83. prefect/utilities/schema_tools/validation.py +52 -42
  84. prefect/utilities/services.py +13 -12
  85. prefect/utilities/templating.py +45 -45
  86. prefect/utilities/text.py +2 -1
  87. prefect/utilities/timeout.py +4 -4
  88. prefect/utilities/urls.py +9 -4
  89. prefect/utilities/visualization.py +46 -24
  90. prefect/variables.py +9 -8
  91. prefect/workers/base.py +18 -10
  92. {prefect_client-3.1.4.dist-info → prefect_client-3.1.6.dist-info}/METADATA +5 -5
  93. {prefect_client-3.1.4.dist-info → prefect_client-3.1.6.dist-info}/RECORD +96 -94
  94. {prefect_client-3.1.4.dist-info → prefect_client-3.1.6.dist-info}/WHEEL +1 -1
  95. {prefect_client-3.1.4.dist-info → prefect_client-3.1.6.dist-info}/LICENSE +0 -0
  96. {prefect_client-3.1.4.dist-info → prefect_client-3.1.6.dist-info}/top_level.txt +0 -0
@@ -1,15 +1,16 @@
1
1
  import datetime
2
2
  import warnings
3
+ from collections.abc import Callable, Mapping
3
4
  from functools import partial
4
5
  from typing import (
5
6
  TYPE_CHECKING,
6
7
  Annotated,
7
8
  Any,
8
- Dict,
9
+ ClassVar,
9
10
  Generic,
10
- List,
11
11
  Optional,
12
12
  Union,
13
+ cast,
13
14
  overload,
14
15
  )
15
16
  from uuid import UUID, uuid4
@@ -23,13 +24,12 @@ from pydantic import (
23
24
  HttpUrl,
24
25
  IPvAnyNetwork,
25
26
  SerializationInfo,
27
+ SerializerFunctionWrapHandler,
26
28
  Tag,
27
29
  field_validator,
28
30
  model_serializer,
29
31
  model_validator,
30
32
  )
31
- from pydantic.functional_validators import ModelWrapValidatorHandler
32
- from pydantic_extra_types.pendulum_dt import DateTime
33
33
  from typing_extensions import Literal, Self, TypeVar
34
34
 
35
35
  from prefect._internal.compatibility import deprecated
@@ -53,7 +53,7 @@ from prefect.client.schemas.schedules import SCHEDULE_TYPES
53
53
  from prefect.settings import PREFECT_CLOUD_API_URL, PREFECT_CLOUD_UI_URL
54
54
  from prefect.types import (
55
55
  MAX_VARIABLE_NAME_LENGTH,
56
- KeyValueLabels,
56
+ KeyValueLabelsField,
57
57
  Name,
58
58
  NonNegativeInteger,
59
59
  PositiveInteger,
@@ -64,8 +64,13 @@ from prefect.utilities.names import generate_slug
64
64
  from prefect.utilities.pydantic import handle_secret_render
65
65
 
66
66
  if TYPE_CHECKING:
67
+ from prefect.client.schemas.actions import StateCreate
67
68
  from prefect.results import BaseResult, ResultRecordMetadata
68
69
 
70
+ DateTime = pendulum.DateTime
71
+ else:
72
+ from pydantic_extra_types.pendulum_dt import DateTime
73
+
69
74
 
70
75
  R = TypeVar("R", default=Any)
71
76
 
@@ -180,7 +185,7 @@ class StateDetails(PrefectBaseModel):
180
185
  pause_timeout: Optional[DateTime] = None
181
186
  pause_reschedule: bool = False
182
187
  pause_key: Optional[str] = None
183
- run_input_keyset: Optional[Dict[str, str]] = None
188
+ run_input_keyset: Optional[dict[str, str]] = None
184
189
  refresh_cache: Optional[bool] = None
185
190
  retriable: Optional[bool] = None
186
191
  transition_id: Optional[UUID] = None
@@ -215,11 +220,21 @@ class State(ObjectBaseModel, Generic[R]):
215
220
  ] = Field(default=None)
216
221
 
217
222
  @overload
218
- def result(self: "State[R]", raise_on_failure: bool = True) -> R:
223
+ def result(
224
+ self: "State[R]",
225
+ raise_on_failure: Literal[True] = ...,
226
+ fetch: bool = ...,
227
+ retry_result_failure: bool = ...,
228
+ ) -> R:
219
229
  ...
220
230
 
221
231
  @overload
222
- def result(self: "State[R]", raise_on_failure: bool = False) -> Union[R, Exception]:
232
+ def result(
233
+ self: "State[R]",
234
+ raise_on_failure: Literal[False] = False,
235
+ fetch: bool = ...,
236
+ retry_result_failure: bool = ...,
237
+ ) -> Union[R, Exception]:
223
238
  ...
224
239
 
225
240
  @deprecated.deprecated_parameter(
@@ -311,7 +326,7 @@ class State(ObjectBaseModel, Generic[R]):
311
326
  retry_result_failure=retry_result_failure,
312
327
  )
313
328
 
314
- def to_state_create(self):
329
+ def to_state_create(self) -> "StateCreate":
315
330
  """
316
331
  Convert this state to a `StateCreate` type which can be used to set the state of
317
332
  a run in the API.
@@ -327,7 +342,7 @@ class State(ObjectBaseModel, Generic[R]):
327
342
  )
328
343
 
329
344
  if isinstance(self.data, BaseResult):
330
- data = self.data
345
+ data = cast(BaseResult[R], self.data)
331
346
  elif isinstance(self.data, ResultRecord) and should_persist_result():
332
347
  data = self.data.metadata
333
348
  else:
@@ -348,14 +363,14 @@ class State(ObjectBaseModel, Generic[R]):
348
363
  # validation check and an error will be raised after this function is called
349
364
  name = self.name
350
365
  if name is None and self.type:
351
- self.name = " ".join([v.capitalize() for v in self.type.value.split("_")])
366
+ self.name = " ".join([v.capitalize() for v in self.type.split("_")])
352
367
  return self
353
368
 
354
369
  @model_validator(mode="after")
355
370
  def default_scheduled_start_time(self) -> Self:
356
371
  if self.type == StateType.SCHEDULED:
357
372
  if not self.state_details.scheduled_time:
358
- self.state_details.scheduled_time = DateTime.now("utc")
373
+ self.state_details.scheduled_time = pendulum.DateTime.now("utc")
359
374
  return self
360
375
 
361
376
  @model_validator(mode="after")
@@ -395,17 +410,19 @@ class State(ObjectBaseModel, Generic[R]):
395
410
  return self.type == StateType.PAUSED
396
411
 
397
412
  def model_copy(
398
- self, *, update: Optional[Dict[str, Any]] = None, deep: bool = False
399
- ):
413
+ self, *, update: Optional[Mapping[str, Any]] = None, deep: bool = False
414
+ ) -> Self:
400
415
  """
401
416
  Copying API models should return an object that could be inserted into the
402
417
  database again. The 'timestamp' is reset using the default factory.
403
418
  """
404
- update = update or {}
405
- update.setdefault("timestamp", self.model_fields["timestamp"].get_default())
419
+ update = {
420
+ "timestamp": self.model_fields["timestamp"].get_default(),
421
+ **(update or {}),
422
+ }
406
423
  return super().model_copy(update=update, deep=deep)
407
424
 
408
- def fresh_copy(self, **kwargs) -> Self:
425
+ def fresh_copy(self, **kwargs: Any) -> Self:
409
426
  """
410
427
  Return a fresh copy of the state with a new ID.
411
428
  """
@@ -443,12 +460,14 @@ class State(ObjectBaseModel, Generic[R]):
443
460
  `MyCompletedState("my message", type=COMPLETED)`
444
461
  """
445
462
 
446
- display = []
463
+ display: list[str] = []
447
464
 
448
465
  if self.message:
449
466
  display.append(repr(self.message))
450
467
 
451
- if self.type.value.lower() != self.name.lower():
468
+ if TYPE_CHECKING:
469
+ assert self.name is not None
470
+ if self.type.lower() != self.name.lower():
452
471
  display.append(f"type={self.type.value}")
453
472
 
454
473
  return f"{self.name}({', '.join(display)})"
@@ -487,7 +506,7 @@ class FlowRunPolicy(PrefectBaseModel):
487
506
  retry_delay: Optional[int] = Field(
488
507
  default=None, description="The delay time between retries, in seconds."
489
508
  )
490
- pause_keys: Optional[set] = Field(
509
+ pause_keys: Optional[set[str]] = Field(
491
510
  default_factory=set, description="Tracks pauses this run has observed."
492
511
  )
493
512
  resuming: Optional[bool] = Field(
@@ -499,7 +518,7 @@ class FlowRunPolicy(PrefectBaseModel):
499
518
 
500
519
  @model_validator(mode="before")
501
520
  @classmethod
502
- def populate_deprecated_fields(cls, values: Any):
521
+ def populate_deprecated_fields(cls, values: Any) -> Any:
503
522
  if isinstance(values, dict):
504
523
  return set_run_policy_deprecated_fields(values)
505
524
  return values
@@ -536,7 +555,7 @@ class FlowRun(ObjectBaseModel):
536
555
  description="The version of the flow executed in this flow run.",
537
556
  examples=["1.0"],
538
557
  )
539
- parameters: Dict[str, Any] = Field(
558
+ parameters: dict[str, Any] = Field(
540
559
  default_factory=dict, description="Parameters for the flow run."
541
560
  )
542
561
  idempotency_key: Optional[str] = Field(
@@ -546,7 +565,7 @@ class FlowRun(ObjectBaseModel):
546
565
  " run is not created multiple times."
547
566
  ),
548
567
  )
549
- context: Dict[str, Any] = Field(
568
+ context: dict[str, Any] = Field(
550
569
  default_factory=dict,
551
570
  description="Additional context for the flow run.",
552
571
  examples=[{"my_var": "my_val"}],
@@ -554,16 +573,12 @@ class FlowRun(ObjectBaseModel):
554
573
  empirical_policy: FlowRunPolicy = Field(
555
574
  default_factory=FlowRunPolicy,
556
575
  )
557
- tags: List[str] = Field(
576
+ tags: list[str] = Field(
558
577
  default_factory=list,
559
578
  description="A list of tags on the flow run",
560
579
  examples=[["tag-1", "tag-2"]],
561
580
  )
562
- labels: KeyValueLabels = Field(
563
- default_factory=dict,
564
- description="Prefect Cloud: A dictionary of key-value labels. Values can be strings, numbers, or booleans.",
565
- examples=[{"key": "value1", "key2": 42}],
566
- )
581
+ labels: KeyValueLabelsField = Field(default_factory=dict)
567
582
  parent_task_run_id: Optional[UUID] = Field(
568
583
  default=None,
569
584
  description=(
@@ -636,7 +651,7 @@ class FlowRun(ObjectBaseModel):
636
651
  description="The state of the flow run.",
637
652
  examples=["State(type=StateType.COMPLETED)"],
638
653
  )
639
- job_variables: Optional[dict] = Field(
654
+ job_variables: Optional[dict[str, Any]] = Field(
640
655
  default=None,
641
656
  description="Job variables for the flow run.",
642
657
  )
@@ -667,7 +682,7 @@ class FlowRun(ObjectBaseModel):
667
682
 
668
683
  @field_validator("name", mode="before")
669
684
  @classmethod
670
- def set_default_name(cls, name):
685
+ def set_default_name(cls, name: Optional[str]) -> str:
671
686
  return get_or_create_run_name(name)
672
687
 
673
688
 
@@ -691,7 +706,7 @@ class TaskRunPolicy(PrefectBaseModel):
691
706
  deprecated=True,
692
707
  )
693
708
  retries: Optional[int] = Field(default=None, description="The number of retries.")
694
- retry_delay: Union[None, int, List[int]] = Field(
709
+ retry_delay: Union[None, int, list[int]] = Field(
695
710
  default=None,
696
711
  description="A delay time or list of delay times between retries, in seconds.",
697
712
  )
@@ -714,18 +729,20 @@ class TaskRunPolicy(PrefectBaseModel):
714
729
  self.retries = self.max_retries
715
730
 
716
731
  if not self.retry_delay and self.retry_delay_seconds != 0:
717
- self.retry_delay = self.retry_delay_seconds
732
+ self.retry_delay = int(self.retry_delay_seconds)
718
733
 
719
734
  return self
720
735
 
721
736
  @field_validator("retry_delay")
722
737
  @classmethod
723
- def validate_configured_retry_delays(cls, v):
738
+ def validate_configured_retry_delays(
739
+ cls, v: Optional[list[float]]
740
+ ) -> Optional[list[float]]:
724
741
  return list_length_50_or_less(v)
725
742
 
726
743
  @field_validator("retry_jitter_factor")
727
744
  @classmethod
728
- def validate_jitter_factor(cls, v):
745
+ def validate_jitter_factor(cls, v: Optional[float]) -> Optional[float]:
729
746
  return validate_not_negative(v)
730
747
 
731
748
 
@@ -735,9 +752,11 @@ class TaskRunInput(PrefectBaseModel):
735
752
  could include, constants, parameters, or other task runs.
736
753
  """
737
754
 
738
- model_config = ConfigDict(frozen=True)
755
+ model_config: ClassVar[ConfigDict] = ConfigDict(frozen=True)
739
756
 
740
- input_type: str
757
+ if not TYPE_CHECKING:
758
+ # subclasses provide the concrete type for this field
759
+ input_type: str
741
760
 
742
761
 
743
762
  class TaskRunResult(TaskRunInput):
@@ -795,15 +814,16 @@ class TaskRun(ObjectBaseModel):
795
814
  empirical_policy: TaskRunPolicy = Field(
796
815
  default_factory=TaskRunPolicy,
797
816
  )
798
- tags: List[str] = Field(
817
+ tags: list[str] = Field(
799
818
  default_factory=list,
800
819
  description="A list of tags for the task run.",
801
820
  examples=[["tag-1", "tag-2"]],
802
821
  )
822
+ labels: KeyValueLabelsField = Field(default_factory=dict)
803
823
  state_id: Optional[UUID] = Field(
804
824
  default=None, description="The id of the current task run state."
805
825
  )
806
- task_inputs: Dict[str, List[Union[TaskRunResult, Parameter, Constant]]] = Field(
826
+ task_inputs: dict[str, list[Union[TaskRunResult, Parameter, Constant]]] = Field(
807
827
  default_factory=dict,
808
828
  description=(
809
829
  "Tracks the source of inputs to a task run. Used for internal bookkeeping. "
@@ -868,7 +888,7 @@ class TaskRun(ObjectBaseModel):
868
888
 
869
889
  @field_validator("name", mode="before")
870
890
  @classmethod
871
- def set_default_name(cls, name):
891
+ def set_default_name(cls, name: Optional[str]) -> Name:
872
892
  return get_or_create_run_name(name)
873
893
 
874
894
 
@@ -886,7 +906,7 @@ class Workspace(PrefectBaseModel):
886
906
  workspace_name: str = Field(..., description="The workspace name.")
887
907
  workspace_description: str = Field(..., description="Description of the workspace.")
888
908
  workspace_handle: str = Field(..., description="The workspace's unique handle.")
889
- model_config = ConfigDict(extra="ignore")
909
+ model_config: ClassVar[ConfigDict] = ConfigDict(extra="ignore")
890
910
 
891
911
  @property
892
912
  def handle(self) -> str:
@@ -915,7 +935,7 @@ class Workspace(PrefectBaseModel):
915
935
  f"/workspace/{self.workspace_id}"
916
936
  )
917
937
 
918
- def __hash__(self):
938
+ def __hash__(self) -> int:
919
939
  return hash(self.handle)
920
940
 
921
941
 
@@ -938,7 +958,7 @@ class IPAllowlist(PrefectBaseModel):
938
958
  Expected payload for an IP allowlist from the Prefect Cloud API.
939
959
  """
940
960
 
941
- entries: List[IPAllowlistEntry]
961
+ entries: list[IPAllowlistEntry]
942
962
 
943
963
 
944
964
  class IPAllowlistMyAccessResponse(PrefectBaseModel):
@@ -976,14 +996,14 @@ class BlockSchema(ObjectBaseModel):
976
996
  """A representation of a block schema."""
977
997
 
978
998
  checksum: str = Field(default=..., description="The block schema's unique checksum")
979
- fields: Dict[str, Any] = Field(
999
+ fields: dict[str, Any] = Field(
980
1000
  default_factory=dict, description="The block schema's field schema"
981
1001
  )
982
1002
  block_type_id: Optional[UUID] = Field(default=..., description="A block type ID")
983
1003
  block_type: Optional[BlockType] = Field(
984
1004
  default=None, description="The associated block type"
985
1005
  )
986
- capabilities: List[str] = Field(
1006
+ capabilities: list[str] = Field(
987
1007
  default_factory=list,
988
1008
  description="A list of Block capabilities",
989
1009
  )
@@ -1002,7 +1022,7 @@ class BlockDocument(ObjectBaseModel):
1002
1022
  "The block document's name. Not required for anonymous block documents."
1003
1023
  ),
1004
1024
  )
1005
- data: Dict[str, Any] = Field(
1025
+ data: dict[str, Any] = Field(
1006
1026
  default_factory=dict, description="The block document's data"
1007
1027
  )
1008
1028
  block_schema_id: UUID = Field(default=..., description="A block schema ID")
@@ -1014,7 +1034,7 @@ class BlockDocument(ObjectBaseModel):
1014
1034
  block_type: Optional[BlockType] = Field(
1015
1035
  default=None, description="The associated block type"
1016
1036
  )
1017
- block_document_references: Dict[str, Dict[str, Any]] = Field(
1037
+ block_document_references: dict[str, dict[str, Any]] = Field(
1018
1038
  default_factory=dict, description="Record of the block document's references"
1019
1039
  )
1020
1040
  is_anonymous: bool = Field(
@@ -1029,13 +1049,15 @@ class BlockDocument(ObjectBaseModel):
1029
1049
 
1030
1050
  @model_validator(mode="before")
1031
1051
  @classmethod
1032
- def validate_name_is_present_if_not_anonymous(cls, values):
1052
+ def validate_name_is_present_if_not_anonymous(
1053
+ cls, values: dict[str, Any]
1054
+ ) -> dict[str, Any]:
1033
1055
  return validate_name_present_on_nonanonymous_blocks(values)
1034
1056
 
1035
1057
  @model_serializer(mode="wrap")
1036
1058
  def serialize_data(
1037
- self, handler: ModelWrapValidatorHandler, info: SerializationInfo
1038
- ):
1059
+ self, handler: SerializerFunctionWrapHandler, info: SerializationInfo
1060
+ ) -> Any:
1039
1061
  self.data = visit_collection(
1040
1062
  self.data,
1041
1063
  visit_fn=partial(handle_secret_render, context=info.context or {}),
@@ -1050,11 +1072,12 @@ class Flow(ObjectBaseModel):
1050
1072
  name: Name = Field(
1051
1073
  default=..., description="The name of the flow", examples=["my-flow"]
1052
1074
  )
1053
- tags: List[str] = Field(
1075
+ tags: list[str] = Field(
1054
1076
  default_factory=list,
1055
1077
  description="A list of flow tags",
1056
1078
  examples=[["tag-1", "tag-2"]],
1057
1079
  )
1080
+ labels: KeyValueLabelsField
1058
1081
 
1059
1082
 
1060
1083
  class DeploymentSchedule(ObjectBaseModel):
@@ -1093,26 +1116,27 @@ class Deployment(ObjectBaseModel):
1093
1116
  concurrency_limit: Optional[int] = Field(
1094
1117
  default=None, description="The concurrency limit for the deployment."
1095
1118
  )
1096
- schedules: List[DeploymentSchedule] = Field(
1119
+ schedules: list[DeploymentSchedule] = Field(
1097
1120
  default_factory=list, description="A list of schedules for the deployment."
1098
1121
  )
1099
- job_variables: Dict[str, Any] = Field(
1122
+ job_variables: dict[str, Any] = Field(
1100
1123
  default_factory=dict,
1101
1124
  description="Overrides to apply to flow run infrastructure at runtime.",
1102
1125
  )
1103
- parameters: Dict[str, Any] = Field(
1126
+ parameters: dict[str, Any] = Field(
1104
1127
  default_factory=dict,
1105
1128
  description="Parameters for flow runs scheduled by the deployment.",
1106
1129
  )
1107
- pull_steps: Optional[List[dict]] = Field(
1130
+ pull_steps: Optional[list[dict[str, Any]]] = Field(
1108
1131
  default=None,
1109
1132
  description="Pull steps for cloning and running this deployment.",
1110
1133
  )
1111
- tags: List[str] = Field(
1134
+ tags: list[str] = Field(
1112
1135
  default_factory=list,
1113
1136
  description="A list of tags for the deployment",
1114
1137
  examples=[["tag-1", "tag-2"]],
1115
1138
  )
1139
+ labels: KeyValueLabelsField
1116
1140
  work_queue_name: Optional[str] = Field(
1117
1141
  default=None,
1118
1142
  description=(
@@ -1124,7 +1148,7 @@ class Deployment(ObjectBaseModel):
1124
1148
  default=None,
1125
1149
  description="The last time the deployment was polled for status updates.",
1126
1150
  )
1127
- parameter_openapi_schema: Optional[Dict[str, Any]] = Field(
1151
+ parameter_openapi_schema: Optional[dict[str, Any]] = Field(
1128
1152
  default=None,
1129
1153
  description="The parameter schema of the flow, including defaults.",
1130
1154
  )
@@ -1178,7 +1202,7 @@ class ConcurrencyLimit(ObjectBaseModel):
1178
1202
  default=..., description="A tag the concurrency limit is applied to."
1179
1203
  )
1180
1204
  concurrency_limit: int = Field(default=..., description="The concurrency limit.")
1181
- active_slots: List[UUID] = Field(
1205
+ active_slots: list[UUID] = Field(
1182
1206
  default_factory=list,
1183
1207
  description="A list of active run ids using a concurrency slot",
1184
1208
  )
@@ -1225,7 +1249,7 @@ class BlockDocumentReference(ObjectBaseModel):
1225
1249
 
1226
1250
  @model_validator(mode="before")
1227
1251
  @classmethod
1228
- def validate_parent_and_ref_are_different(cls, values):
1252
+ def validate_parent_and_ref_are_different(cls, values: Any) -> Any:
1229
1253
  if isinstance(values, dict):
1230
1254
  return validate_parent_and_ref_diff(values)
1231
1255
  return values
@@ -1235,7 +1259,7 @@ class Configuration(ObjectBaseModel):
1235
1259
  """An ORM representation of account info."""
1236
1260
 
1237
1261
  key: str = Field(default=..., description="Account info key")
1238
- value: Dict[str, Any] = Field(default=..., description="Account info")
1262
+ value: dict[str, Any] = Field(default=..., description="Account info")
1239
1263
 
1240
1264
 
1241
1265
  class SavedSearchFilter(PrefectBaseModel):
@@ -1259,7 +1283,7 @@ class SavedSearch(ObjectBaseModel):
1259
1283
  """An ORM representation of saved search data. Represents a set of filter criteria."""
1260
1284
 
1261
1285
  name: str = Field(default=..., description="The name of the saved search.")
1262
- filters: List[SavedSearchFilter] = Field(
1286
+ filters: list[SavedSearchFilter] = Field(
1263
1287
  default_factory=list, description="The filter set for the saved search."
1264
1288
  )
1265
1289
 
@@ -1282,11 +1306,11 @@ class Log(ObjectBaseModel):
1282
1306
  class QueueFilter(PrefectBaseModel):
1283
1307
  """Filter criteria definition for a work queue."""
1284
1308
 
1285
- tags: Optional[List[str]] = Field(
1309
+ tags: Optional[list[str]] = Field(
1286
1310
  default=None,
1287
1311
  description="Only include flow runs with these tags in the work queue.",
1288
1312
  )
1289
- deployment_ids: Optional[List[UUID]] = Field(
1313
+ deployment_ids: Optional[list[UUID]] = Field(
1290
1314
  default=None,
1291
1315
  description="Only include flow runs from these deployments in the work queue.",
1292
1316
  )
@@ -1346,7 +1370,7 @@ class WorkQueueHealthPolicy(PrefectBaseModel):
1346
1370
  )
1347
1371
 
1348
1372
  def evaluate_health_status(
1349
- self, late_runs_count: int, last_polled: Optional[DateTime] = None
1373
+ self, late_runs_count: int, last_polled: Optional[pendulum.DateTime] = None
1350
1374
  ) -> bool:
1351
1375
  """
1352
1376
  Given empirical information about the state of the work queue, evaluate its health status.
@@ -1398,10 +1422,10 @@ class FlowRunNotificationPolicy(ObjectBaseModel):
1398
1422
  is_active: bool = Field(
1399
1423
  default=True, description="Whether the policy is currently active"
1400
1424
  )
1401
- state_names: List[str] = Field(
1425
+ state_names: list[str] = Field(
1402
1426
  default=..., description="The flow run states that trigger notifications"
1403
1427
  )
1404
- tags: List[str] = Field(
1428
+ tags: list[str] = Field(
1405
1429
  default=...,
1406
1430
  description="The flow run tags that trigger notifications (set [] to disable)",
1407
1431
  )
@@ -1423,7 +1447,7 @@ class FlowRunNotificationPolicy(ObjectBaseModel):
1423
1447
 
1424
1448
  @field_validator("message_template")
1425
1449
  @classmethod
1426
- def validate_message_template_variables(cls, v):
1450
+ def validate_message_template_variables(cls, v: Optional[str]) -> Optional[str]:
1427
1451
  return validate_message_template_variables(v)
1428
1452
 
1429
1453
 
@@ -1455,7 +1479,7 @@ class WorkPool(ObjectBaseModel):
1455
1479
  default=None, description="A description of the work pool."
1456
1480
  )
1457
1481
  type: str = Field(description="The work pool type.")
1458
- base_job_template: Dict[str, Any] = Field(
1482
+ base_job_template: dict[str, Any] = Field(
1459
1483
  default_factory=dict, description="The work pool's base job template."
1460
1484
  )
1461
1485
  is_paused: bool = Field(
@@ -1470,10 +1494,12 @@ class WorkPool(ObjectBaseModel):
1470
1494
  )
1471
1495
 
1472
1496
  # this required field has a default of None so that the custom validator
1473
- # below will be called and produce a more helpful error message
1474
- default_queue_id: UUID = Field(
1475
- None, description="The id of the pool's default queue."
1476
- )
1497
+ # below will be called and produce a more helpful error message. Because
1498
+ # the field metadata is attached via an annotation, the default is hidden
1499
+ # from type checkers.
1500
+ default_queue_id: Annotated[
1501
+ UUID, Field(default=None, description="The id of the pool's default queue.")
1502
+ ]
1477
1503
 
1478
1504
  @property
1479
1505
  def is_push_pool(self) -> bool:
@@ -1485,7 +1511,7 @@ class WorkPool(ObjectBaseModel):
1485
1511
 
1486
1512
  @field_validator("default_queue_id")
1487
1513
  @classmethod
1488
- def helpful_error_for_missing_default_queue_id(cls, v):
1514
+ def helpful_error_for_missing_default_queue_id(cls, v: Optional[UUID]) -> UUID:
1489
1515
  return validate_default_queue_id_not_none(v)
1490
1516
 
1491
1517
 
@@ -1496,8 +1522,8 @@ class Worker(ObjectBaseModel):
1496
1522
  work_pool_id: UUID = Field(
1497
1523
  description="The work pool with which the queue is associated."
1498
1524
  )
1499
- last_heartbeat_time: datetime.datetime = Field(
1500
- None, description="The last time the worker process sent a heartbeat."
1525
+ last_heartbeat_time: Optional[datetime.datetime] = Field(
1526
+ default=None, description="The last time the worker process sent a heartbeat."
1501
1527
  )
1502
1528
  heartbeat_interval_seconds: Optional[int] = Field(
1503
1529
  default=None,
@@ -1530,14 +1556,14 @@ class Artifact(ObjectBaseModel):
1530
1556
  default=None, description="A markdown-enabled description of the artifact."
1531
1557
  )
1532
1558
  # data will eventually be typed as `Optional[Union[Result, Any]]`
1533
- data: Optional[Union[Dict[str, Any], Any]] = Field(
1559
+ data: Optional[Union[dict[str, Any], Any]] = Field(
1534
1560
  default=None,
1535
1561
  description=(
1536
1562
  "Data associated with the artifact, e.g. a result.; structure depends on"
1537
1563
  " the artifact type."
1538
1564
  ),
1539
1565
  )
1540
- metadata_: Optional[Dict[str, str]] = Field(
1566
+ metadata_: Optional[dict[str, str]] = Field(
1541
1567
  default=None,
1542
1568
  description=(
1543
1569
  "User-defined artifact metadata. Content must be string key and value"
@@ -1553,7 +1579,9 @@ class Artifact(ObjectBaseModel):
1553
1579
 
1554
1580
  @field_validator("metadata_")
1555
1581
  @classmethod
1556
- def validate_metadata_length(cls, v):
1582
+ def validate_metadata_length(
1583
+ cls, v: Optional[dict[str, str]]
1584
+ ) -> Optional[dict[str, str]]:
1557
1585
  return validate_max_metadata_length(v)
1558
1586
 
1559
1587
 
@@ -1572,14 +1600,14 @@ class ArtifactCollection(ObjectBaseModel):
1572
1600
  description: Optional[str] = Field(
1573
1601
  default=None, description="A markdown-enabled description of the artifact."
1574
1602
  )
1575
- data: Optional[Union[Dict[str, Any], Any]] = Field(
1603
+ data: Optional[Union[dict[str, Any], Any]] = Field(
1576
1604
  default=None,
1577
1605
  description=(
1578
1606
  "Data associated with the artifact, e.g. a result.; structure depends on"
1579
1607
  " the artifact type."
1580
1608
  ),
1581
1609
  )
1582
- metadata_: Optional[Dict[str, str]] = Field(
1610
+ metadata_: Optional[dict[str, str]] = Field(
1583
1611
  default=None,
1584
1612
  description=(
1585
1613
  "User-defined artifact metadata. Content must be string key and value"
@@ -1606,7 +1634,7 @@ class Variable(ObjectBaseModel):
1606
1634
  description="The value of the variable",
1607
1635
  examples=["my_value"],
1608
1636
  )
1609
- tags: List[str] = Field(
1637
+ tags: list[str] = Field(
1610
1638
  default_factory=list,
1611
1639
  description="A list of variable tags",
1612
1640
  examples=[["tag-1", "tag-2"]],
@@ -1631,7 +1659,7 @@ class FlowRunInput(ObjectBaseModel):
1631
1659
 
1632
1660
  @field_validator("key", check_fields=False)
1633
1661
  @classmethod
1634
- def validate_name_characters(cls, v):
1662
+ def validate_name_characters(cls, v: str) -> str:
1635
1663
  raise_on_name_alphanumeric_dashes_only(v)
1636
1664
  return v
1637
1665
 
@@ -1676,7 +1704,7 @@ class CsrfToken(ObjectBaseModel):
1676
1704
  )
1677
1705
 
1678
1706
 
1679
- __getattr__ = getattr_migration(__name__)
1707
+ __getattr__: Callable[[str], Any] = getattr_migration(__name__)
1680
1708
 
1681
1709
 
1682
1710
  class Integration(PrefectBaseModel):
@@ -1694,7 +1722,7 @@ class WorkerMetadata(PrefectBaseModel):
1694
1722
  should support flexible metadata.
1695
1723
  """
1696
1724
 
1697
- integrations: List[Integration] = Field(
1725
+ integrations: list[Integration] = Field(
1698
1726
  default=..., description="Prefect integrations installed in the worker."
1699
1727
  )
1700
- model_config = ConfigDict(extra="allow")
1728
+ model_config: ClassVar[ConfigDict] = ConfigDict(extra="allow")