prefect-client 3.1.11__py3-none-any.whl → 3.1.13__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 (133) hide show
  1. prefect/_experimental/sla/__init__.py +0 -0
  2. prefect/_experimental/sla/client.py +92 -0
  3. prefect/_experimental/sla/objects.py +61 -0
  4. prefect/_internal/concurrency/services.py +2 -2
  5. prefect/_internal/concurrency/threads.py +6 -0
  6. prefect/_internal/retries.py +6 -3
  7. prefect/_internal/schemas/validators.py +6 -4
  8. prefect/_version.py +3 -3
  9. prefect/artifacts.py +4 -1
  10. prefect/automations.py +236 -30
  11. prefect/blocks/__init__.py +3 -3
  12. prefect/blocks/abstract.py +57 -31
  13. prefect/blocks/core.py +181 -82
  14. prefect/blocks/notifications.py +134 -73
  15. prefect/blocks/redis.py +13 -9
  16. prefect/blocks/system.py +24 -11
  17. prefect/blocks/webhook.py +7 -5
  18. prefect/cache_policies.py +23 -22
  19. prefect/client/orchestration/__init__.py +103 -2006
  20. prefect/client/orchestration/_automations/__init__.py +0 -0
  21. prefect/client/orchestration/_automations/client.py +329 -0
  22. prefect/client/orchestration/_blocks_documents/__init__.py +0 -0
  23. prefect/client/orchestration/_blocks_documents/client.py +334 -0
  24. prefect/client/orchestration/_blocks_schemas/__init__.py +0 -0
  25. prefect/client/orchestration/_blocks_schemas/client.py +200 -0
  26. prefect/client/orchestration/_blocks_types/__init__.py +0 -0
  27. prefect/client/orchestration/_blocks_types/client.py +380 -0
  28. prefect/client/orchestration/_deployments/__init__.py +0 -0
  29. prefect/client/orchestration/_deployments/client.py +1128 -0
  30. prefect/client/orchestration/_flow_runs/__init__.py +0 -0
  31. prefect/client/orchestration/_flow_runs/client.py +903 -0
  32. prefect/client/orchestration/_flows/__init__.py +0 -0
  33. prefect/client/orchestration/_flows/client.py +343 -0
  34. prefect/client/orchestration/_logs/client.py +16 -14
  35. prefect/client/schemas/__init__.py +68 -28
  36. prefect/client/schemas/objects.py +5 -5
  37. prefect/client/utilities.py +3 -3
  38. prefect/context.py +15 -1
  39. prefect/deployments/base.py +13 -4
  40. prefect/deployments/flow_runs.py +5 -1
  41. prefect/deployments/runner.py +37 -1
  42. prefect/deployments/steps/core.py +1 -1
  43. prefect/deployments/steps/pull.py +8 -3
  44. prefect/deployments/steps/utility.py +2 -2
  45. prefect/docker/docker_image.py +13 -9
  46. prefect/engine.py +33 -11
  47. prefect/events/cli/automations.py +4 -4
  48. prefect/events/clients.py +17 -14
  49. prefect/events/schemas/automations.py +12 -8
  50. prefect/events/schemas/events.py +5 -1
  51. prefect/events/worker.py +1 -1
  52. prefect/filesystems.py +7 -3
  53. prefect/flow_engine.py +64 -47
  54. prefect/flows.py +128 -74
  55. prefect/futures.py +14 -7
  56. prefect/infrastructure/provisioners/__init__.py +2 -0
  57. prefect/infrastructure/provisioners/cloud_run.py +4 -4
  58. prefect/infrastructure/provisioners/coiled.py +249 -0
  59. prefect/infrastructure/provisioners/container_instance.py +4 -3
  60. prefect/infrastructure/provisioners/ecs.py +55 -43
  61. prefect/infrastructure/provisioners/modal.py +5 -4
  62. prefect/input/actions.py +5 -1
  63. prefect/input/run_input.py +157 -43
  64. prefect/logging/configuration.py +3 -3
  65. prefect/logging/filters.py +2 -2
  66. prefect/logging/formatters.py +15 -11
  67. prefect/logging/handlers.py +24 -14
  68. prefect/logging/highlighters.py +5 -5
  69. prefect/logging/loggers.py +28 -18
  70. prefect/logging/logging.yml +1 -1
  71. prefect/main.py +3 -1
  72. prefect/results.py +166 -86
  73. prefect/runner/runner.py +38 -29
  74. prefect/runner/server.py +3 -1
  75. prefect/runner/storage.py +18 -18
  76. prefect/runner/submit.py +19 -12
  77. prefect/runtime/deployment.py +15 -8
  78. prefect/runtime/flow_run.py +19 -6
  79. prefect/runtime/task_run.py +7 -3
  80. prefect/settings/base.py +17 -7
  81. prefect/settings/legacy.py +4 -4
  82. prefect/settings/models/api.py +4 -3
  83. prefect/settings/models/cli.py +4 -3
  84. prefect/settings/models/client.py +7 -4
  85. prefect/settings/models/cloud.py +9 -3
  86. prefect/settings/models/deployments.py +4 -3
  87. prefect/settings/models/experiments.py +4 -8
  88. prefect/settings/models/flows.py +4 -3
  89. prefect/settings/models/internal.py +4 -3
  90. prefect/settings/models/logging.py +8 -6
  91. prefect/settings/models/results.py +4 -3
  92. prefect/settings/models/root.py +11 -16
  93. prefect/settings/models/runner.py +8 -5
  94. prefect/settings/models/server/api.py +6 -3
  95. prefect/settings/models/server/database.py +120 -25
  96. prefect/settings/models/server/deployments.py +4 -3
  97. prefect/settings/models/server/ephemeral.py +7 -4
  98. prefect/settings/models/server/events.py +6 -3
  99. prefect/settings/models/server/flow_run_graph.py +4 -3
  100. prefect/settings/models/server/root.py +4 -3
  101. prefect/settings/models/server/services.py +15 -12
  102. prefect/settings/models/server/tasks.py +7 -4
  103. prefect/settings/models/server/ui.py +4 -3
  104. prefect/settings/models/tasks.py +10 -5
  105. prefect/settings/models/testing.py +4 -3
  106. prefect/settings/models/worker.py +7 -4
  107. prefect/settings/profiles.py +13 -12
  108. prefect/settings/sources.py +20 -19
  109. prefect/states.py +74 -51
  110. prefect/task_engine.py +43 -33
  111. prefect/task_runners.py +85 -72
  112. prefect/task_runs.py +20 -11
  113. prefect/task_worker.py +14 -9
  114. prefect/tasks.py +36 -28
  115. prefect/telemetry/bootstrap.py +13 -9
  116. prefect/telemetry/run_telemetry.py +15 -13
  117. prefect/telemetry/services.py +4 -0
  118. prefect/transactions.py +3 -3
  119. prefect/types/__init__.py +3 -1
  120. prefect/utilities/_deprecated.py +38 -0
  121. prefect/utilities/engine.py +11 -4
  122. prefect/utilities/filesystem.py +2 -2
  123. prefect/utilities/generics.py +1 -1
  124. prefect/utilities/pydantic.py +21 -36
  125. prefect/utilities/templating.py +25 -1
  126. prefect/workers/base.py +58 -33
  127. prefect/workers/process.py +20 -15
  128. prefect/workers/server.py +4 -5
  129. {prefect_client-3.1.11.dist-info → prefect_client-3.1.13.dist-info}/METADATA +3 -3
  130. {prefect_client-3.1.11.dist-info → prefect_client-3.1.13.dist-info}/RECORD +133 -114
  131. {prefect_client-3.1.11.dist-info → prefect_client-3.1.13.dist-info}/LICENSE +0 -0
  132. {prefect_client-3.1.11.dist-info → prefect_client-3.1.13.dist-info}/WHEEL +0 -0
  133. {prefect_client-3.1.11.dist-info → prefect_client-3.1.13.dist-info}/top_level.txt +0 -0
