I've found implementations here on PR, but they all contain disruptive changes that make Pydentic 2 mandatory or define new functions without tests. I propose to implement this support in a non-destructive and unobtrusive way, while maintaining as much backward compatibility as possible.
All you need is to set extras in fastapi-utils or pin the pydantic dependency in your project:
for v1 use fastapi-utils = "^0.3", or pydantic = "^1.10", or both,
for v2 use fastapi-utils = { version = "^0.3", extras = ["pydantic_settings"] }, or pydantic = "^2.0", or both.
Tested in my projects with Pydantic v1 on Python 3.10, and Pydantic v2 on Python 3.11 & 3.12.
I liked it very much, however in the new version (soon to be released 0.6.0) we will support pydantic 2.0, leave this around so I can test it to version 1.0
I've found implementations here on PR, but they all contain disruptive changes that make Pydentic 2 mandatory or define new functions without tests. I propose to implement this support in a non-destructive and unobtrusive way, while maintaining as much backward compatibility as possible.
All you need is to set
extras
infastapi-utils
or pin thepydantic
dependency in your project:fastapi-utils = "^0.3"
, orpydantic = "^1.10"
, or both,fastapi-utils = { version = "^0.3", extras = ["pydantic_settings"] }
, orpydantic = "^2.0"
, or both.Tested in my projects with Pydantic v1 on Python 3.10, and Pydantic v2 on Python 3.11 & 3.12.
Fix #276