Ask HN: Pydantic has too much deprecation. Why is it popular?

7 points by behnamoh ↗ HN
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 ] thread
Is the complaint that v1 and v2 are different? Why are you learning v1 at all?
I'm not learning v1. I'm complaining about the constant deprecation of things that already worked. If it's working, why change it?

I 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...

I spent the last month or so migrating over a hundred models to v2 and it has been a pretty pleasant experience. Free performance gains and a lot more clear/readable models. On top of this interacting with complex nested root models is now much more organized and `.model_validate(data).model_dump()` always works whereas before I had to do a lot of strange json loading and dumping surrounding instantiation for certain models.

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.

We've had one very small change within V2, related solely to typing. I think you're overblowing this.
Pydantic's v1 to v2 was due to a full rewrite/port to Rust. Lots of depreciations are expected in that instance, and it's not common for a popular library and will likely not happen again.

Deprecations are healthy, otherwise you get technical debt which harms development.

I like Pydantic, but it is true it broke too many things.

It is not the same, but typeguard has runtime typechecks with the @typechecked function annotation. Mypy checks help as well.

From my perspective a large factor contributing to its popularity is because of FastAPIs native integration. V2 has broken so much behavior, and the library is generally fragile and slow. Credit where it is due, it is a great library that has done a lot to bring python types to more projects, but there are better solutions out there now.

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.

That's simply not true. It's much faster than most similar libraries, 16x faster than DRF, 30x faster than Cerberus.

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 author here.

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.