@@ -28,11 +28,11 @@ class Setting:
28
28
  self.accessor: str = accessor
29
29
 
30
30
  @property
31
- def name(self):
31
+ def name(self) -> str:
32
32
  return self._name
33
33
 
34
34
  @property
35
- def is_secret(self):
35
+ def is_secret(self) -> bool:
36
36
  if self._type in _SECRET_TYPES:
37
37
  return True
38
38
  for secret_type in _SECRET_TYPES:
@@ -40,7 +40,7 @@ class Setting:
40
40
  return True
41
41
  return False
42
42
 
43
- def default(self):
43
+ def default(self) -> Any:
44
44
  return self._default
45
45
 
46
46
  def value(self: Self) -> Any:
@@ -123,7 +123,7 @@ def _get_settings_fields(
123
123
  settings: Type[BaseSettings], accessor_prefix: Optional[str] = None
124
124
  ) -> Dict[str, "Setting"]:
125
125
  """Get the settings fields for the settings object"""
126
- settings_fields: Dict[str, Setting] = {}
126
+ settings_fields: dict[str, Setting] = {}
127
127
  for field_name, field in settings.model_fields.items():
128
128
  if inspect.isclass(field.annotation) and issubclass(
129
129
  field.annotation, PrefectBaseSettings
@@ -1,11 +1,12 @@
1
1
  import os
2
2
  from typing import ClassVar, Optional
3
3
 
4
- from pydantic import ConfigDict, Field, SecretStr
4
+ from pydantic import Field, SecretStr
5
+ from pydantic_settings import SettingsConfigDict
5
6
 
6
7
  from prefect.settings.base import (
7
8
  PrefectBaseSettings,
8
- _build_settings_config,
9
+ build_settings_config,
9
10
  )
10
11
 
11
12
 
@@ -14,7 +15,7 @@ class APISettings(PrefectBaseSettings):
14
15
  Settings for interacting with the Prefect API
15
16
  """
16
17
 
17
- model_config: ClassVar[ConfigDict] = _build_settings_config(("api",))
18
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(("api",))
18
19
  url: Optional[str] = Field(
19
20
  default=None,
20
21
  description="The URL of the Prefect API. If not set, the client will attempt to infer it.",
@@ -1,10 +1,11 @@
1
1
  from typing import ClassVar, Optional
2
2
 
3
- from pydantic import ConfigDict, Field
3
+ from pydantic import Field
4
+ from pydantic_settings import SettingsConfigDict
4
5
 
5
6
  from prefect.settings.base import (
6
7
  PrefectBaseSettings,
7
- _build_settings_config,
8
+ build_settings_config,
8
9
  )
9
10
 
10
11
 
@@ -13,7 +14,7 @@ class CLISettings(PrefectBaseSettings):
13
14
  Settings for controlling CLI behavior
14
15
  """
15
16
 
16
- model_config: ClassVar[ConfigDict] = _build_settings_config(("cli",))
17
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(("cli",))
17
18
 
18
19
  colors: bool = Field(
19
20
  default=True,
@@ -1,10 +1,11 @@
1
1
  from typing import ClassVar
2
2
 
3
- from pydantic import AliasChoices, AliasPath, ConfigDict, Field
3
+ from pydantic import AliasChoices, AliasPath, Field
4
+ from pydantic_settings import SettingsConfigDict
4
5
 
5
6
  from prefect.settings.base import (
6
7
  PrefectBaseSettings,
7
- _build_settings_config,
8
+ build_settings_config,
8
9
  )
9
10
  from prefect.types import ClientRetryExtraCodes
10
11
 
@@ -14,7 +15,9 @@ class ClientMetricsSettings(PrefectBaseSettings):
14
15
  Settings for controlling metrics reporting from the client
15
16
  """
16
17
 
17
- model_config: ClassVar[ConfigDict] = _build_settings_config(("client", "metrics"))
18
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(
19
+ ("client", "metrics")
20
+ )
18
21
 
19
22
  enabled: bool = Field(
20
23
  default=False,
@@ -39,7 +42,7 @@ class ClientSettings(PrefectBaseSettings):
39
42
  Settings for controlling API client behavior
40
43
  """
41
44
 
42
- model_config: ClassVar[ConfigDict] = _build_settings_config(("client",))
45
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(("client",))
43
46
 
44
47
  max_retries: int = Field(
45
48
  default=5,
@@ -1,12 +1,13 @@
1
1
  import re
2
2
  from typing import ClassVar, Optional
3
3
 
4
- from pydantic import ConfigDict, Field, model_validator
4
+ from pydantic import Field, model_validator
5
+ from pydantic_settings import SettingsConfigDict
5
6
  from typing_extensions import Self
6
7
 
7
8
  from prefect.settings.base import (
8
9
  PrefectBaseSettings,
9
- _build_settings_config,
10
+ build_settings_config,
10
11
  )
11
12
 
12
13
 
@@ -32,13 +33,18 @@ class CloudSettings(PrefectBaseSettings):
32
33
  Settings for interacting with Prefect Cloud
33
34
  """
34
35
 
35
- model_config: ClassVar[ConfigDict] = _build_settings_config(("cloud",))
36
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(("cloud",))
36
37
 
37
38
  api_url: str = Field(
38
39
  default="https://api.prefect.cloud/api",
39
40
  description="API URL for Prefect Cloud. Used for authentication with Prefect Cloud.",
40
41
  )
41
42
 
43
+ enable_orchestration_telemetry: bool = Field(
44
+ default=True,
45
+ description="Whether or not to enable orchestration telemetry.",
46
+ )
47
+
42
48
  ui_url: Optional[str] = Field(
43
49
  default=None,
44
50
  description="The URL of the Prefect Cloud UI. If not set, the client will attempt to infer it.",
@@ -1,8 +1,9 @@
1
1
  from typing import ClassVar, Optional
2
2
 
3
- from pydantic import AliasChoices, AliasPath, ConfigDict, Field
3
+ from pydantic import AliasChoices, AliasPath, Field
4
+ from pydantic_settings import SettingsConfigDict
4
5
 
5
- from prefect.settings.base import PrefectBaseSettings, _build_settings_config
6
+ from prefect.settings.base import PrefectBaseSettings, build_settings_config
6
7
 
7
8
 
8
9
  class DeploymentsSettings(PrefectBaseSettings):
@@ -10,7 +11,7 @@ class DeploymentsSettings(PrefectBaseSettings):
10
11
  Settings for configuring deployments defaults
11
12
  """
12
13
 
13
- model_config: ClassVar[ConfigDict] = _build_settings_config(("deployments",))
14
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(("deployments",))
14
15
 
15
16
  default_work_pool_name: Optional[str] = Field(
16
17
  default=None,
@@ -1,8 +1,9 @@
1
1
  from typing import ClassVar
2
2
 
3
- from pydantic import AliasChoices, AliasPath, ConfigDict, Field
3
+ from pydantic import AliasChoices, AliasPath, Field
4
+ from pydantic_settings import SettingsConfigDict
4
5
 
5
- from prefect.settings.base import PrefectBaseSettings, _build_settings_config
6
+ from prefect.settings.base import PrefectBaseSettings, build_settings_config
6
7
 
7
8
 
8
9
  class ExperimentsSettings(PrefectBaseSettings):
@@ -10,7 +11,7 @@ class ExperimentsSettings(PrefectBaseSettings):
10
11
  Settings for configuring experimental features
11
12
  """
12
13
 
13
- model_config: ClassVar[ConfigDict] = _build_settings_config(("experiments",))
14
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(("experiments",))
14
15
 
15
16
  warn: bool = Field(
16
17
  default=True,
@@ -20,11 +21,6 @@ class ExperimentsSettings(PrefectBaseSettings):
20
21
  ),
21
22
  )
22
23
 
23
- telemetry_enabled: bool = Field(
24
- default=False,
25
- description="Enables sending telemetry to Prefect Cloud.",
26
- )
27
-
28
24
  lineage_events_enabled: bool = Field(
29
25
  default=False,
30
26
  description="If `True`, enables emitting lineage events. Set to `False` to disable lineage event emission.",
@@ -1,8 +1,9 @@
1
1
  from typing import ClassVar, Union
2
2
 
3
- from pydantic import AliasChoices, AliasPath, ConfigDict, Field
3
+ from pydantic import AliasChoices, AliasPath, Field
4
+ from pydantic_settings import SettingsConfigDict
4
5
 
5
- from prefect.settings.base import PrefectBaseSettings, _build_settings_config
6
+ from prefect.settings.base import PrefectBaseSettings, build_settings_config
6
7
 
7
8
 
8
9
  class FlowsSettings(PrefectBaseSettings):
@@ -10,7 +11,7 @@ class FlowsSettings(PrefectBaseSettings):
10
11
  Settings for controlling flow behavior
11
12
  """
12
13
 
13
- model_config: ClassVar[ConfigDict] = _build_settings_config(("flows",))
14
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(("flows",))
14
15
 
15
16
  default_retries: int = Field(
16
17
  default=0,
@@ -1,13 +1,14 @@
1
1
  from typing import ClassVar
2
2
 
3
- from pydantic import AliasChoices, AliasPath, ConfigDict, Field
3
+ from pydantic import AliasChoices, AliasPath, Field
4
+ from pydantic_settings import SettingsConfigDict
4
5
 
5
- from prefect.settings.base import PrefectBaseSettings, _build_settings_config
6
+ from prefect.settings.base import PrefectBaseSettings, build_settings_config
6
7
  from prefect.types import LogLevel
7
8
 
8
9
 
9
10
  class InternalSettings(PrefectBaseSettings):
10
- model_config: ClassVar[ConfigDict] = _build_settings_config(("internal",))
11
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(("internal",))
11
12
 
12
13
  logging_level: LogLevel = Field(
13
14
  default="ERROR",
@@ -1,22 +1,22 @@
1
1
  from functools import partial
2
2
  from pathlib import Path
3
- from typing import Annotated, ClassVar, Literal, Optional, Union
3
+ from typing import Annotated, Any, ClassVar, Literal, Optional, Union
4
4
 
5
5
  from pydantic import (
6
6
  AliasChoices,
7
7
  AliasPath,
8
8
  BeforeValidator,
9
- ConfigDict,
10
9
  Field,
11
10
  model_validator,
12
11
  )
12
+ from pydantic_settings import SettingsConfigDict
13
13
  from typing_extensions import Self
14
14
 
15
- from prefect.settings.base import PrefectBaseSettings, _build_settings_config
15
+ from prefect.settings.base import PrefectBaseSettings, build_settings_config
16
16
  from prefect.types import LogLevel, validate_set_T_from_delim_string
17
17
 
18
18
 
19
- def max_log_size_smaller_than_batch_size(values):
19
+ def max_log_size_smaller_than_batch_size(values: dict[str, Any]) -> dict[str, Any]:
20
20
  """
21
21
  Validator for settings asserting the batch size and match log size are compatible
22
22
  """
@@ -33,7 +33,9 @@ class LoggingToAPISettings(PrefectBaseSettings):
33
33
  Settings for controlling logging to the API
34
34
  """
35
35
 
36
- model_config: ClassVar[ConfigDict] = _build_settings_config(("logging", "to_api"))
36
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(
37
+ ("logging", "to_api")
38
+ )
37
39
 
38
40
  enabled: bool = Field(
39
41
  default=True,
@@ -86,7 +88,7 @@ class LoggingSettings(PrefectBaseSettings):
86
88
  Settings for controlling logging behavior
87
89
  """
88
90
 
89
- model_config: ClassVar[ConfigDict] = _build_settings_config(("logging",))
91
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(("logging",))
90
92
 
91
93
  level: LogLevel = Field(
92
94
  default="INFO",
@@ -1,9 +1,10 @@
1
1
  from pathlib import Path
2
2
  from typing import ClassVar, Optional
3
3
 
4
- from pydantic import AliasChoices, AliasPath, ConfigDict, Field
4
+ from pydantic import AliasChoices, AliasPath, Field
5
+ from pydantic_settings import SettingsConfigDict
5
6
 
6
- from prefect.settings.base import PrefectBaseSettings, _build_settings_config
7
+ from prefect.settings.base import PrefectBaseSettings, build_settings_config
7
8
 
8
9
 
9
10
  class ResultsSettings(PrefectBaseSettings):
@@ -11,7 +12,7 @@ class ResultsSettings(PrefectBaseSettings):
11
12
  Settings for controlling result storage behavior
12
13
  """
13
14
 
14
- model_config: ClassVar[ConfigDict] = _build_settings_config(("results",))
15
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(("results",))
15
16
 
16
17
  default_serializer: str = Field(
17
18
  default="pickle",
@@ -11,10 +11,11 @@ from typing import (
11
11
  )
12
12
  from urllib.parse import urlparse
13
13
 
14
- from pydantic import BeforeValidator, ConfigDict, Field, SecretStr, model_validator
14
+ from pydantic import BeforeValidator, Field, SecretStr, model_validator
15
+ from pydantic_settings import SettingsConfigDict
15
16
  from typing_extensions import Self
16
17
 
17
- from prefect.settings.base import PrefectBaseSettings, _build_settings_config
18
+ from prefect.settings.base import PrefectBaseSettings, build_settings_config
18
19
  from prefect.settings.models.tasks import TasksSettings
19
20
  from prefect.settings.models.testing import TestingSettings
20
21
  from prefect.settings.models.worker import WorkerSettings
@@ -44,7 +45,7 @@ class Settings(PrefectBaseSettings):
44
45
  See https://docs.pydantic.dev/latest/concepts/pydantic_settings
45
46
  """
46
47
 
47
- model_config: ClassVar[ConfigDict] = _build_settings_config()
48
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config()
48
49
 
49
50
  home: Annotated[Path, BeforeValidator(lambda x: Path(x).expanduser())] = Field(
50
51
  default=Path("~") / ".prefect",
@@ -214,11 +215,7 @@ class Settings(PrefectBaseSettings):
214
215
  if self.server.database.connection_url is None:
215
216
  self.server.database.connection_url = _default_database_connection_url(self)
216
217
  self.server.database.__pydantic_fields_set__.remove("connection_url")
217
- db_url = (
218
- self.server.database.connection_url.get_secret_value()
219
- if isinstance(self.server.database.connection_url, SecretStr)
220
- else self.server.database.connection_url
221
- )
218
+ db_url = self.server.database.connection_url.get_secret_value()
222
219
  if (
223
220
  "PREFECT_API_DATABASE_PASSWORD" in db_url
224
221
  or "PREFECT_SERVER_DATABASE_PASSWORD" in db_url
@@ -275,7 +272,7 @@ class Settings(PrefectBaseSettings):
275
272
  # To restore defaults, we need to resolve the setting path and then
276
273
  # set the default value on the new settings object. When restoring
277
274
  # defaults, all settings sources will be ignored.
278
- restore_defaults_obj = {}
275
+ restore_defaults_obj: dict[str, Any] = {}
279
276
  for r in restore_defaults or []:
280
277
  path = r.accessor.split(".")
281
278
  model = self
@@ -301,11 +298,11 @@ class Settings(PrefectBaseSettings):
301
298
  updates = updates or {}
302
299
  set_defaults = set_defaults or {}
303
300
 
304
- set_defaults_obj = {}
301
+ set_defaults_obj: dict[str, Any] = {}
305
302
  for setting, value in set_defaults.items():
306
303
  set_in_dict(set_defaults_obj, setting.accessor, value)
307
304
 
308
- updates_obj = {}
305
+ updates_obj: dict[str, Any] = {}
309
306
  for setting, value in updates.items():
310
307
  set_in_dict(updates_obj, setting.accessor, value)
311
308
 
@@ -377,7 +374,7 @@ def _warn_on_misconfigured_api_url(settings: "Settings"):
377
374
  "`PREFECT_API_URL` uses `/workspace/` but should use `/workspaces/`."
378
375
  ),
379
376
  }
380
- warnings_list = []
377
+ warnings_list: list[str] = []
381
378
 
382
379
  for misconfig, warning in misconfigured_mappings.items():
383
380
  if misconfig in api_url:
@@ -399,7 +396,7 @@ def _warn_on_misconfigured_api_url(settings: "Settings"):
399
396
 
400
397
 
401
398
  def _default_database_connection_url(settings: "Settings") -> SecretStr:
402
- value = None
399
+ value: str = f"sqlite+aiosqlite:///{settings.home}/prefect.db"
403
400
  if settings.server.database.driver == "postgresql+asyncpg":
404
401
  required = [
405
402
  "host",
@@ -417,7 +414,7 @@ def _default_database_connection_url(settings: "Settings") -> SecretStr:
417
414
 
418
415
  from sqlalchemy import URL
419
416
 
420
- return URL(
417
+ value = URL(
421
418
  drivername=settings.server.database.driver,
422
419
  host=settings.server.database.host,
423
420
  port=settings.server.database.port or 5432,
@@ -443,6 +440,4 @@ def _default_database_connection_url(settings: "Settings") -> SecretStr:
443
440
  raise ValueError(
444
441
  f"Unsupported database driver: {settings.server.database.driver}"
445
442
  )
446
-
447
- value = value if value else f"sqlite+aiosqlite:///{settings.home}/prefect.db"
448
443
  return SecretStr(value)
@@ -1,8 +1,9 @@
1
1
  from typing import ClassVar, Optional
2
2
 
3
- from pydantic import ConfigDict, Field
3
+ from pydantic import Field
4
+ from pydantic_settings import SettingsConfigDict
4
5
 
5
- from prefect.settings.base import PrefectBaseSettings, _build_settings_config
6
+ from prefect.settings.base import PrefectBaseSettings, build_settings_config
6
7
  from prefect.types import LogLevel
7
8
 
8
9
 
@@ -11,7 +12,9 @@ class RunnerServerSettings(PrefectBaseSettings):
11
12
  Settings for controlling runner server behavior
12
13
  """
13
14
 
14
- model_config: ClassVar[ConfigDict] = _build_settings_config(("runner", "server"))
15
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(
16
+ ("runner", "server")
17
+ )
15
18
 
16
19
  enable: bool = Field(
17
20
  default=False,
@@ -29,7 +32,7 @@ class RunnerServerSettings(PrefectBaseSettings):
29
32
  )
30
33
 
31
34
  log_level: LogLevel = Field(
32
- default="error",
35
+ default="ERROR",
33
36
  description="The log level of the runner's webserver.",
34
37
  )
35
38
 
@@ -44,7 +47,7 @@ class RunnerSettings(PrefectBaseSettings):
44
47
  Settings for controlling runner behavior
45
48
  """
46
49
 
47
- model_config: ClassVar[ConfigDict] = _build_settings_config(("runner",))
50
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(("runner",))
48
51
 
49
52
  process_limit: int = Field(
50
53
  default=5,
@@ -1,9 +1,10 @@
1
1
  from datetime import timedelta
2
2
  from typing import ClassVar, Optional
3
3
 
4
- from pydantic import AliasChoices, AliasPath, ConfigDict, Field, SecretStr
4
+ from pydantic import AliasChoices, AliasPath, Field, SecretStr
5
+ from pydantic_settings import SettingsConfigDict
5
6
 
6
- from prefect.settings.base import PrefectBaseSettings, _build_settings_config
7
+ from prefect.settings.base import PrefectBaseSettings, build_settings_config
7
8
 
8
9
 
9
10
  class ServerAPISettings(PrefectBaseSettings):
@@ -11,7 +12,9 @@ class ServerAPISettings(PrefectBaseSettings):
11
12
  Settings for controlling API server behavior
12
13
  """
13
14
 
14
- model_config: ClassVar[ConfigDict] = _build_settings_config(("server", "api"))
15
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(
16
+ ("server", "api")
17
+ )
15
18
 
16
19
  auth_string: Optional[SecretStr] = Field(
17
20
  default=None,
@@ -1,18 +1,80 @@
1
1
  import warnings
2
- from typing import ClassVar, Optional
2
+ from typing import Any, ClassVar, Optional
3
3
  from urllib.parse import quote_plus
4
4
 
5
5
  from pydantic import (
6
6
  AliasChoices,
7
7
  AliasPath,
8
- ConfigDict,
9
8
  Field,
10
9
  SecretStr,
11
10
  model_validator,
12
11
  )
12
+ from pydantic_settings import SettingsConfigDict
13
13
  from typing_extensions import Literal, Self
14
14
 
15
- from prefect.settings.base import PrefectBaseSettings, _build_settings_config
15
+ from prefect.settings.base import PrefectBaseSettings, build_settings_config
16
+
17
+
18
+ class SQLAlchemyConnectArgsSettings(PrefectBaseSettings):
19
+ """
20
+ Settings for controlling SQLAlchemy connection behavior; note that these settings only take effect when
21
+ using a PostgreSQL database.
22
+ """
23
+
24
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(
25
+ ("server", "database", "sqlalchemy", "connect_args")
26
+ )
27
+
28
+ application_name: Optional[str] = Field(
29
+ default=None,
30
+ description="Controls the application_name field for connections opened from the connection pool when using a PostgreSQL database with the Prefect backend.",
31
+ )
32
+
33
+
34
+ class SQLAlchemySettings(PrefectBaseSettings):
35
+ """
36
+ Settings for controlling SQLAlchemy behavior; note that these settings only take effect when
37
+ using a PostgreSQL database.
38
+ """
39
+
40
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(
41
+ ("server", "database", "sqlalchemy")
42
+ )
43
+
44
+ connect_args: SQLAlchemyConnectArgsSettings = Field(
45
+ default_factory=SQLAlchemyConnectArgsSettings,
46
+ description="Settings for controlling SQLAlchemy connection behavior",
47
+ )
48
+
49
+ pool_size: int = Field(
50
+ default=5,
51
+ description="Controls connection pool size of database connection pools from the Prefect backend.",
52
+ validation_alias=AliasChoices(
53
+ AliasPath("pool_size"),
54
+ "prefect_server_database_sqlalchemy_pool_size",
55
+ "prefect_sqlalchemy_pool_size",
56
+ ),
57
+ )
58
+
59
+ pool_recycle: int = Field(
60
+ default=3600,
61
+ description="This setting causes the pool to recycle connections after the given number of seconds has passed; set it to -1 to avoid recycling entirely.",
62
+ )
63
+
64
+ pool_timeout: Optional[float] = Field(
65
+ default=30.0,
66
+ description="Number of seconds to wait before giving up on getting a connection from the pool. Defaults to 30 seconds.",
67
+ )
68
+
69
+ max_overflow: int = Field(
70
+ default=10,
71
+ description="Controls maximum overflow of the connection pool. To prevent overflow, set to -1.",
72
+ validation_alias=AliasChoices(
73
+ AliasPath("max_overflow"),
74
+ "prefect_server_database_sqlalchemy_max_overflow",
75
+ "prefect_sqlalchemy_max_overflow",
76
+ ),
77
+ )
16
78
 
17
79
 
18
80
  class ServerDatabaseSettings(PrefectBaseSettings):
@@ -20,7 +82,14 @@ class ServerDatabaseSettings(PrefectBaseSettings):
20
82
  Settings for controlling server database behavior
21
83
  """
22
84
 
23
- model_config: ClassVar[ConfigDict] = _build_settings_config(("server", "database"))
85
+ model_config: ClassVar[SettingsConfigDict] = build_settings_config(
86
+ ("server", "database")
87
+ )
88
+
89
+ sqlalchemy: SQLAlchemySettings = Field(
90
+ default_factory=SQLAlchemySettings,
91
+ description="Settings for controlling SQLAlchemy behavior",
92
+ )
24
93
 
25
94
  connection_url: Optional[SecretStr] = Field(
26
95
  default=None,
@@ -128,7 +197,7 @@ class ServerDatabaseSettings(PrefectBaseSettings):
128
197
 
129
198
  timeout: Optional[float] = Field(
130
199
  default=10.0,
131
- description="A statement timeout, in seconds, applied to all database interactions made by the API. Defaults to 10 seconds.",
200
+ description="A statement timeout, in seconds, applied to all database interactions made by the Prefect backend. Defaults to 10 seconds.",
132
201
  validation_alias=AliasChoices(
133
202
  AliasPath("timeout"),
134
203
  "prefect_server_database_timeout",
@@ -146,25 +215,49 @@ class ServerDatabaseSettings(PrefectBaseSettings):
146
215
  ),
147
216
  )
148
217
 
149
- sqlalchemy_pool_size: Optional[int] = Field(
150
- default=None,
151
- description="Controls connection pool size when using a PostgreSQL database with the Prefect API. If not set, the default SQLAlchemy pool size will be used.",
152
- validation_alias=AliasChoices(
153
- AliasPath("sqlalchemy_pool_size"),
154
- "prefect_server_database_sqlalchemy_pool_size",
155
- "prefect_sqlalchemy_pool_size",
156
- ),
157
- )
218
+ # handle deprecated fields
158
219
 
159
- sqlalchemy_max_overflow: Optional[int] = Field(
160
- default=None,
161
- description="Controls maximum overflow of the connection pool when using a PostgreSQL database with the Prefect API. If not set, the default SQLAlchemy maximum overflow value will be used.",
162
- validation_alias=AliasChoices(
163
- AliasPath("sqlalchemy_max_overflow"),
164
- "prefect_server_database_sqlalchemy_max_overflow",
165
- "prefect_sqlalchemy_max_overflow",
166
- ),
167
- )
220
+ def __getattribute__(self, name: str) -> Any:
221
+ if name in ["sqlalchemy_pool_size", "sqlalchemy_max_overflow"]:
222
+ warnings.warn(
223
+ f"Setting {name} has been moved to the `sqlalchemy` settings group.",
224
+ DeprecationWarning,
225
+ )
226
+ field_name = name.replace("sqlalchemy_", "")
227
+ return getattr(super().__getattribute__("sqlalchemy"), field_name)
228
+ return super().__getattribute__(name)
229
+
230
+ # validators
231
+
232
+ @model_validator(mode="before")
233
+ @classmethod
234
+ def set_deprecated_sqlalchemy_settings_on_child_model_and_warn(
235
+ cls, values: dict[str, Any]
236
+ ) -> dict[str, Any]:
237
+ """
238
+ Set deprecated settings on the child model.
239
+ """
240
+ # Initialize sqlalchemy settings if not present
241
+ if "sqlalchemy" not in values:
242
+ values["sqlalchemy"] = SQLAlchemySettings()
243
+
244
+ if "sqlalchemy_pool_size" in values:
245
+ warnings.warn(
246
+ "`sqlalchemy_pool_size` has been moved to the `sqlalchemy` settings group as `pool_size`.",
247
+ DeprecationWarning,
248
+ )
249
+ if "pool_size" not in values["sqlalchemy"].model_fields_set:
250
+ values["sqlalchemy"].pool_size = values["sqlalchemy_pool_size"]
251
+
252
+ if "sqlalchemy_max_overflow" in values:
253
+ warnings.warn(
254
+ "`sqlalchemy_max_overflow` has been moved to the `sqlalchemy` settings group as `max_overflow`.",
255
+ DeprecationWarning,
256
+ )
257
+ if "max_overflow" not in values["sqlalchemy"].model_fields_set:
258
+ values["sqlalchemy"].max_overflow = values["sqlalchemy_max_overflow"]
259
+
260
+ return values
168
261
 
169
262
  @model_validator(mode="after")
170
263
  def emit_warnings(self) -> Self: # noqa: F821
@@ -173,7 +266,9 @@ class ServerDatabaseSettings(PrefectBaseSettings):
173
266
  return self
174
267
 
175
268
 
176
- def warn_on_database_password_value_without_usage(settings: ServerDatabaseSettings):
269
+ def warn_on_database_password_value_without_usage(
270
+ settings: ServerDatabaseSettings,
271
+ ) -> None:
177
272
  """
178
273
  Validator for settings warning if the database password is set but not used.
179
274
  """
@@ -201,4 +296,4 @@ def warn_on_database_password_value_without_usage(settings: ServerDatabaseSettin
201
296
  "PREFECT_SERVER_DATABASE_CONNECTION_URL. "
202
297
  "The provided password will be ignored."
203
298
  )
204
- return settings
299
+ return None