@@ -183,22 +183,22 @@ See also: :ref:`configuration-envs-interpolation`.
183
183
Loading from a Pydantic settings
184
184
--------------------------------
185
185
186
- ``Configuration `` provider can load configuration from a ``pydantic `` settings object using the
186
+ ``Configuration `` provider can load configuration from a ``pydantic_settings.BaseSettings `` object using the
187
187
:py:meth: `Configuration.from_pydantic ` method:
188
188
189
189
.. literalinclude :: ../../examples/providers/configuration/configuration_pydantic.py
190
190
:language: python
191
191
:lines: 3-
192
- :emphasize-lines: 31
192
+ :emphasize-lines: 32
193
193
194
- To get the data from pydantic settings ``Configuration `` provider calls `` Settings.dict () `` method.
194
+ To get the data from pydantic settings ``Configuration `` provider calls its `` model_dump () `` method.
195
195
If you need to pass an argument to this call, use ``.from_pydantic() `` keyword arguments.
196
196
197
197
.. code-block :: python
198
198
199
199
container.config.from_pydantic(Settings(), exclude = {" optional" })
200
200
201
- Alternatively, you can provide a ``pydantic `` settings object over the configuration provider argument. In that case,
201
+ Alternatively, you can provide a ``pydantic_settings.BaseSettings `` object over the configuration provider argument. In that case,
202
202
the container will call ``config.from_pydantic() `` automatically:
203
203
204
204
.. code-block :: python
@@ -215,18 +215,23 @@ the container will call ``config.from_pydantic()`` automatically:
215
215
216
216
.. note ::
217
217
218
- ``Dependency Injector `` doesn't install ``pydantic `` by default.
218
+ ``Dependency Injector `` doesn't install ``pydantic-settings `` by default.
219
219
220
220
You can install the ``Dependency Injector `` with an extra dependency::
221
221
222
- pip install dependency-injector[pydantic ]
222
+ pip install dependency-injector[pydantic2 ]
223
223
224
- or install ``pydantic `` directly::
224
+ or install ``pydantic-settings `` directly::
225
225
226
- pip install pydantic
226
+ pip install pydantic-settings
227
227
228
228
*Don't forget to mirror the changes in the requirements file. *
229
229
230
+ .. note ::
231
+
232
+ For backward-compatibility, Pydantic v1 is still supported.
233
+ Passing ``pydantic.BaseSettings `` instances will work just as fine as ``pydantic_settings.BaseSettings ``.
234
+
230
235
Loading from a dictionary
231
236
-------------------------
232
237
0 commit comments