prefect-client 2.20.2__py3-none-any.whl → 3.0.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 (288) hide show
  1. prefect/__init__.py +74 -110
  2. prefect/_internal/compatibility/deprecated.py +6 -115
  3. prefect/_internal/compatibility/experimental.py +4 -79
  4. prefect/_internal/compatibility/migration.py +166 -0
  5. prefect/_internal/concurrency/__init__.py +2 -2
  6. prefect/_internal/concurrency/api.py +1 -35
  7. prefect/_internal/concurrency/calls.py +0 -6
  8. prefect/_internal/concurrency/cancellation.py +0 -3
  9. prefect/_internal/concurrency/event_loop.py +0 -20
  10. prefect/_internal/concurrency/inspection.py +3 -3
  11. prefect/_internal/concurrency/primitives.py +1 -0
  12. prefect/_internal/concurrency/services.py +23 -0
  13. prefect/_internal/concurrency/threads.py +35 -0
  14. prefect/_internal/concurrency/waiters.py +0 -28
  15. prefect/_internal/integrations.py +7 -0
  16. prefect/_internal/pydantic/__init__.py +0 -45
  17. prefect/_internal/pydantic/annotations/pendulum.py +2 -2
  18. prefect/_internal/pydantic/v1_schema.py +21 -22
  19. prefect/_internal/pydantic/v2_schema.py +0 -2
  20. prefect/_internal/pydantic/v2_validated_func.py +18 -23
  21. prefect/_internal/pytz.py +1 -1
  22. prefect/_internal/retries.py +61 -0
  23. prefect/_internal/schemas/bases.py +45 -177
  24. prefect/_internal/schemas/fields.py +1 -43
  25. prefect/_internal/schemas/validators.py +47 -233
  26. prefect/agent.py +3 -695
  27. prefect/artifacts.py +173 -14
  28. prefect/automations.py +39 -4
  29. prefect/blocks/abstract.py +1 -1
  30. prefect/blocks/core.py +423 -164
  31. prefect/blocks/fields.py +2 -57
  32. prefect/blocks/notifications.py +43 -28
  33. prefect/blocks/redis.py +168 -0
  34. prefect/blocks/system.py +67 -20
  35. prefect/blocks/webhook.py +2 -9
  36. prefect/cache_policies.py +239 -0
  37. prefect/client/__init__.py +4 -0
  38. prefect/client/base.py +33 -27
  39. prefect/client/cloud.py +65 -20
  40. prefect/client/collections.py +1 -1
  41. prefect/client/orchestration.py +667 -440
  42. prefect/client/schemas/actions.py +115 -100
  43. prefect/client/schemas/filters.py +46 -52
  44. prefect/client/schemas/objects.py +228 -178
  45. prefect/client/schemas/responses.py +18 -36
  46. prefect/client/schemas/schedules.py +55 -36
  47. prefect/client/schemas/sorting.py +2 -0
  48. prefect/client/subscriptions.py +8 -7
  49. prefect/client/types/flexible_schedule_list.py +11 -0
  50. prefect/client/utilities.py +9 -6
  51. prefect/concurrency/asyncio.py +60 -11
  52. prefect/concurrency/context.py +24 -0
  53. prefect/concurrency/events.py +2 -2
  54. prefect/concurrency/services.py +46 -16
  55. prefect/concurrency/sync.py +51 -7
  56. prefect/concurrency/v1/asyncio.py +143 -0
  57. prefect/concurrency/v1/context.py +27 -0
  58. prefect/concurrency/v1/events.py +61 -0
  59. prefect/concurrency/v1/services.py +116 -0
  60. prefect/concurrency/v1/sync.py +92 -0
  61. prefect/context.py +246 -149
  62. prefect/deployments/__init__.py +33 -18
  63. prefect/deployments/base.py +10 -15
  64. prefect/deployments/deployments.py +2 -1048
  65. prefect/deployments/flow_runs.py +178 -0
  66. prefect/deployments/runner.py +72 -173
  67. prefect/deployments/schedules.py +31 -25
  68. prefect/deployments/steps/__init__.py +0 -1
  69. prefect/deployments/steps/core.py +7 -0
  70. prefect/deployments/steps/pull.py +15 -21
  71. prefect/deployments/steps/utility.py +2 -1
  72. prefect/docker/__init__.py +20 -0
  73. prefect/docker/docker_image.py +82 -0
  74. prefect/engine.py +15 -2466
  75. prefect/events/actions.py +17 -23
  76. prefect/events/cli/automations.py +20 -7
  77. prefect/events/clients.py +142 -80
  78. prefect/events/filters.py +14 -18
  79. prefect/events/related.py +74 -75
  80. prefect/events/schemas/__init__.py +0 -5
  81. prefect/events/schemas/automations.py +55 -46
  82. prefect/events/schemas/deployment_triggers.py +7 -197
  83. prefect/events/schemas/events.py +46 -65
  84. prefect/events/schemas/labelling.py +10 -14
  85. prefect/events/utilities.py +4 -5
  86. prefect/events/worker.py +23 -8
  87. prefect/exceptions.py +15 -0
  88. prefect/filesystems.py +30 -529
  89. prefect/flow_engine.py +827 -0
  90. prefect/flow_runs.py +379 -7
  91. prefect/flows.py +470 -360
  92. prefect/futures.py +382 -331
  93. prefect/infrastructure/__init__.py +5 -26
  94. prefect/infrastructure/base.py +3 -320
  95. prefect/infrastructure/provisioners/__init__.py +5 -3
  96. prefect/infrastructure/provisioners/cloud_run.py +13 -8
  97. prefect/infrastructure/provisioners/container_instance.py +14 -9
  98. prefect/infrastructure/provisioners/ecs.py +10 -8
  99. prefect/infrastructure/provisioners/modal.py +8 -5
  100. prefect/input/__init__.py +4 -0
  101. prefect/input/actions.py +2 -4
  102. prefect/input/run_input.py +9 -9
  103. prefect/logging/formatters.py +2 -4
  104. prefect/logging/handlers.py +9 -14
  105. prefect/logging/loggers.py +5 -5
  106. prefect/main.py +72 -0
  107. prefect/plugins.py +2 -64
  108. prefect/profiles.toml +16 -2
  109. prefect/records/__init__.py +1 -0
  110. prefect/records/base.py +223 -0
  111. prefect/records/filesystem.py +207 -0
  112. prefect/records/memory.py +178 -0
  113. prefect/records/result_store.py +64 -0
  114. prefect/results.py +577 -504
  115. prefect/runner/runner.py +124 -51
  116. prefect/runner/server.py +32 -34
  117. prefect/runner/storage.py +3 -12
  118. prefect/runner/submit.py +2 -10
  119. prefect/runner/utils.py +2 -2
  120. prefect/runtime/__init__.py +1 -0
  121. prefect/runtime/deployment.py +1 -0
  122. prefect/runtime/flow_run.py +40 -5
  123. prefect/runtime/task_run.py +1 -0
  124. prefect/serializers.py +28 -39
  125. prefect/server/api/collections_data/views/aggregate-worker-metadata.json +5 -14
  126. prefect/settings.py +209 -332
  127. prefect/states.py +160 -63
  128. prefect/task_engine.py +1478 -57
  129. prefect/task_runners.py +383 -287
  130. prefect/task_runs.py +240 -0
  131. prefect/task_worker.py +463 -0
  132. prefect/tasks.py +684 -374
  133. prefect/transactions.py +410 -0
  134. prefect/types/__init__.py +72 -86
  135. prefect/types/entrypoint.py +13 -0
  136. prefect/utilities/annotations.py +4 -3
  137. prefect/utilities/asyncutils.py +227 -148
  138. prefect/utilities/callables.py +138 -48
  139. prefect/utilities/collections.py +134 -86
  140. prefect/utilities/dispatch.py +27 -14
  141. prefect/utilities/dockerutils.py +11 -4
  142. prefect/utilities/engine.py +186 -32
  143. prefect/utilities/filesystem.py +4 -5
  144. prefect/utilities/importtools.py +26 -27
  145. prefect/utilities/pydantic.py +128 -38
  146. prefect/utilities/schema_tools/hydration.py +18 -1
  147. prefect/utilities/schema_tools/validation.py +30 -0
  148. prefect/utilities/services.py +35 -9
  149. prefect/utilities/templating.py +12 -2
  150. prefect/utilities/timeout.py +20 -5
  151. prefect/utilities/urls.py +195 -0
  152. prefect/utilities/visualization.py +1 -0
  153. prefect/variables.py +78 -59
  154. prefect/workers/__init__.py +0 -1
  155. prefect/workers/base.py +237 -244
  156. prefect/workers/block.py +5 -226
  157. prefect/workers/cloud.py +6 -0
  158. prefect/workers/process.py +265 -12
  159. prefect/workers/server.py +29 -11
  160. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/METADATA +30 -26
  161. prefect_client-3.0.0.dist-info/RECORD +201 -0
  162. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/WHEEL +1 -1
  163. prefect/_internal/pydantic/_base_model.py +0 -51
  164. prefect/_internal/pydantic/_compat.py +0 -82
  165. prefect/_internal/pydantic/_flags.py +0 -20
  166. prefect/_internal/pydantic/_types.py +0 -8
  167. prefect/_internal/pydantic/utilities/config_dict.py +0 -72
  168. prefect/_internal/pydantic/utilities/field_validator.py +0 -150
  169. prefect/_internal/pydantic/utilities/model_construct.py +0 -56
  170. prefect/_internal/pydantic/utilities/model_copy.py +0 -55
  171. prefect/_internal/pydantic/utilities/model_dump.py +0 -136
  172. prefect/_internal/pydantic/utilities/model_dump_json.py +0 -112
  173. prefect/_internal/pydantic/utilities/model_fields.py +0 -50
  174. prefect/_internal/pydantic/utilities/model_fields_set.py +0 -29
  175. prefect/_internal/pydantic/utilities/model_json_schema.py +0 -82
  176. prefect/_internal/pydantic/utilities/model_rebuild.py +0 -80
  177. prefect/_internal/pydantic/utilities/model_validate.py +0 -75
  178. prefect/_internal/pydantic/utilities/model_validate_json.py +0 -68
  179. prefect/_internal/pydantic/utilities/model_validator.py +0 -87
  180. prefect/_internal/pydantic/utilities/type_adapter.py +0 -71
  181. prefect/_vendor/fastapi/__init__.py +0 -25
  182. prefect/_vendor/fastapi/applications.py +0 -946
  183. prefect/_vendor/fastapi/background.py +0 -3
  184. prefect/_vendor/fastapi/concurrency.py +0 -44
  185. prefect/_vendor/fastapi/datastructures.py +0 -58
  186. prefect/_vendor/fastapi/dependencies/__init__.py +0 -0
  187. prefect/_vendor/fastapi/dependencies/models.py +0 -64
  188. prefect/_vendor/fastapi/dependencies/utils.py +0 -877
  189. prefect/_vendor/fastapi/encoders.py +0 -177
  190. prefect/_vendor/fastapi/exception_handlers.py +0 -40
  191. prefect/_vendor/fastapi/exceptions.py +0 -46
  192. prefect/_vendor/fastapi/logger.py +0 -3
  193. prefect/_vendor/fastapi/middleware/__init__.py +0 -1
  194. prefect/_vendor/fastapi/middleware/asyncexitstack.py +0 -25
  195. prefect/_vendor/fastapi/middleware/cors.py +0 -3
  196. prefect/_vendor/fastapi/middleware/gzip.py +0 -3
  197. prefect/_vendor/fastapi/middleware/httpsredirect.py +0 -3
  198. prefect/_vendor/fastapi/middleware/trustedhost.py +0 -3
  199. prefect/_vendor/fastapi/middleware/wsgi.py +0 -3
  200. prefect/_vendor/fastapi/openapi/__init__.py +0 -0
  201. prefect/_vendor/fastapi/openapi/constants.py +0 -2
  202. prefect/_vendor/fastapi/openapi/docs.py +0 -203
  203. prefect/_vendor/fastapi/openapi/models.py +0 -480
  204. prefect/_vendor/fastapi/openapi/utils.py +0 -485
  205. prefect/_vendor/fastapi/param_functions.py +0 -340
  206. prefect/_vendor/fastapi/params.py +0 -453
  207. prefect/_vendor/fastapi/py.typed +0 -0
  208. prefect/_vendor/fastapi/requests.py +0 -4
  209. prefect/_vendor/fastapi/responses.py +0 -40
  210. prefect/_vendor/fastapi/routing.py +0 -1331
  211. prefect/_vendor/fastapi/security/__init__.py +0 -15
  212. prefect/_vendor/fastapi/security/api_key.py +0 -98
  213. prefect/_vendor/fastapi/security/base.py +0 -6
  214. prefect/_vendor/fastapi/security/http.py +0 -172
  215. prefect/_vendor/fastapi/security/oauth2.py +0 -227
  216. prefect/_vendor/fastapi/security/open_id_connect_url.py +0 -34
  217. prefect/_vendor/fastapi/security/utils.py +0 -10
  218. prefect/_vendor/fastapi/staticfiles.py +0 -1
  219. prefect/_vendor/fastapi/templating.py +0 -3
  220. prefect/_vendor/fastapi/testclient.py +0 -1
  221. prefect/_vendor/fastapi/types.py +0 -3
  222. prefect/_vendor/fastapi/utils.py +0 -235
  223. prefect/_vendor/fastapi/websockets.py +0 -7
  224. prefect/_vendor/starlette/__init__.py +0 -1
  225. prefect/_vendor/starlette/_compat.py +0 -28
  226. prefect/_vendor/starlette/_exception_handler.py +0 -80
  227. prefect/_vendor/starlette/_utils.py +0 -88
  228. prefect/_vendor/starlette/applications.py +0 -261
  229. prefect/_vendor/starlette/authentication.py +0 -159
  230. prefect/_vendor/starlette/background.py +0 -43
  231. prefect/_vendor/starlette/concurrency.py +0 -59
  232. prefect/_vendor/starlette/config.py +0 -151
  233. prefect/_vendor/starlette/convertors.py +0 -87
  234. prefect/_vendor/starlette/datastructures.py +0 -707
  235. prefect/_vendor/starlette/endpoints.py +0 -130
  236. prefect/_vendor/starlette/exceptions.py +0 -60
  237. prefect/_vendor/starlette/formparsers.py +0 -276
  238. prefect/_vendor/starlette/middleware/__init__.py +0 -17
  239. prefect/_vendor/starlette/middleware/authentication.py +0 -52
  240. prefect/_vendor/starlette/middleware/base.py +0 -220
  241. prefect/_vendor/starlette/middleware/cors.py +0 -176
  242. prefect/_vendor/starlette/middleware/errors.py +0 -265
  243. prefect/_vendor/starlette/middleware/exceptions.py +0 -74
  244. prefect/_vendor/starlette/middleware/gzip.py +0 -113
  245. prefect/_vendor/starlette/middleware/httpsredirect.py +0 -19
  246. prefect/_vendor/starlette/middleware/sessions.py +0 -82
  247. prefect/_vendor/starlette/middleware/trustedhost.py +0 -64
  248. prefect/_vendor/starlette/middleware/wsgi.py +0 -147
  249. prefect/_vendor/starlette/py.typed +0 -0
  250. prefect/_vendor/starlette/requests.py +0 -328
  251. prefect/_vendor/starlette/responses.py +0 -347
  252. prefect/_vendor/starlette/routing.py +0 -933
  253. prefect/_vendor/starlette/schemas.py +0 -154
  254. prefect/_vendor/starlette/staticfiles.py +0 -248
  255. prefect/_vendor/starlette/status.py +0 -199
  256. prefect/_vendor/starlette/templating.py +0 -231
  257. prefect/_vendor/starlette/testclient.py +0 -804
  258. prefect/_vendor/starlette/types.py +0 -30
  259. prefect/_vendor/starlette/websockets.py +0 -193
  260. prefect/blocks/kubernetes.py +0 -119
  261. prefect/deprecated/__init__.py +0 -0
  262. prefect/deprecated/data_documents.py +0 -350
  263. prefect/deprecated/packaging/__init__.py +0 -12
  264. prefect/deprecated/packaging/base.py +0 -96
  265. prefect/deprecated/packaging/docker.py +0 -146
  266. prefect/deprecated/packaging/file.py +0 -92
  267. prefect/deprecated/packaging/orion.py +0 -80
  268. prefect/deprecated/packaging/serializers.py +0 -171
  269. prefect/events/instrument.py +0 -135
  270. prefect/infrastructure/container.py +0 -824
  271. prefect/infrastructure/kubernetes.py +0 -920
  272. prefect/infrastructure/process.py +0 -289
  273. prefect/manifests.py +0 -20
  274. prefect/new_flow_engine.py +0 -449
  275. prefect/new_task_engine.py +0 -423
  276. prefect/pydantic/__init__.py +0 -76
  277. prefect/pydantic/main.py +0 -39
  278. prefect/software/__init__.py +0 -2
  279. prefect/software/base.py +0 -50
  280. prefect/software/conda.py +0 -199
  281. prefect/software/pip.py +0 -122
  282. prefect/software/python.py +0 -52
  283. prefect/task_server.py +0 -322
  284. prefect_client-2.20.2.dist-info/RECORD +0 -294
  285. /prefect/{_internal/pydantic/utilities → client/types}/__init__.py +0 -0
  286. /prefect/{_vendor → concurrency/v1}/__init__.py +0 -0
  287. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/LICENSE +0 -0
  288. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/top_level.txt +0 -0
