Chapter 4: Managing Pydantic Data Models in FastAPI

This chapter will cover in more detail the definition of a data model with Pydantic, the underlying data validation library used by FastAPI. We'll explain how to implement variations of the same model without repeating the same code again and again, thanks to class inheritance. Finally, we'll show how to implement custom data validation logic into Pydantic models.

In this chapter, we're going to cover the following main topics:

  • Defining models and their field types with Pydantic
  • Creating model variations with class inheritance
  • Adding custom data validation with Pydantic
  • Working with Pydantic objects

Technical requirements

To run the code examples, you'll need a Python virtual environment, ...

Get Building Data Science Applications with FastAPI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.