Skip to main content
Real-world data rarely comes flat. An order has items. A user has an address. A company has employees. Pydantic handles this naturally.

Models inside models

Use one model as a field type in another:

Creating from dictionaries

The real power shows when parsing nested JSON or dictionaries:
Pydantic automatically creates the nested OrderItem model from the dictionary.

Lists of models

Handle collections of nested objects:
Output:

Optional nested models

Make nested models optional:

Deep nesting

You can nest as deep as needed:

Converting nested models

When you call model_dump(), nested models are converted too:

Common patterns

Reusing models across your codebase

Self-referencing models (trees)

Learn more

Practice & Exercises

To reinforce what you’ve learned, practice with these interactive notebooks:

Follow-Along Practice

Practice nesting models for complex and hierarchical data types, and converting models using .model_dump() and .model_dump_json().💻 VS Code | 🚀 Colab | 📥 Download

Practice Exercises

Test your knowledge with hands-on exercises modeling user profiles and address schemas using nested dictionary structures.💻 VS Code | 🚀 Colab | 📥 Download

What’s next?

You can now handle complex data structures. Next, let’s learn how to manage application configuration with Pydantic Settings.

Pydantic Settings

Learn how to manage environment-based application configuration with Pydantic Settings.