prefect/settings.py CHANGED
@@ -42,6 +42,7 @@ dependent on the value of other settings or perform other dynamic effects.
42
42
 
43
43
  import logging
44
44
  import os
45
+ import re
45
46
  import string
46
47
  import warnings
47
48
  from contextlib import contextmanager
@@ -65,36 +66,22 @@ from typing import (
65
66
  )
66
67
  from urllib.parse import urlparse
67
68
 
69
+ import pydantic
68
70
  import toml
69
-
70
- from prefect._internal.pydantic import HAS_PYDANTIC_V2
71
- from prefect._internal.schemas.validators import validate_settings
72
-
73
- if HAS_PYDANTIC_V2:
74
- from pydantic.v1 import (
75
- BaseModel,
76
- BaseSettings,
77
- Field,
78
- create_model,
79
- fields,
80
- root_validator,
81
- validator,
82
- )
83
- else:
84
- from pydantic import (
85
- BaseModel,
86
- BaseSettings,
87
- Field,
88
- create_model,
89
- fields,
90
- root_validator,
91
- validator,
92
- )
93
-
71
+ from pydantic import (
72
+ BaseModel,
73
+ ConfigDict,
74
+ Field,
75
+ create_model,
76
+ field_validator,
77
+ fields,
78
+ model_validator,
79
+ )
80
+ from pydantic_settings import BaseSettings, SettingsConfigDict
94
81
  from typing_extensions import Literal
