Skip to content

Commit

Permalink
add in-place reloading in docs (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrolin committed Jun 18, 2024
1 parent f1b82d8 commit c2d44a7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1514,3 +1514,39 @@ except ValidationError as exc_info:
For further information visit https://errors.pydantic.dev/2/v/missing
"""
```


## In-place reloading

In case you want to reload in-place an existing setting, you can do it by using its `__init__` method :

```py
import os

from pydantic import Field

from pydantic_settings import BaseSettings


class Settings(BaseSettings):
foo: str = Field('foo')


mutable_settings = Settings()

print(mutable_settings.foo)
#> foo

os.environ['foo'] = 'bar'
print(mutable_settings.foo)
#> foo

mutable_settings.__init__()
print(mutable_settings.foo)
#> bar

os.environ.pop('foo')
mutable_settings.__init__()
print(mutable_settings.foo)
#> foo
```

0 comments on commit c2d44a7

Please sign in to comment.