prefect.settings
Prefect settings are defined using BaseSettings
from pydantic_settings
. BaseSettings
can load setting values
from system environment variables and each additionally specified env_file
.
The recommended user-facing way to access Prefect settings at this time is to import specific setting objects directly,
like from prefect.settings import PREFECT_API_URL; print(PREFECT_API_URL.value())
.
Importantly, we replace the callback
mechanism for updating settings with an "after" model_validator that updates dependent settings.
After https://github.com/pydantic/pydantic/issues/9789 is resolved, we will be able to define context-aware defaults
for settings, at which point we will not need to use the "after" model_validator.
Profile
Bases: BaseModel
A user profile containing settings.
Source code in src/prefect/settings/profiles.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
to_environment_variables()
Convert the profile settings to a dictionary of environment variables.
Source code in src/prefect/settings/profiles.py
59 60 61 62 63 64 65 |
|
ProfilesCollection
" A utility class for working with a collection of profiles.
Profiles in the collection must have unique names.
The collection may store the name of the active profile.
Source code in src/prefect/settings/profiles.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
active_profile: Optional[Profile]
property
Retrieve the active profile in this collection.
names: Set[str]
property
Return a set of profile names in this collection.
add_profile(profile)
Add a profile to the collection.
If the profile name already exists, an exception will be raised.
Source code in src/prefect/settings/profiles.py
170 171 172 173 174 175 176 177 178 179 180 181 |
|
remove_profile(name)
Remove a profile from the collection.
Source code in src/prefect/settings/profiles.py
183 184 185 186 187 |
|
set_active(name, check=True)
Set the active profile name in the collection.
A null value may be passed to indicate that this collection does not determine the active profile.
Source code in src/prefect/settings/profiles.py
118 119 120 121 122 123 124 125 126 127 |
|
to_dict()
Convert to a dictionary suitable for writing to disk.
Source code in src/prefect/settings/profiles.py
204 205 206 207 208 209 210 211 212 213 214 |
|
update_profile(name, settings, source=None)
Add a profile to the collection or update the existing on if the name is already present in this collection.
If updating an existing profile, the settings will be merged. Settings can
be dropped from the existing profile by setting them to None
in the new
profile.
Returns the new profile object.
Source code in src/prefect/settings/profiles.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
without_profile_source(path)
Remove profiles that were loaded from a given path.
Returns a new collection.
Source code in src/prefect/settings/profiles.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
Setting
Mimics the old Setting object for compatibility with existing code.
Source code in src/prefect/settings/legacy.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
Settings
Bases: PrefectBaseSettings
Settings for Prefect using Pydantic settings.
See https://docs.pydantic.dev/latest/concepts/pydantic_settings
Source code in src/prefect/settings/models/root.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|
copy_with_update(updates=None, set_defaults=None, restore_defaults=None)
Create a new Settings object with validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
updates
|
Optional[Mapping[Setting, Any]]
|
A mapping of settings to new values. Existing values for the given settings will be overridden. |
None
|
set_defaults
|
Optional[Mapping[Setting, Any]]
|
A mapping of settings to new default values. Existing values for the given settings will only be overridden if they were not set. |
None
|
restore_defaults
|
Optional[Iterable[Setting]]
|
An iterable of settings to restore to their default values. |
None
|
Returns:
Type | Description |
---|---|
Self
|
A new Settings object. |
Source code in src/prefect/settings/models/root.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
emit_warnings()
More post-hoc validation of settings, including warnings for misconfigurations.
Source code in src/prefect/settings/models/root.py
245 246 247 248 249 250 |
|
hash_key()
Return a hash key for the settings object. This is needed since some settings may be unhashable, like lists.
Source code in src/prefect/settings/models/root.py
321 322 323 324 325 326 327 |
|
post_hoc_settings()
refactor on resolution of https://github.com/pydantic/pydantic/issues/9789
we should not be modifying pydantic_fields_set directly, but until we can define dependencies between defaults in a first-class way, we need clean up post-hoc default assignments to keep set/unset fields correct after instantiation.
Source code in src/prefect/settings/models/root.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
get_current_settings()
Returns a settings object populated with values from the current settings context or, if no settings context is active, the environment.
Source code in src/prefect/settings/context.py
10 11 12 13 14 15 16 17 18 19 20 21 |
|
load_current_profile()
Load the current profile from the default and current profile paths.
This will not include settings from the current settings context. Only settings that have been persisted to the profiles file will be saved.
Source code in src/prefect/settings/profiles.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
|
load_profile(name)
Load a single profile by name.
Source code in src/prefect/settings/profiles.py
343 344 345 346 347 348 349 350 351 |
|
load_profiles(include_defaults=True)
Load profiles from the current profile path. Optionally include profiles from the default profile path.
Source code in src/prefect/settings/profiles.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
save_profiles(profiles)
Writes all non-default profiles to the current profiles path.
Source code in src/prefect/settings/profiles.py
333 334 335 336 337 338 339 340 |
|
temporary_settings(updates=None, set_defaults=None, restore_defaults=None)
Temporarily override the current settings by entering a new profile.
See Settings.copy_with_update
for details on different argument behavior.
Examples:
>>> from prefect.settings import PREFECT_API_URL
>>>
>>> with temporary_settings(updates={PREFECT_API_URL: "foo"}):
>>> assert PREFECT_API_URL.value() == "foo"
>>>
>>> with temporary_settings(set_defaults={PREFECT_API_URL: "bar"}):
>>> assert PREFECT_API_URL.value() == "foo"
>>>
>>> with temporary_settings(restore_defaults={PREFECT_API_URL}):
>>> assert PREFECT_API_URL.value() is None
>>>
>>> with temporary_settings(set_defaults={PREFECT_API_URL: "bar"})
>>> assert PREFECT_API_URL.value() == "bar"
>>> assert PREFECT_API_URL.value() is None
Source code in src/prefect/settings/context.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
update_current_profile(settings)
Update the persisted data for the profile currently in-use.
If the profile does not exist in the profiles file, it will be created.
Given settings will be merged with the existing settings as described in
ProfilesCollection.update_profile
.
Returns:
Type | Description |
---|---|
Profile
|
The new profile. |
Source code in src/prefect/settings/profiles.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|