95
82
 
96
83
  from prefect._internal.compatibility.deprecated import generate_deprecation_message
97
- from prefect._internal.pydantic import HAS_PYDANTIC_V2
84
+ from prefect._internal.schemas.validators import validate_settings
98
85
  from prefect.exceptions import MissingProfileError
99
86
  from prefect.utilities.names import OBFUSCATED_PREFIX, obfuscate
100
87
  from prefect.utilities.pydantic import add_cloudpickle_reduction
@@ -104,15 +91,6 @@ T = TypeVar("T")
104
91
 
105
92
  DEFAULT_PROFILES_PATH = Path(__file__).parent.joinpath("profiles.toml")
106
93
 
107
- REMOVED_EXPERIMENTAL_FLAGS = {
108
- "PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_SCHEDULING_UI",
109
- "PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_DEPLOYMENT_PARAMETERS",
110
- "PREFECT_EXPERIMENTAL_ENABLE_EVENTS_CLIENT",
111
- "PREFECT_EXPERIMENTAL_WARN_EVENTS_CLIENT",
112
- "PREFECT_EXPERIMENTAL_ENABLE_FLOW_RUN_INFRA_OVERRIDES",
113
- "PREFECT_EXPERIMENTAL_WARN_FLOW_RUN_INFRA_OVERRIDES",
114
- }
115
-
116
94
 
117
95
  class Setting(Generic[T]):
118
96
  """
@@ -245,7 +223,7 @@ class Setting(Generic[T]):
245
223
  )
246
224
 
247
225
  def __repr__(self) -> str:
248
- return f"<{self.name}: {self.type.__name__}>"
226
+ return f"<{self.name}: {self.type!r}>"
249
227
 
250
228
  def __bool__(self) -> bool:
251
229
  """
