Ask HN: Pydantic has too much deprecation. Why is it popular?
Almost all tutorials I see online (and ChatGPT's knowledge base) teach you Pydantic v1. There are numerous things that are deprecated during transition to v2 (@root_validator, @validator, using 'always', etc. are all gone now.). I even found a code example on its Github from November 2023 which now throws an error, saying that FieldValidationInfo is deprecated now, use <new_thing> instead...
I wanted to use something to validate user inputs to my API, but getting Pydantic right and then keeping it updated has been too much unnecessary work, which makes me wonder if you have also faced this problem and what your solution is?
10 comments
[ 3.2 ms ] story [ 33.8 ms ] threadI get that major transitions are difficult, but there are also numerous small deprecations. Nov. 2023 was 2-3 months ago. Yet, code written then throws deprecation warnings now...
The changes are overall good and the library has matured into something that seems like it will be stable for a long time to come.
Spend an hour with this https://www.youtube.com/watch?v=ok8bF8M7gjk and never look back.
Also https://www.youtube.com/watch?v=4yUXPZGhIX8 specifically for migrating from v1 to v2.
Deprecations are healthy, otherwise you get technical debt which harms development.
[0]: https://github.com/pydantic/pydantic/discussions/6337
It is not the same, but typeguard has runtime typechecks with the @typechecked function annotation. Mypy checks help as well.
I’d strongly recommend looking into msgspec. It is a much faster alternative and is largely “correct” in its implementation. It uses all of the python native type annotations without many hacks. Really it is much much faster and can actually be used for performance sensitive python workloads that need strong typing.
Msgspec is impressive in some ways, but there are good reasons to use Pydantic instead - for a start msgspec is written in a non-memory safe language by (mostly) one person, and is less widely tested than Pydantic.
Pydantic won't change again significantly, so it won't be any effort to keep it up-to-date.
There were good reasons to make all the changes made in the V1->V2 upgrade, I think those are pretty clear.
I think Pydantic is popular because of it's extremely flexible/powerful while also being intuitive to get started with.