Modern APIs with FastAPI and Python Transcripts
Chapter: Modern language foundations
Lecture: Concept: Pydantic models
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
So you've seen how awesome pydantic types are. Let's just review real quickly how we create them.
0:05
We start by importing the base model, because that's our base class for all the types to create. We're gonna create an order derived from based model,
0:12
it has an item ID, which is an integer, and a created date, which is a datetime and a float and then optional list of integers.
0:20
And that's all we got to do. If we have some data we get from HTTP post to say our API or some other place we get some JSON data, a dictionary,
0:30
all you gotta do is pass it by keyword argument, and it does all the conversions that you saw. Make sure the list is there,
0:35
that it's a list of imagers, and if it's not there, it can be just the empty list. Super, super cool.