Parsing data with Pydantic - A Python short by Michael Kennedy

preview_player
Показать описание
Quickly learn to use Pydantic to parse JSON data from a file or API. In just 5 minutes, you'll see how to take invalid data in JSON format, model it with Pydantic classes we create, and automatically detect errors and convert data to valid inputs when possible.

Enjoy this Python short "quick hit" video by Michael Kennedy, a Python Software Fellow and host of the Talk Python To Me podcast.

▬ CODE ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

▬ Chapters ▬▬▬▬▬▬▬▬▬▬▬▬

0:00 - Introduction
0:21 - Your job: API developer
0:50 - What is Pydantic?
1:05 - The data we get with our "api"
2:17 - Modeling the data with classes
3:34 - Installing Pydantic
4:14 - Passing data to our Pydantic models
4:35 - Catching invalid data with Pydantic
5:20 - Seeing the validated and converted model result
7:08 - Conclusion

▬ More Videos ▬▬▬▬▬▬▬▬▬▬▬▬

▬ Dive deeper ▬▬▬▬▬▬▬▬▬▬▬▬

Рекомендации по теме
Комментарии
Автор

Hi Michael. I just wanted to say thanks for all the content you've provided over the years. I listen to your Talk Python to Me podcast all the time! I've literally listened to some episodes 4 or 5 times just to keep extracting bits of information out of it. Keep up the good work and always remember that there are thousands (hundred of thousands!?) of people out there who are positively impacted by your contributions!

argiebargie
Автор

This is really well explained. The motivation was really helpful. It's a great way to teach and provide context.

wryltxw
Автор

That was great Michael - a nice and succinct little intro. If you're going to print to console a lot, the print method from rich would give you nicely readable output, although you would then possibly need to divert attention from your subject to discuss what rich does.

rooijan
Автор

Very helpful and friendly introductory tutorial about Pydantic.
Thank you! Also, I really like your teaching style.

silkogelman
Автор

This is awesome!!
Looking forward to this series.

albertulysses
Автор

Wow that was informative!
Here from your Twitter post.

murjoshua
Автор

Just wow...the way you explain is just wow 😮

Travellife
Автор

I really liked this Michael. I hope these get popular so you keep making them.

One question, why ** before the data? I don't understand args/kwargs but I have a hunch the **data has something to do with that.

aasd
Автор

Hope these are a success. I got a lot out of this one as I’m going through my Strava API JSON activities to do some analysis right now.

antlister
Автор

This guy should do a cameo in Portlandia! 😂😂😂😂😂

aftalavera
Автор

This guy went mad! He went from Mastodon to Mastodon by invite!

aftalavera
Автор

At first you declared rides as an empty list by default. Is it OK to have a mutable type here?

fastrockstar
Автор

Thanks for the video, but really what I was looking for is how to get data from DB using pydantic. LIke have few classes with Foreign keys and so on and how to work with that?
That's the problem I encounter and unfortunately can't find the answer.

vladislavmikhailov
Автор

Hi, one issue I saw just copying/testing was: error: type object is not subscriptable (rides: list[int] = []). So did you get this error? int is not iterable.
I fixed it with "from typing import List" ... "rides: List[int] = []"

mikecmw
Автор

A question, if I take a BaseModel child class instance (like instance of User), and I pass it into some function that expects dict instead of User, will pydantic automatically try to coerce User to a dict?

If yes, what’s the limit of this coercion. What I mean is if User could be coerced into another class MyUser, would pydantic do that too or does it only work with python native things like int str etc.

astronemir
Автор

I feel like Pydantic makes Python more Java

mertyertugrul
Автор

not useful for other than absolute beginners. :(

Slackero