1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to FastAPI

Connected

Exercise

Pydantic model

You've been asked to create an API endpoint that manages items in inventory. To get started, create a Pydantic model for Items that has attributes name, quantity, and expiration.

Instructions

100 XP
  • Import date from datetime and BaseModel from pydantic.
  • Create a Pydantic model for Item.
  • Fill in the following fields correctly: name (string), quantity (integer, optional, default 0), and expiration (date, optional, default None).