Skip to content

Commit c2d44a7

Browse files
authored
add in-place reloading in docs (#316)
1 parent f1b82d8 commit c2d44a7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/index.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,3 +1514,39 @@ except ValidationError as exc_info:
15141514
For further information visit https://errors.pydantic.dev/2/v/missing
15151515
"""
15161516
```
1517+
1518+
1519+
## In-place reloading
1520+
1521+
In case you want to reload in-place an existing setting, you can do it by using its `__init__` method :
1522+
1523+
```py
1524+
import os
1525+
1526+
from pydantic import Field
1527+
1528+
from pydantic_settings import BaseSettings
1529+
1530+
1531+
class Settings(BaseSettings):
1532+
foo: str = Field('foo')
1533+
1534+
1535+
mutable_settings = Settings()
1536+
1537+
print(mutable_settings.foo)
1538+
#> foo
1539+
1540+
os.environ['foo'] = 'bar'
1541+
print(mutable_settings.foo)
1542+
#> foo
1543+
1544+
mutable_settings.__init__()
1545+
print(mutable_settings.foo)
1546+
#> bar
1547+
1548+
os.environ.pop('foo')
1549+
mutable_settings.__init__()
1550+
print(mutable_settings.foo)
1551+
#> foo
1552+
```

0 commit comments

Comments
 (0)