prefect-client 2.16.8__py3-none-any.whl → 2.17.0__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 (89) hide show
  1. prefect/__init__.py +0 -18
  2. prefect/_internal/compatibility/deprecated.py +108 -5
  3. prefect/_internal/compatibility/experimental.py +9 -8
  4. prefect/_internal/concurrency/api.py +23 -42
  5. prefect/_internal/concurrency/waiters.py +25 -22
  6. prefect/_internal/pydantic/__init__.py +16 -3
  7. prefect/_internal/pydantic/_base_model.py +39 -4
  8. prefect/_internal/pydantic/_compat.py +69 -452
  9. prefect/_internal/pydantic/_flags.py +5 -0
  10. prefect/_internal/pydantic/_types.py +8 -0
  11. prefect/_internal/pydantic/utilities/__init__.py +0 -0
  12. prefect/_internal/pydantic/utilities/config_dict.py +72 -0
  13. prefect/_internal/pydantic/utilities/field_validator.py +135 -0
  14. prefect/_internal/pydantic/utilities/model_construct.py +56 -0
  15. prefect/_internal/pydantic/utilities/model_copy.py +55 -0
  16. prefect/_internal/pydantic/utilities/model_dump.py +136 -0
  17. prefect/_internal/pydantic/utilities/model_dump_json.py +112 -0
  18. prefect/_internal/pydantic/utilities/model_fields.py +50 -0
  19. prefect/_internal/pydantic/utilities/model_fields_set.py +29 -0
  20. prefect/_internal/pydantic/utilities/model_json_schema.py +82 -0
  21. prefect/_internal/pydantic/utilities/model_rebuild.py +80 -0
  22. prefect/_internal/pydantic/utilities/model_validate.py +75 -0
  23. prefect/_internal/pydantic/utilities/model_validate_json.py +68 -0
  24. prefect/_internal/pydantic/utilities/model_validator.py +79 -0
  25. prefect/_internal/pydantic/utilities/type_adapter.py +71 -0
  26. prefect/_internal/schemas/bases.py +1 -17
  27. prefect/_internal/schemas/validators.py +425 -4
  28. prefect/agent.py +1 -1
  29. prefect/blocks/kubernetes.py +7 -3
  30. prefect/blocks/notifications.py +18 -18
  31. prefect/blocks/webhook.py +1 -1
  32. prefect/client/base.py +7 -0
  33. prefect/client/cloud.py +1 -1
  34. prefect/client/orchestration.py +51 -11
  35. prefect/client/schemas/actions.py +367 -297
  36. prefect/client/schemas/filters.py +28 -28
  37. prefect/client/schemas/objects.py +78 -147
  38. prefect/client/schemas/responses.py +240 -60
  39. prefect/client/schemas/schedules.py +6 -8
  40. prefect/concurrency/events.py +2 -2
  41. prefect/context.py +4 -2
  42. prefect/deployments/base.py +6 -13
  43. prefect/deployments/deployments.py +34 -9
  44. prefect/deployments/runner.py +9 -27
  45. prefect/deprecated/packaging/base.py +5 -6
  46. prefect/deprecated/packaging/docker.py +19 -25
  47. prefect/deprecated/packaging/file.py +10 -5
  48. prefect/deprecated/packaging/orion.py +9 -4
  49. prefect/deprecated/packaging/serializers.py +8 -58
  50. prefect/engine.py +55 -618
  51. prefect/events/actions.py +16 -1
  52. prefect/events/clients.py +45 -13
  53. prefect/events/filters.py +19 -2
  54. prefect/events/related.py +4 -4
  55. prefect/events/schemas/automations.py +13 -2
  56. prefect/events/schemas/deployment_triggers.py +73 -5
  57. prefect/events/schemas/events.py +1 -1
  58. prefect/events/utilities.py +12 -4
  59. prefect/events/worker.py +26 -8
  60. prefect/exceptions.py +3 -8
  61. prefect/filesystems.py +7 -7
  62. prefect/flows.py +7 -3
  63. prefect/infrastructure/provisioners/ecs.py +1 -0
  64. prefect/logging/configuration.py +2 -2
  65. prefect/manifests.py +1 -8
  66. prefect/profiles.toml +1 -1
  67. prefect/pydantic/__init__.py +74 -2
  68. prefect/pydantic/main.py +26 -2
  69. prefect/serializers.py +6 -31
  70. prefect/settings.py +72 -26
  71. prefect/software/python.py +3 -5
  72. prefect/task_server.py +2 -2
  73. prefect/utilities/callables.py +1 -1
  74. prefect/utilities/collections.py +2 -1
  75. prefect/utilities/dispatch.py +1 -0
  76. prefect/utilities/engine.py +629 -0
  77. prefect/utilities/pydantic.py +1 -1
  78. prefect/utilities/schema_tools/validation.py +2 -2
  79. prefect/utilities/visualization.py +1 -1
  80. prefect/variables.py +88 -12
  81. prefect/workers/base.py +20 -11
  82. prefect/workers/block.py +4 -8
  83. prefect/workers/process.py +2 -5
  84. {prefect_client-2.16.8.dist-info → prefect_client-2.17.0.dist-info}/METADATA +4 -3
  85. {prefect_client-2.16.8.dist-info → prefect_client-2.17.0.dist-info}/RECORD +88 -72
  86. prefect/_internal/schemas/transformations.py +0 -106
  87. {prefect_client-2.16.8.dist-info → prefect_client-2.17.0.dist-info}/LICENSE +0 -0
  88. {prefect_client-2.16.8.dist-info → prefect_client-2.17.0.dist-info}/WHEEL +0 -0
  89. {prefect_client-2.16.8.dist-info → prefect_client-2.17.0.dist-info}/top_level.txt +0 -0
