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.
0:02
Let's just review real quickly how we create them.
0:04
We start by importing the base model, because that's our base class
0:08
for all the types to create.
0:09
We're gonna create an order derived from based model,
0:11
it has an item ID,
0:13
which is an integer, and a created date,
0:14
which is a datetime and a float and then optional list of integers.
0:19
And that's all we got to do.
0:21
If we have some data we get from HTTP post to say our API
0:26
or some other place we get some JSON data, a dictionary,
0:29
all you gotta do is pass it by keyword argument,
0:31
and it does all the conversions that you saw.
0:33
Make sure the list is there,
0:34
that it's a list of imagers,
0:35
and if it's not there, it can be just the empty list. Super, super cool.