@@ -317,15 +317,25 @@ Once you have your `.env` file filled with variables, *pydantic* supports loadin
317
317
1 . Setting the ` env_file ` (and ` env_file_encoding ` if you don't want the default encoding of your OS) on ` model_config `
318
318
in the ` BaseSettings ` class:
319
319
320
- ``` py test="skip" lint="skip"
320
+ ``` py hl_lines="4 5"
321
+ from pydantic_settings import BaseSettings, SettingsConfigDict
322
+
323
+
321
324
class Settings (BaseSettings ):
322
325
model_config = SettingsConfigDict(env_file = ' .env' , env_file_encoding = ' utf-8' )
323
326
```
324
327
325
328
2 . Instantiating the ` BaseSettings ` derived class with the ` _env_file ` keyword argument
326
329
(and the ` _env_file_encoding ` if needed):
327
330
328
- ``` py test="skip" lint="skip"
331
+ ``` py hl_lines="8"
332
+ from pydantic_settings import BaseSettings, SettingsConfigDict
333
+
334
+
335
+ class Settings (BaseSettings ):
336
+ model_config = SettingsConfigDict(env_file = ' .env' , env_file_encoding = ' utf-8' )
337
+
338
+
329
339
settings = Settings(_env_file = ' prod.env' , _env_file_encoding = ' utf-8' )
330
340
```
331
341
@@ -347,7 +357,10 @@ while `.env` would be ignored.
347
357
If you need to load multiple dotenv files, you can pass multiple file paths as a tuple or list. The files will be
348
358
loaded in order, with each file overriding the previous one.
349
359
350
- ``` py test="skip" lint="skip"
360
+ ``` py
361
+ from pydantic_settings import BaseSettings, SettingsConfigDict
362
+
363
+
351
364
class Settings (BaseSettings ):
352
365
model_config = SettingsConfigDict(
353
366
# `.env.prod` takes priority over `.env`
@@ -381,7 +394,10 @@ Once you have your secret files, *pydantic* supports loading it in two ways:
381
394
382
395
1 . Setting the ` secrets_dir ` on ` model_config ` in a ` BaseSettings ` class to the directory where your secret files are stored.
383
396
384
- ``` py test="skip" lint="skip"
397
+ ``` py hl_lines="4 5 6 7"
398
+ from pydantic_settings import BaseSettings, SettingsConfigDict
399
+
400
+
385
401
class Settings (BaseSettings ):
386
402
model_config = SettingsConfigDict(secrets_dir = ' /var/run' )
387
403
@@ -390,7 +406,7 @@ class Settings(BaseSettings):
390
406
391
407
2 . Instantiating the ` BaseSettings ` derived class with the ` _secrets_dir ` keyword argument:
392
408
393
- ``` py test="skip" lint="skip"
409
+ ```
394
410
settings = Settings(_secrets_dir='/var/run')
395
411
```
396
412
@@ -413,7 +429,10 @@ and using secrets in Docker see the official
413
429
414
430
First, define your ` Settings ` class with a ` SettingsConfigDict ` that specifies the secrets directory.
415
431
416
- ``` py test="skip" lint="skip"
432
+ ``` py hl_lines="4 5 6 7"
433
+ from pydantic_settings import BaseSettings, SettingsConfigDict
434
+
435
+
417
436
class Settings (BaseSettings ):
418
437
model_config = SettingsConfigDict(secrets_dir = ' /run/secrets' )
419
438
0 commit comments