prefect/client/base.py CHANGED
@@ -27,6 +27,8 @@ from httpx import HTTPStatusError, Request, Response
27
27
  from prefect._vendor.starlette import status
28
28
  from typing_extensions import Self
29
29
 
30
+ import prefect
31
+ from prefect.client import constants
30
32
  from prefect.client.schemas.objects import CsrfToken
31
33
  from prefect.exceptions import PrefectHTTPStatusError
32
34
  from prefect.logging import get_logger
@@ -199,6 +201,11 @@ class PrefectHttpxClient(httpx.AsyncClient):
199
201
 
200
202
  super().__init__(*args, **kwargs)
201
203
 
204
+ user_agent = (
205
+ f"prefect/{prefect.__version__} (API {constants.SERVER_API_VERSION})"
206
+ )
207
+ self.headers["User-Agent"] = user_agent
208
+
202
209
  async def _send_with_retry(
203
210
  self,
204
211
  request: Request,
prefect/client/cloud.py CHANGED
@@ -63,7 +63,7 @@ class CloudClient:
63
63
  self,
64
64
  host: str,
65
65
  api_key: str,
66
- httpx_settings: dict = None,
66
+ httpx_settings: Optional[Dict[str, Any]] = None,
67
67
  ) -> None:
68
68
  httpx_settings = httpx_settings or dict()
69
69
  httpx_settings.setdefault("headers", dict())
@@ -20,6 +20,9 @@ import httpcore
20
20
  import httpx
21
21
  import pendulum
22
22
 
23
+ from prefect._internal.compatibility.deprecated import (
24
+ handle_deprecated_infra_overrides_parameter,
25
+ )
23
26
  from prefect._internal.compatibility.experimental import (
24
27
  EXPERIMENTAL_WARNING,
25
28
  ExperimentalFeature,
@@ -68,6 +71,8 @@ from prefect.client.schemas.actions import (
68
71
  LogCreate,
69
72
  TaskRunCreate,
70
73
  TaskRunUpdate,
74
+ VariableCreate,
75
+ VariableUpdate,
71
76
  WorkPoolCreate,
72
77
  WorkPoolUpdate,
73
78
  WorkQueueCreate,
@@ -216,7 +221,7 @@ class PrefectClient:
216
221
  *,
217
222
  api_key: str = None,
218
223
  api_version: str = None,
219
- httpx_settings: dict = None,
224
+ httpx_settings: Optional[Dict[str, Any]] = None,
220
225
  ) -> None:
221
226
  httpx_settings = httpx_settings.copy() if httpx_settings else {}
222
227
  httpx_settings.setdefault("headers", {})
@@ -523,8 +528,8 @@ class PrefectClient:
523
528
  self,
524
529
  deployment_id: UUID,
525
530
  *,
526
- parameters: Dict[str, Any] = None,
527
- context: dict = None,
531
+ parameters: Optional[Dict[str, Any]] = None,
532
+ context: Optional[Dict[str, Any]] = None,
528
533
  state: prefect.states.State = None,
529
534
  name: str = None,
530
535
  tags: Iterable[str] = None,
@@ -608,8 +613,8 @@ class PrefectClient:
608
613
  self,
609
614
  flow: "FlowObject",
610
615
  name: str = None,
611
- parameters: Dict[str, Any] = None,
612
- context: dict = None,
616
+ parameters: Optional[Dict[str, Any]] = None,
617
+ context: Optional[Dict[str, Any]] = None,
613
618
  tags: Iterable[str] = None,
614
619
  parent_task_run_id: UUID = None,
615
620
  state: "prefect.states.State" = None,
@@ -1578,7 +1583,7 @@ class PrefectClient:
1578
1583
  version: str = None,
1579
1584
  schedule: SCHEDULE_TYPES = None,
1580
1585
  schedules: List[DeploymentScheduleCreate] = None,
1581
- parameters: Dict[str, Any] = None,
1586
+ parameters: Optional[Dict[str, Any]] = None,
1582
1587
  description: str = None,
1583
1588
  work_queue_name: str = None,
1584
1589
  work_pool_name: str = None,
@@ -1588,12 +1593,13 @@ class PrefectClient:
1588
1593
  path: str = None,
1589
1594
  entrypoint: str = None,
1590
1595
  infrastructure_document_id: UUID = None,
1591
- infra_overrides: Dict[str, Any] = None,
1592
- parameter_openapi_schema: dict = None,
1596
+ infra_overrides: Optional[Dict[str, Any]] = None, # for backwards compat
1597
+ parameter_openapi_schema: Optional[Dict[str, Any]] = None,
1593
1598
  is_schedule_active: Optional[bool] = None,
1594
1599
  paused: Optional[bool] = None,
1595
1600
  pull_steps: Optional[List[dict]] = None,
1596
1601
  enforce_parameter_schema: Optional[bool] = None,
1602
+ job_variables: Optional[Dict[str, Any]] = None,
1597
1603
  ) -> UUID:
