what are the pros and cons with pydantic models vs data classes? i like the runtime validation in pydantic models.
the pattern i landed on is that 1) only use primitive data types such as str, int, pydantic models and pandas dataframes to present data. 2) no classes with methods, no polymorphism, only use module functions.
martinky24|1 year ago
The power of Pydantic models comes with benefits in terms of what they're able to do out of the box. But this comes at a significant cost of speed, which does matter for some applications. There are plenty of applications where it simply doesn't make sense to validate types every time you stand up a class.
Sure you can turn some of that off with Pydantic, etc, etc, but the fact that dataclasses don't require a third party install and are efficient and easy out of the box makes them useful and non-duplicative.