@@ -377,6 +355,7 @@ def warn_on_database_password_value_without_usage(values):
377
355
  if (
378
356
  value
379
357
  and not value.startswith(OBFUSCATED_PREFIX)
358
+ and values["PREFECT_API_DATABASE_CONNECTION_URL"] is not None
380
359
  and (
381
360
  "PREFECT_API_DATABASE_PASSWORD"
382
361
  not in values["PREFECT_API_DATABASE_CONNECTION_URL"]
@@ -390,21 +369,6 @@ def warn_on_database_password_value_without_usage(values):
390
369
  return values
391
370
 
392
371
 
393
- def check_for_deprecated_cloud_url(settings, value):
394
- deprecated_value = PREFECT_CLOUD_URL.value_from(settings, bypass_callback=True)
395
- if deprecated_value is not None:
396
- warnings.warn(
397
- (
398
- "`PREFECT_CLOUD_URL` is set and will be used instead of"
399
- " `PREFECT_CLOUD_API_URL` for backwards compatibility."
400
- " `PREFECT_CLOUD_URL` is deprecated, set `PREFECT_CLOUD_API_URL`"
401
- " instead."
402
- ),
403
- DeprecationWarning,
404
- )
405
- return deprecated_value or value
406
-
407
-
408
372
  def warn_on_misconfigured_api_url(values):
409
373
  """
410
374
  Validator for settings warning if the API URL is misconfigured.
@@ -444,7 +408,45 @@ def warn_on_misconfigured_api_url(values):
444
408
  return values
445
409
 
446
410
 
447
- def default_database_connection_url(settings, value):
411
+ def default_database_connection_url(settings: "Settings", value: Optional[str]):
412
+ driver = PREFECT_API_DATABASE_DRIVER.value_from(settings)
413
+ if driver == "postgresql+asyncpg":
414
+ required = [
415
+ PREFECT_API_DATABASE_HOST,
416
+ PREFECT_API_DATABASE_USER,
417
+ PREFECT_API_DATABASE_NAME,
418
+ PREFECT_API_DATABASE_PASSWORD,
419
+ ]
420
+ missing = [
421
+ setting.name for setting in required if not setting.value_from(settings)
422
+ ]
423
+ if missing:
424
+ raise ValueError(
425
+ f"Missing required database connection settings: {', '.join(missing)}"
426
+ )
427
+
428
+ # We only need SQLAlchemy here if we're parsing a remote database connection
429
+ # string. Import it here so that we don't require the prefect-client package
430
+ # to have SQLAlchemy installed.
431
+ from sqlalchemy import URL
432
+
433
+ return URL(
434
+ drivername=driver,
435
+ host=PREFECT_API_DATABASE_HOST.value_from(settings),
436
+ port=PREFECT_API_DATABASE_PORT.value_from(settings) or 5432,
437
+ username=PREFECT_API_DATABASE_USER.value_from(settings),
438
+ password=PREFECT_API_DATABASE_PASSWORD.value_from(settings),
439
+ database=PREFECT_API_DATABASE_NAME.value_from(settings),
440
+ query=[],
441
+ ).render_as_string(hide_password=False)
442
+
443
+ elif driver == "sqlite+aiosqlite":
444
+ path = PREFECT_API_DATABASE_NAME.value_from(settings)
445
+ if path:
446
+ return f"{driver}:///{path}"
447
+ elif driver:
448
+ raise ValueError(f"Unsupported database driver: {driver}")
449
+
448
450
  templater = template_with_settings(PREFECT_HOME, PREFECT_API_DATABASE_PASSWORD)
449
451
 
450
452
  # If the user has provided a value, use it
@@ -502,10 +504,8 @@ def default_cloud_ui_url(settings, value):
502
504
  # Otherwise, infer a value from the API URL
503
505
  ui_url = api_url = PREFECT_CLOUD_API_URL.value_from(settings)
504
506
 
505
- if api_url.startswith("https://api.prefect.cloud"):
506
- ui_url = ui_url.replace(
507
- "https://api.prefect.cloud", "https://app.prefect.cloud", 1
508
- )
507
+ if re.match(r"^https://api[\.\w]*.prefect.[^\.]+/", api_url):
508
+ ui_url = ui_url.replace("https://api", "https://app", 1)
509
509
 
510
510
  if ui_url.endswith("/api"):
511
511
  ui_url = ui_url[:-4]
@@ -524,18 +524,6 @@ PREFECT_HOME = Setting(
524
524
  directory may be created automatically when required.
525
525
  """
526
526
 
527
- PREFECT_EXTRA_ENTRYPOINTS = Setting(
528
- str,
529
- default="",
530
- )
531
- """
532
- Modules for Prefect to import when Prefect is imported.
533
-
534
- Values should be separated by commas, e.g. `my_module,my_other_module`.
535
- Objects within modules may be specified by a ':' partition, e.g. `my_module:my_object`.
536
- If a callable object is provided, it will be called with no arguments on import.
537
- """
538
-
539
527
  PREFECT_DEBUG_MODE = Setting(
540
528
  bool,
541
529
  default=False,
@@ -614,7 +602,7 @@ This is recommended only during development, e.g. when using self-signed certifi
614
602
  """
615
603
 
616
604
  PREFECT_API_SSL_CERT_FILE = Setting(
617
- str,
605
+ Optional[str],
618
606
  default=os.environ.get("SSL_CERT_FILE"),
619
607
  )
620
608
  """
@@ -624,7 +612,7 @@ If left unset, the setting will default to the value provided by the `SSL_CERT_F
624
612
  """
625
613
 
626
614
  PREFECT_API_URL = Setting(
627
- str,
615
+ Optional[str],
628
616
  default=None,
629
617
  )
630
618
  """
@@ -643,7 +631,7 @@ we would like to silence this warning so we will set it to `FALSE`.
643
631
  """
644
632
 
645
633
  PREFECT_API_KEY = Setting(
646
- str,
634
+ Optional[str],
647
635
  default=None,
648
636
  is_secret=True,
649
637
  )
@@ -706,22 +694,10 @@ Defaults to `True`, ensuring CSRF protection is enabled by default.
706
694
  PREFECT_CLOUD_API_URL = Setting(
707
695
  str,
708
696
  default="https://api.prefect.cloud/api",
709
- value_callback=check_for_deprecated_cloud_url,
710
697
  )
711
698
  """API URL for Prefect Cloud. Used for authentication."""
712
699
 
713
700
 
714
- PREFECT_CLOUD_URL = Setting(
715
- str,
716
- default=None,
717
- deprecated=True,
718
- deprecated_start_date="Dec 2022",
719
- deprecated_help="Use `PREFECT_CLOUD_API_URL` instead.",
720
- )
721
- """
722
- DEPRECATED: Use `PREFECT_CLOUD_API_URL` instead.
723
- """
724
-
725
701
  PREFECT_UI_URL = Setting(
726
702
  Optional[str],
727
703
  default=None,
@@ -736,7 +712,7 @@ When using an ephemeral server, this will be `None`.
736
712
 
737
713
 
738
714
  PREFECT_CLOUD_UI_URL = Setting(
739
- str,
715
+ Optional[str],
740
716
  default=None,
741
717
  value_callback=default_cloud_ui_url,
742
718
  )
@@ -950,7 +926,7 @@ The following options are available:
950
926
  """
951
927
 
952
928
  PREFECT_SQLALCHEMY_POOL_SIZE = Setting(
953
- int,
929
+ Optional[int],
954
930
  default=None,
955
931
  )
956
932
  """
@@ -958,7 +934,7 @@ Controls connection pool size when using a PostgreSQL database with the Prefect
958
934
  """
959
935
 
960
936
  PREFECT_SQLALCHEMY_MAX_OVERFLOW = Setting(
961
- int,
937
+ Optional[int],
962
938
  default=None,
963
939
  )
964
940
  """
@@ -984,41 +960,6 @@ interpreted and lead to incomplete output, e.g.
984
960
  `DROP TABLE [dbo].[SomeTable];"` outputs `DROP TABLE .[SomeTable];`.
985
961
  """
986
962
 
987
- PREFECT_TASK_INTROSPECTION_WARN_THRESHOLD = Setting(
988
- float,
989
- default=10.0,
990
- )
991
- """
992
- Threshold time in seconds for logging a warning if task parameter introspection
993
- exceeds this duration. Parameter introspection can be a significant performance hit
994
- when the parameter is a large collection object, e.g. a large dictionary or DataFrame,
995
- and each element needs to be inspected. See `prefect.utilities.annotations.quote`
996
- for more details.
997
- Defaults to `10.0`.
998
- Set to `0` to disable logging the warning.
999
- """
1000
-
1001
- PREFECT_AGENT_QUERY_INTERVAL = Setting(
1002
- float,
1003
- default=15,
1004
- )
1005
- """
1006
- The agent loop interval, in seconds. Agents will check for new runs this often.
1007
- Defaults to `15`.
1008
- """
1009
-
1010
- PREFECT_AGENT_PREFETCH_SECONDS = Setting(
1011
- int,
1012
- default=15,
1013
- )
1014
- """
1015
- Agents will look for scheduled runs this many seconds in
1016
- the future and attempt to run them. This accounts for any additional
1017
- infrastructure spin-up time or latency in preparing a flow run. Note
1018
- flow runs will not start before their scheduled time, even if they are
1019
- prefetched. Defaults to `15`.
1020
- """
1021
-
1022
963
  PREFECT_ASYNC_FETCH_STATE_RESULT = Setting(bool, default=False)
1023
964
  """
1024
965
  Determines whether `State.result()` fetches results automatically or not.
@@ -1043,19 +984,8 @@ backend on application startup. If not set, block types must be manually
1043
984
  registered.
1044
985
  """
1045
986
 
1046
- PREFECT_API_DATABASE_PASSWORD = Setting(
1047
- str,
1048
- default=None,
1049
- is_secret=True,
1050
- )
1051
- """
1052
- Password to template into the `PREFECT_API_DATABASE_CONNECTION_URL`.
1053
- This is useful if the password must be provided separately from the connection URL.
1054
- To use this setting, you must include it in your connection URL.
1055
- """
1056
-
1057
987
  PREFECT_API_DATABASE_CONNECTION_URL = Setting(
1058
- str,
988
+ Optional[str],
1059
989
  default=None,
1060
990
  value_callback=default_database_connection_url,
1061
991
  is_secret=True,
@@ -1083,6 +1013,46 @@ PREFECT_API_DATABASE_CONNECTION_URL='postgresql+asyncpg://postgres:${PREFECT_API
1083
1013
  ```
1084
1014
  """
1085
1015
 
1016
+ PREFECT_API_DATABASE_DRIVER = Setting(
1017
+ Optional[Literal["postgresql+asyncpg", "sqlite+aiosqlite"]],
1018
+ default=None,
1019
+ )
1020
+ """
1021
+ The database driver to use when connecting to the database.
1022
+ """
1023
+
1024
+ PREFECT_API_DATABASE_HOST = Setting(Optional[str], default=None)
1025
+ """
1026
+ The database server host.
1027
+ """
1028
+
1029
+ PREFECT_API_DATABASE_PORT = Setting(Optional[int], default=None)
1030
+ """
1031
+ The database server port.
1032
+ """
1033
+
1034
+ PREFECT_API_DATABASE_USER = Setting(Optional[str], default=None)
1035
+ """
1036
+ The user to use when connecting to the database.
1037
+ """
1038
+
1039
+ PREFECT_API_DATABASE_NAME = Setting(Optional[str], default=None)
1040
+ """
1041
+ The name of the Prefect database on the remote server, or the path to the database file
1042
+ for SQLite.
1043
+ """
1044
+
1045
+ PREFECT_API_DATABASE_PASSWORD = Setting(
1046
+ Optional[str],
1047
+ default=None,
1048
+ is_secret=True,
1049
+ )
1050
+ """
1051
+ Password to template into the `PREFECT_API_DATABASE_CONNECTION_URL`.
1052
+ This is useful if the password must be provided separately from the connection URL.
1053
+ To use this setting, you must include it in your connection URL.
1054
+ """
1055
+
1086
1056
  PREFECT_API_DATABASE_ECHO = Setting(
1087
1057
  bool,
1088
1058
  default=False,
@@ -1247,6 +1217,14 @@ PREFECT_API_SERVICES_FOREMAN_WORK_QUEUE_LAST_POLLED_TIMEOUT_SECONDS = Setting(
1247
1217
  """The number of seconds before a work queue is marked as not ready if it has not been
1248
1218
  polled."""
1249
1219
 
1220
+ PREFECT_API_LOG_RETRYABLE_ERRORS = Setting(bool, default=False)
1221
+ """If `True`, log retryable errors in the API and it's services."""
1222
+
1223
+ PREFECT_API_SERVICES_TASK_RUN_RECORDER_ENABLED = Setting(bool, default=True)
1224
+ """
1225
+ Whether or not to start the task run recorder service in the server application.
1226
+ """
1227
+
1250
1228
 
1251
1229
  PREFECT_API_DEFAULT_LIMIT = Setting(
1252
1230
  int,
@@ -1310,6 +1288,19 @@ compromise. Adjust this setting based on your specific security requirements
1310
1288
  and usage patterns.
1311
1289
  """
1312
1290
 
1291
+ PREFECT_SERVER_ALLOW_EPHEMERAL_MODE = Setting(bool, default=False)
1292
+ """
1293
+ Controls whether or not a subprocess server can be started when no API URL is provided.
1294
+ """
1295
+
1296
+ PREFECT_SERVER_EPHEMERAL_STARTUP_TIMEOUT_SECONDS = Setting(
1297
+ int,
1298
+ default=10,
1299
+ )
1300
+ """
1301
+ The number of seconds to wait for an ephemeral server to respond on start up before erroring.
1302
+ """
1303
+
1313
1304
  PREFECT_UI_ENABLED = Setting(
1314
1305
  bool,
1315
1306
  default=True,
@@ -1317,7 +1308,7 @@ PREFECT_UI_ENABLED = Setting(
1317
1308
  """Whether or not to serve the Prefect UI."""
1318
1309
 
1319
1310
  PREFECT_UI_API_URL = Setting(
1320
- str,
1311
+ Optional[str],
1321
1312
  default=None,
1322
1313
  value_callback=default_ui_api_url,
1323
1314
  )
@@ -1395,81 +1386,8 @@ PREFECT_API_MAX_FLOW_RUN_GRAPH_ARTIFACTS = Setting(int, default=10000)
1395
1386
  The maximum number of artifacts to show on a flow run graph on the v2 API
1396
1387
  """
1397
1388
 
1398
- PREFECT_EXPERIMENTAL_ENABLE_ARTIFACTS_ON_FLOW_RUN_GRAPH = Setting(bool, default=True)
1399
- """
1400
- Whether or not to enable artifacts on the flow run graph.
1401
- """
1402
-
1403
- PREFECT_EXPERIMENTAL_ENABLE_STATES_ON_FLOW_RUN_GRAPH = Setting(bool, default=True)
1404
- """
1405
- Whether or not to enable flow run states on the flow run graph.
1406
- """
1407
-
1408
- PREFECT_EXPERIMENTAL_ENABLE_WORK_POOLS = Setting(bool, default=True)
1409
- """
1410
- Whether or not to enable experimental Prefect work pools.
1411
- """
1412
-
1413
- PREFECT_EXPERIMENTAL_WARN_WORK_POOLS = Setting(bool, default=False)
1414
- """
1415
- Whether or not to warn when experimental Prefect work pools are used.
1416
- """
1417
-
1418
- PREFECT_EXPERIMENTAL_ENABLE_WORKERS = Setting(bool, default=True)
1419
- """
1420
- Whether or not to enable experimental Prefect workers.
1421
- """
1422
-
1423
- PREFECT_EXPERIMENTAL_WARN_WORKERS = Setting(bool, default=False)
1424
- """
1425
- Whether or not to warn when experimental Prefect workers are used.
1426
- """
1427
-
1428
- PREFECT_EXPERIMENTAL_WARN_VISUALIZE = Setting(bool, default=False)
1429
- """
1430
- Whether or not to warn when experimental Prefect visualize is used.
1431
- """
1432
-
1433
- PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_CANCELLATION = Setting(bool, default=True)
1434
- """
1435
- Whether or not to enable experimental enhanced flow run cancellation.
1436
- """
1437
-
1438
- PREFECT_EXPERIMENTAL_WARN_ENHANCED_CANCELLATION = Setting(bool, default=False)
1439
- """
1440
- Whether or not to warn when experimental enhanced flow run cancellation is used.
1441
- """
1442
-
1443
- PREFECT_EXPERIMENTAL_ENABLE_DEPLOYMENT_STATUS = Setting(bool, default=True)
1444
- """
1445
- Whether or not to enable deployment status in the UI
1446
- """
1447
-
1448
- PREFECT_EXPERIMENTAL_WARN_DEPLOYMENT_STATUS = Setting(bool, default=False)
1449
- """
1450
- Whether or not to warn when deployment status is used.
1451
- """
1452
-
1453
- PREFECT_EXPERIMENTAL_FLOW_RUN_INPUT = Setting(bool, default=False)
1454
- """
1455
- Whether or not to enable flow run input.
1456
- """
1457
-
1458
- PREFECT_EXPERIMENTAL_WARN_FLOW_RUN_INPUT = Setting(bool, default=True)
1459
- """
1460
- Whether or not to enable flow run input.
1461
- """
1462
-
1463
-
1464
1389
  # Prefect Events feature flags
1465
1390
 
1466
- PREFECT_EXPERIMENTAL_EVENTS = Setting(bool, default=False)
1467
- """
1468
- Whether to enable Prefect's server-side event features. Note that Prefect Cloud clients
1469
- will always emit events during flow and task runs regardless of this setting.
1470
- """
1471
-
1472
-
1473
1391
  PREFECT_RUNNER_PROCESS_LIMIT = Setting(int, default=5)
1474
1392
  """
1475
1393
  Maximum number of processes a runner will execute in parallel.
@@ -1542,10 +1460,7 @@ PREFECT_WORKER_WEBSERVER_PORT = Setting(
1542
1460
  The port the worker's webserver should bind to.
1543
1461
  """
1544
1462
 
1545
- PREFECT_TASK_SCHEDULING_DEFAULT_STORAGE_BLOCK = Setting(
1546
- str,
1547
- default="local-file-system/prefect-task-scheduling",
1548
- )
1463
+ PREFECT_TASK_SCHEDULING_DEFAULT_STORAGE_BLOCK = Setting(Optional[str], default=None)
1549
1464
  """The `block-type/block-document` slug of a block to use as the default storage
1550
1465
  for autonomous tasks."""
1551
1466
 
@@ -1575,75 +1490,31 @@ The maximum number of retries to queue for submission.
1575
1490
 
1576
1491
  PREFECT_TASK_SCHEDULING_PENDING_TASK_TIMEOUT = Setting(
1577
1492
  timedelta,
1578
- default=timedelta(seconds=30),
1493
+ default=timedelta(0),
1579
1494
  )
1580
1495
  """
1581
- How long before a PENDING task are made available to another task server. In practice,
1582
- a task server should move a task from PENDING to RUNNING very quickly, so runs stuck in
1583
- PENDING for a while is a sign that the task server may have crashed.
1584
- """
1585
-
1586
- PREFECT_EXPERIMENTAL_ENABLE_EXTRA_RUNNER_ENDPOINTS = Setting(bool, default=False)
1587
- """
1588
- Whether or not to enable experimental worker webserver endpoints.
1589
- """
1590
-
1591
- PREFECT_EXPERIMENTAL_ENABLE_ARTIFACTS = Setting(bool, default=True)
1592
- """
1593
- Whether or not to enable experimental Prefect artifacts.
1594
- """
1595
-
1596
- PREFECT_EXPERIMENTAL_WARN_ARTIFACTS = Setting(bool, default=False)
1597
- """
1598
- Whether or not to warn when experimental Prefect artifacts are used.
1599
- """
1600
-
1601
- PREFECT_EXPERIMENTAL_ENABLE_WORKSPACE_DASHBOARD = Setting(bool, default=True)
1602
- """
1603
- Whether or not to enable the experimental workspace dashboard.
1604
- """
1605
-
1606
- PREFECT_EXPERIMENTAL_WARN_WORKSPACE_DASHBOARD = Setting(bool, default=False)
1607
- """
1608
- Whether or not to warn when the experimental workspace dashboard is enabled.
1609
- """
1610
-
1611
- PREFECT_EXPERIMENTAL_ENABLE_TASK_SCHEDULING = Setting(bool, default=False)
1612
- """
1613
- Whether or not to enable experimental task scheduling.
1614
- """
1615
-
1616
- PREFECT_EXPERIMENTAL_ENABLE_WORK_QUEUE_STATUS = Setting(bool, default=True)
1617
- """
1618
- Whether or not to enable experimental work queue status in-place of work queue health.
1619
- """
1620
-
1621
- PREFECT_EXPERIMENTAL_ENABLE_NEW_ENGINE = Setting(bool, default=False)
1622
- """
1623
- Whether or not to enable experimental new engine.
1624
- """
1625
-
1626
- PREFECT_EXPERIMENTAL_DISABLE_SYNC_COMPAT = Setting(bool, default=False)
1627
- """
1628
- Whether or not to disable the sync_compatible decorator utility.
1496
+ How long before a PENDING task are made available to another task worker. In practice,
1497
+ a task worker should move a task from PENDING to RUNNING very quickly, so runs stuck in
1498
+ PENDING for a while is a sign that the task worker may have crashed.
1629
1499
  """
1630
1500
 
1501
+ PREFECT_EXPERIMENTAL_ENABLE_SCHEDULE_CONCURRENCY = Setting(bool, default=False)
1631
1502
 
1632
1503
  # Defaults -----------------------------------------------------------------------------
1633
1504
 
1634
1505
  PREFECT_DEFAULT_RESULT_STORAGE_BLOCK = Setting(
1635
- str,
1506
+ Optional[str],
1636
1507
  default=None,
1637
1508
  )
1638
1509
  """The `block-type/block-document` slug of a block to use as the default result storage."""
1639
1510
 
1640
- PREFECT_DEFAULT_WORK_POOL_NAME = Setting(str, default=None)
1511
+ PREFECT_DEFAULT_WORK_POOL_NAME = Setting(Optional[str], default=None)
1641
1512
  """
1642
1513
  The default work pool to deploy to.
1643
1514
  """
1644
1515
 
1645
1516
  PREFECT_DEFAULT_DOCKER_BUILD_NAMESPACE = Setting(
1646
- str,
1517
+ Optional[str],
1647
1518
  default=None,
1648
1519
  )
1649
1520
  """
@@ -1663,7 +1534,7 @@ Defaults to the root path.
1663
1534
  """
1664
1535
 
1665
1536
  PREFECT_UI_STATIC_DIRECTORY = Setting(
1666
- str,
1537
+ Optional[str],
1667
1538
  default=None,
1668
1539
  )
1669
1540
  """
@@ -1707,11 +1578,6 @@ PREFECT_EVENTS_MAXIMUM_SIZE_BYTES = Setting(int, default=1_500_000)
1707
1578
  The maximum size of an Event when serialized to JSON
1708
1579
  """
1709
1580
 
1710
- PREFECT_API_SERVICES_EVENT_LOGGER_ENABLED = Setting(bool, default=True)
1711
- """
1712
- Whether or not to start the event debug logger service in the server application.
1713
- """
1714
-
1715
1581
  PREFECT_API_SERVICES_TRIGGERS_ENABLED = Setting(bool, default=True)
1716
1582
  """
1717
1583
  Whether or not to start the triggers service in the server application.
@@ -1759,15 +1625,37 @@ PREFECT_API_EVENTS_RELATED_RESOURCE_CACHE_TTL = Setting(
1759
1625
  How long to cache related resource data for emitting server-side vents
1760
1626
  """
1761
1627
 
1628
+ PREFECT_EVENTS_MAXIMUM_WEBSOCKET_BACKFILL = Setting(
1629
+ timedelta, default=timedelta(minutes=15)
1630
+ )
1631
+ """
1632
+ The maximum range to look back for backfilling events for a websocket subscriber
1633
+ """
1634
+
1635
+ PREFECT_EVENTS_WEBSOCKET_BACKFILL_PAGE_SIZE = Setting(int, default=250, gt=0)
1636
+ """
1637
+ The page size for the queries to backfill events for websocket subscribers
1638
+ """
1762
1639
 
1763
- def automation_settings_enabled() -> bool:
1764
- """
1765
- Whether or not automations are enabled.
1766
- """
1767
- return (
1768
- PREFECT_EXPERIMENTAL_EVENTS.value()
1769
- and PREFECT_API_SERVICES_TRIGGERS_ENABLED.value()
1770
- )
1640
+
1641
+ # Metrics settings
1642
+
1643
+ PREFECT_API_ENABLE_METRICS = Setting(bool, default=False)
1644
+ """
1645
+ Whether or not to enable Prometheus metrics in the server application. Metrics are
1646
+ served at the path /api/metrics on the API server.
1647
+ """
1648
+
1649
+ PREFECT_CLIENT_ENABLE_METRICS = Setting(bool, default=False)
1650
+ """
1651
+ Whether or not to enable Prometheus metrics in the client SDK. Metrics are served
1652
+ at the path /metrics.
1653
+ """
1654
+
1655
+ PREFECT_CLIENT_METRICS_PORT = Setting(int, default=4201)
1656
+ """
1657
+ The port to expose the client Prometheus metrics on.
1658
+ """
1771
1659
 
1772
1660
 
1773
1661
  # Deprecated settings ------------------------------------------------------------------
@@ -1787,10 +1675,14 @@ for __name, __setting in SETTING_VARIABLES.items():
1787
1675
 
1788
1676
  # Dynamically create a pydantic model that includes all of our settings
1789
1677
 
1790
- SettingsFieldsMixin = create_model(
1678
+
1679
+ class PrefectBaseSettings(BaseSettings):
1680
+ model_config = SettingsConfigDict(extra="ignore")
1681
+
1682
+
1683
+ SettingsFieldsMixin: Type[BaseSettings] = create_model(
1791
1684
  "SettingsFieldsMixin",
1792
- # Inheriting from `BaseSettings` provides environment variable loading
1793
- __base__=BaseSettings,
1685
+ __base__=PrefectBaseSettings, # Inheriting from `BaseSettings` provides environment variable loading
1794
1686
  **{
1795
1687
  setting.name: (setting.type, setting.field)
1796
1688
  for setting in SETTING_VARIABLES.values()
@@ -1832,32 +1724,33 @@ class Settings(SettingsFieldsMixin):
1832
1724
  value = setting.value_callback(self, value)
1833
1725
  return value
1834
1726
 
1835
- @validator(PREFECT_LOGGING_LEVEL.name, PREFECT_LOGGING_SERVER_LEVEL.name)
1727
+ @field_validator(PREFECT_LOGGING_LEVEL.name, PREFECT_LOGGING_SERVER_LEVEL.name)
1836
1728
  def check_valid_log_level(cls, value):
1837
1729
  if isinstance(value, str):
1838
1730
  value = value.upper()
1839
1731
  logging._checkLevel(value)
1840
1732
  return value
1841
1733
 
1842
- @root_validator
1843
- def post_root_validators(cls, values):
1734
+ @model_validator(mode="after")
1735
+ def emit_warnings(self):
1844
1736
  """
1845
1737
  Add root validation functions for settings here.
1846
1738
  """
1847
1739
  # TODO: We could probably register these dynamically but this is the simpler
1848
1740
  # approach for now. We can explore more interesting validation features
1849
1741
  # in the future.
1742
+ values = self.model_dump()
1850
1743
  values = max_log_size_smaller_than_batch_size(values)
1851
1744
  values = warn_on_database_password_value_without_usage(values)
1852
1745
  if not values["PREFECT_SILENCE_API_URL_MISCONFIGURATION"]:
1853
1746
  values = warn_on_misconfigured_api_url(values)
1854
- return values
1747
+ return self
1855
1748
 
1856
1749
  def copy_with_update(
1857
1750
  self,
1858
- updates: Mapping[Setting, Any] = None,
1859
- set_defaults: Mapping[Setting, Any] = None,
1860
- restore_defaults: Iterable[Setting] = None,
1751
+ updates: Optional[Mapping[Setting, Any]] = None,
1752
+ set_defaults: Optional[Mapping[Setting, Any]] = None,
1753
+ restore_defaults: Optional[Iterable[Setting]] = None,
1861
1754
  ) -> "Settings":
1862
1755
  """
1863
1756
  Create a new `Settings` object with validation.
@@ -1880,7 +1773,7 @@ class Settings(SettingsFieldsMixin):
1880
1773
  return self.__class__(
1881
1774
  **{
1882
1775
  **{setting.name: value for setting, value in set_defaults.items()},
1883
- **self.dict(exclude_unset=True, exclude=restore_defaults_names),
1776
+ **self.model_dump(exclude_unset=True, exclude=restore_defaults_names),
1884
1777
  **{setting.name: value for setting, value in updates.items()},
1885
1778
  }
1886
1779
  )
@@ -1889,7 +1782,7 @@ class Settings(SettingsFieldsMixin):
1889
1782
  """
1890
1783
  Returns a copy of this settings object with secret setting values obfuscated.
1891
1784
  """
1892
- settings = self.copy(
1785
+ settings = self.model_copy(
1893
1786
  update={
1894
1787
  setting.name: obfuscate(self.value_of(setting))
1895
1788
  for setting in SETTING_VARIABLES.values()
@@ -1900,7 +1793,11 @@ class Settings(SettingsFieldsMixin):
1900
1793
  )
1901
1794
  # Ensure that settings that have not been marked as "set" before are still so
1902
1795
  # after we have updated their value above
1903
- settings.__fields_set__.intersection_update(self.__fields_set__)
1796
+ with warnings.catch_warnings():
1797
+ warnings.simplefilter(
1798
+ "ignore", category=pydantic.warnings.PydanticDeprecatedSince20
1799
+ )
1800
+ settings.__fields_set__.intersection_update(self.__fields_set__)
1904
1801
  return settings
1905
1802
 
1906
1803
  def hash_key(self) -> str:
@@ -1912,7 +1809,7 @@ class Settings(SettingsFieldsMixin):
1912
1809
  return str(hash(tuple((key, value) for key, value in env_variables.items())))
1913
1810
 
1914
1811
  def to_environment_variables(
1915
- self, include: Iterable[Setting] = None, exclude_unset: bool = False
1812
+ self, include: Optional[Iterable[Setting]] = None, exclude_unset: bool = False
1916
1813
  ) -> Dict[str, str]:
1917
1814
  """
1918
1815
  Convert the settings object to environment variables.
@@ -1936,7 +1833,7 @@ class Settings(SettingsFieldsMixin):
1936
1833
  set_keys = {
1937
1834
  # Collect all of the "set" keys and cast to `Setting` objects
1938
1835
  SETTING_VARIABLES[key]
1939
- for key in self.dict(exclude_unset=True)
1836
+ for key in self.model_dump(exclude_unset=True)
1940
1837
  }
1941
1838
  include.intersection_update(set_keys)
1942
1839
 
@@ -1947,23 +1844,19 @@ class Settings(SettingsFieldsMixin):
1947
1844
  "Invalid type {type(key).__name__!r} for key in `include`."
1948
1845
  )
1949
1846
 
1950
- env = {
1951
- # Use `getattr` instead of `value_of` to avoid value callback resolution
1952
- key: getattr(self, key)
1953
- for key, setting in SETTING_VARIABLES.items()
1954
- if setting in include
1955
- }
1847
+ env: dict[str, Any] = self.model_dump(
1848
+ mode="json", include={s.name for s in include}
1849
+ )
1956
1850
 
1957
1851
  # Cast to strings and drop null values
1958
1852
  return {key: str(value) for key, value in env.items() if value is not None}
1959
1853
 
1960
- class Config:
1961
- frozen = True
1854
+ model_config = ConfigDict(frozen=True)
1962
1855
 
1963
1856
 
1964
1857
  # Functions to instantiate `Settings` instances
1965
1858
 
1966
- _DEFAULTS_CACHE: Settings = None
1859
+ _DEFAULTS_CACHE: Optional[Settings] = None
1967
1860
  _FROM_ENV_CACHE: Dict[int, Settings] = {}
1968
1861
 
1969
1862
 
@@ -2070,9 +1963,10 @@ class Profile(BaseModel):
2070
1963
 
2071
1964
  name: str
2072
1965
  settings: Dict[Setting, Any] = Field(default_factory=dict)
2073
- source: Optional[Path]
1966
+ source: Optional[Path] = None
1967
+ model_config = ConfigDict(extra="ignore", arbitrary_types_allowed=True)
2074
1968
 
2075
- @validator("settings", pre=True)
1969
+ @field_validator("settings", mode="before")
2076
1970
  def map_names_to_settings(cls, value):
2077
1971
  return validate_settings(value)
2078
1972
 
@@ -2109,9 +2003,6 @@ class Profile(BaseModel):
2109
2003
  changed.append((setting, setting.deprecated_renamed_to))
2110
2004
  return changed
2111
2005
 
2112
- class Config:
2113
- arbitrary_types_allowed = True
2114
-
2115
2006
 
2116
2007
  class ProfilesCollection:
2117
2008
  """ "
@@ -2266,26 +2157,6 @@ class ProfilesCollection:
2266
2157
  )
2267
2158
 
2268
2159
 
2269
- def _handle_removed_flags(
2270
- profile_name: str, settings: Dict[str, Any]
2271
- ) -> Dict[str, Any]:
2272
- to_remove = [name for name in settings if name in REMOVED_EXPERIMENTAL_FLAGS]
2273
-
2274
- for name in to_remove:
2275
- warnings.warn(
2276
- (
2277
- f"Experimental flag {name!r} has been removed, please "
2278
- f"update your {profile_name!r} profile."
2279
- ),
2280
- UserWarning,
2281
- stacklevel=3,
2282
- )
2283
-
2284
- settings.pop(name)
2285
-
2286
- return settings
2287
-
2288
-
2289
2160
  def _read_profiles_from(path: Path) -> ProfilesCollection:
2290
2161
  """
2291
2162
  Read profiles from a path into a new `ProfilesCollection`.
@@ -2304,7 +2175,6 @@ def _read_profiles_from(path: Path) -> ProfilesCollection:
2304
2175
 
2305
2176
  profiles = []
2306
2177
  for name, settings in raw_profiles.items():
2307
- settings = _handle_removed_flags(name, settings)
2308
2178
  profiles.append(Profile(name=name, settings=settings, source=path))
2309
2179
 
2310
2180
  return ProfilesCollection(profiles, active=active_profile)
@@ -2321,13 +2191,20 @@ def _write_profiles_to(path: Path, profiles: ProfilesCollection) -> None:
2321
2191
  return path.write_text(toml.dumps(profiles.to_dict()))
2322
2192
 
2323
2193
 
2324
- def load_profiles() -> ProfilesCollection:
2194
+ def load_profiles(include_defaults: bool = True) -> ProfilesCollection:
2325
2195
  """
2326
- Load all profiles from the default and current profile paths.
2196
+ Load profiles from the current profile path. Optionally include profiles from the
2197
+ default profile path.
2327
2198
  """
2328
- profiles = _read_profiles_from(DEFAULT_PROFILES_PATH)
2199
+ default_profiles = _read_profiles_from(DEFAULT_PROFILES_PATH)
2200
+
2201
+ if not include_defaults:
2202
+ if not PREFECT_PROFILES_PATH.value().exists():
2203
+ return ProfilesCollection([])
2204
+ return _read_profiles_from(PREFECT_PROFILES_PATH.value())
2329
2205
 
2330
2206
  user_profiles_path = PREFECT_PROFILES_PATH.value()
2207
+ profiles = default_profiles
2331
2208
  if user_profiles_path.exists():
2332
2209
  user_profiles = _read_profiles_from(user_profiles_path)
2333
2210
 
@@ -2352,10 +2229,10 @@ def load_current_profile():
2352
2229
  This will _not_ include settings from the current settings context. Only settings
2353
2230
  that have been persisted to the profiles file will be saved.
2354
2231
  """
2355
- from prefect.context import SettingsContext
2232
+ import prefect.context
2356
2233
 
2357
2234
  profiles = load_profiles()
2358
- context = SettingsContext.get()
2235
+ context = prefect.context.get_settings_context()
2359
2236
 
2360
2237
  if context:
2361
2238
  profiles.set_active(context.profile.name)