What is the meaning of pydantic models(schemas) in Python while building an API with FastAPI What is the meaning of pydantic models(schemas) in Python while building an API with FastAPI postgresql postgresql

What is the meaning of pydantic models(schemas) in Python while building an API with FastAPI


Pydantic schemas define the properties and types to validate some payload.

They act like a guard before you actually allow a service to fulfil a certain action (e.g. create a database object). I'm not sure if you're used to serializers, but it's pretty much the same thing except Pydantic and FastAPI integrate with newish Python 3 properties (see type checking) which makes it somewhat easier to achieve the things you used to do with framework builtins/libraries.

In your example UserCreate only requires a password and email address so inheritance makes your code more DRY.