@@ -313,7 +313,7 @@ print(Settings().model_dump())
313
313
1 . Sub model has to inherit from ` pydantic.BaseModel ` , Otherwise ` pydantic-settings ` will initialize sub model,
314
314
collects values for sub model fields separately, and you may get unexpected results.
315
315
316
- 1 . Sub model has to inherit from ` pydantic.BaseModel ` , Otherwise ` pydantic-settings ` will initialize sub model,
316
+ 2 . Sub model has to inherit from ` pydantic.BaseModel ` , Otherwise ` pydantic-settings ` will initialize sub model,
317
317
collects values for sub model fields separately, and you may get unexpected results.
318
318
319
319
` env_nested_delimiter ` can be configured via the ` model_config ` as shown above, or via the
@@ -389,29 +389,25 @@ Once you have your `.env` file filled with variables, *pydantic* supports loadin
389
389
390
390
1 . Setting the ` env_file ` (and ` env_file_encoding ` if you don't want the default encoding of your OS) on ` model_config `
391
391
in the ` BaseSettings ` class:
392
+ ```` py hl_lines="4 5"
393
+ from pydantic_settings import BaseSettings, SettingsConfigDict
392
394
393
- ``` py hl_lines="4 5"
394
- from pydantic_settings import BaseSettings, SettingsConfigDict
395
-
396
-
397
- class Settings (BaseSettings ):
398
- model_config = SettingsConfigDict(env_file = ' .env' , env_file_encoding = ' utf-8' )
399
- ```
400
395
396
+ class Settings (BaseSettings ):
397
+ model_config = SettingsConfigDict(env_file = ' .env' , env_file_encoding = ' utf-8' )
398
+ ````
401
399
2 . Instantiating the ` BaseSettings ` derived class with the ` _env_file ` keyword argument
402
400
(and the ` _env_file_encoding ` if needed):
401
+ ```` py hl_lines="8"
402
+ from pydantic_settings import BaseSettings, SettingsConfigDict
403
403
404
- ``` py hl_lines="8"
405
- from pydantic_settings import BaseSettings, SettingsConfigDict
406
-
407
-
408
- class Settings (BaseSettings ):
409
- model_config = SettingsConfigDict(env_file = ' .env' , env_file_encoding = ' utf-8' )
410
404
405
+ class Settings (BaseSettings ):
406
+ model_config = SettingsConfigDict(env_file = ' .env' , env_file_encoding = ' utf-8' )
411
407
412
- settings = Settings(_env_file = ' prod.env' , _env_file_encoding = ' utf-8' )
413
- ```
414
408
409
+ settings = Settings(_env_file = ' prod.env' , _env_file_encoding = ' utf-8' )
410
+ ````
415
411
In either case, the value of the passed argument can be any valid path or filename, either absolute or relative to the
416
412
current working directory. From there, * pydantic* will handle everything for you by loading in your variables and
417
413
validating them.
@@ -476,22 +472,19 @@ super_secret_database_password
476
472
Once you have your secret files, * pydantic* supports loading it in two ways:
477
473
478
474
1 . Setting the ` secrets_dir ` on ` model_config ` in a ` BaseSettings ` class to the directory where your secret files are stored.
475
+ ```` py hl_lines="4 5 6 7"
476
+ from pydantic_settings import BaseSettings, SettingsConfigDict
479
477
480
- ``` py hl_lines="4 5 6 7"
481
- from pydantic_settings import BaseSettings, SettingsConfigDict
482
-
483
-
484
- class Settings (BaseSettings ):
485
- model_config = SettingsConfigDict(secrets_dir = ' /var/run' )
486
478
487
- database_password: str
488
- ```
479
+ class Settings ( BaseSettings ):
480
+ model_config = SettingsConfigDict( secrets_dir = ' /var/run ' )
489
481
482
+ database_password: str
483
+ ````
490
484
2 . Instantiating the ` BaseSettings ` derived class with the ` _secrets_dir ` keyword argument:
491
-
492
- ```
493
- settings = Settings(_secrets_dir='/var/run')
494
- ```
485
+ ````
486
+ settings = Settings(_secrets_dir='/var/run')
487
+ ````
495
488
496
489
In either case, the value of the passed argument can be any valid directory, either absolute or relative to the
497
490
current working directory. ** Note that a non existent directory will only generate a warning** .
0 commit comments