1598
1604
  """
1599
1605
  Create a deployment.
@@ -1608,6 +1614,10 @@ class PrefectClient:
1608
1614
  used for the deployed flow
1609
1615
  infrastructure_document_id: an reference to the infrastructure block document
1610
1616
  to use for this deployment
1617
+ job_variables: A dictionary of dot delimited infrastructure overrides that
1618
+ will be applied at runtime; for example `env.CONFIG_KEY=config_value` or
1619
+ `namespace='prefect'`. This argument was previously named `infra_overrides`.
1620
+ Both arguments are supported for backwards compatibility.
1611
1621
 
1612
1622
  Raises:
1613
1623
  httpx.RequestError: if the deployment was not created for any reason
@@ -1615,6 +1625,7 @@ class PrefectClient:
1615
1625
  Returns:
1616
1626
  the ID of the deployment in the backend
1617
1627
  """
1628
+ jv = handle_deprecated_infra_overrides_parameter(job_variables, infra_overrides)
1618
1629
 
1619
1630
  deployment_create = DeploymentCreate(
1620
1631
  flow_id=flow_id,
@@ -1629,7 +1640,7 @@ class PrefectClient:
1629
1640
  entrypoint=entrypoint,
1630
1641
  manifest_path=manifest_path, # for backwards compat
1631
1642
  infrastructure_document_id=infrastructure_document_id,
1632
- infra_overrides=infra_overrides or {},
1643
+ job_variables=jv,
1633
1644
  parameter_openapi_schema=parameter_openapi_schema,
1634
1645
  is_schedule_active=is_schedule_active,
1635
1646
  paused=paused,
@@ -1706,7 +1717,7 @@ class PrefectClient:
1706
1717
  parameters=deployment.parameters,
1707
1718
  storage_document_id=deployment.storage_document_id,
1708
1719
  infrastructure_document_id=deployment.infrastructure_document_id,
1709
- infra_overrides=deployment.infra_overrides,
1720
+ job_variables=deployment.job_variables,
1710
1721
  enforce_parameter_schema=deployment.enforce_parameter_schema,
1711
1722
  )
1712
1723
 
@@ -2926,11 +2937,40 @@ class PrefectClient:
2926
2937
  else:
2927
2938
  raise
2928
2939
 
2940
+ async def create_variable(self, variable: VariableCreate) -> Variable:
2941
+ """
2942
+ Creates an variable with the provided configuration.
2943
+
2944
+ Args:
2945
+ variable: Desired configuration for the new variable.
2946
+ Returns:
2947
+ Information about the newly created variable.
2948
+ """
2949
+ response = await self._client.post(
2950
+ "/variables/",
2951
+ json=variable.dict(json_compatible=True, exclude_unset=True),
2952
+ )
2953
+ return Variable(**response.json())
2954
+
2955
+ async def update_variable(self, variable: VariableUpdate) -> None:
2956
+ """
2957
+ Updates a variable with the provided configuration.
2958
+
2959
+ Args:
2960
+ variable: Desired configuration for the updated variable.
2961
+ Returns:
2962
+ Information about the updated variable.
2963
+ """
2964
+ await self._client.patch(
2965
+ f"/variables/name/{variable.name}",
2966
+ json=variable.dict(json_compatible=True, exclude_unset=True),
2967
+ )
2968
+
2929
2969
  async def read_variable_by_name(self, name: str) -> Optional[Variable]:
2930
2970
  """Reads a variable by name. Returns None if no variable is found."""
2931
2971
  try:
2932
2972
  response = await self._client.get(f"/variables/name/{name}")
2933
- return pydantic.parse_obj_as(Variable, response.json())
2973
+ return Variable(**response.json())
2934
2974
  except httpx.HTTPStatusError as e:
2935
2975
  if e.response.status_code == status.HTTP_404_NOT_FOUND:
2936
2976
  return None