Does Pydantic Replace Dataclasses in Python?

preview_player
Показать описание
Today we learn about Pydantic and discuss whether it replaces Python's dataclasses or not.

◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚

🌐 Social Media & Contact 🌐

Timestamps:
(0:00) Intro
(0:20) Pydantic Fundamentals
(3:16) Validating Fields
(9:43) Root Validators
(12:55) Parsing JSON Data
(16:38) Outro
Рекомендации по теме
Комментарии
Автор

The nested if's can easily be turned into a sequence of guard clauses, which should ease the burden on the eyes and boost the understanding of what the code is supposed to do. Just a hint... :)

dariuszspiewak
Автор

At 8:32 you don't need to define a validator for age and score, instead using PositiveFloat from pydantic as type for these fields does the same.

felicytatomaszewska
Автор

No, it doesn't! They are completely different things. Pydantic is a validation and serialization library, dataclasses is essentially a code generation tool for classes, which help you avoid boilerplate when defining classes. They have totally different features, and are completely different things!

If you would use pydantic instead of dataclasses, your code would be way slower. You can't use dataclasses instead of pydantic, because it doesn't provide serialization and you can't really validate user input with it.

wlkmn
Автор

i have a doubt, how to destructor the JSON file, if we have nested objects inside an array ?

gnani-resj
Автор

Hey can we put constructor inside? Tried it but when I do the validators are not invoked.

meisj
Автор

Hello, can someone explain to me, why there is a @classmethod before defining a validator? I think it's optional, because the documentation on pydantic does not mention that. I'm just curious why it is there

pucek
Автор

for root_validators

the "values" is a pydantic keyword? how does it know that "email" is one of the fields?

more dataclasses with functions inside the dataclass!

irmdev
Автор

What could we do if someone makes an assigment to an attribute after the instance? As far as i understand, custom validations are not executed when that happens.

DanielRodriguez-elgb
Автор

can we have more advance video on this ? bdw Kudos for this !!😉

jaypatel
Автор

Amazing and clear explanation as usual! However, one criticism I have is regarding the speed of delivery of information. Nonetheless, we appreciate your abundant knowledge

zakariaabderrahmanesadelao
Автор

Not sure what I am doing wrong but the code does not work for me. Using Python 3.10.7 64-bit

stevenwilson
Автор

So are you the guy that writes the chatgpt produced codes, because you are amazing. Dammn

nithinjp
Автор

thanks this helped me out I really need to start using this!

kosmonautofficial
Автор

Great explanations! Thanks! Your videos are very useful

eugenung
Автор

I cried when i saw this nasted if's in 7:30

szymonzywko