---
title: "💭 Models - Pydantic"
description: "!https://docs.pydantic.dev/latest/concepts/models/#rebuilding-model-schema"
date: 2025-01-28
published: true
tags:
  - python
  - pydantic
  - thought
template: link
---


<div class="embed-card embed-card-external">
  <a href="https://docs.pydantic.dev/latest/concepts/models/#rebuilding-model-schema" class="embed-card-link" target="_blank" rel="noopener noreferrer">
    <div class="embed-card-image">
      <img src="https://pydantic.dev/docs/og/validation/latest/concepts/models.png" alt="Models" loading="lazy">
    </div>
    <div class="embed-card-content">
      <div class="embed-card-title">Models</div>
      <div class="embed-card-meta">Pydantic Docs &middot; docs.pydantic.dev</div>
    </div>
  </a>
</div>


I came accross from_attributes today it allows creation of pydantic models from objects such as a sqlalchemy  `Base` Model or while nesting pydantic models.  I believe in the past I have ran into some inconsistencies with nesting pydantic models and I'll bet one had from_attributes set and another did not.

> Arbitrary class instances¶
> _(Formerly known as "ORM Mode"/from_orm)._
> 
> Pydantic models can also be created from arbitrary class instances by reading the instance > attributes corresponding to the model field names. One common application of this functionality is integration with object-relational mappings (ORMs).
> 
> To do this, set the from_attributes config value to True (see the documentation on Configuration for more details).
>
> The example here uses SQLAlchemy, but the same approach should work for any ORM.

!!! note

    This post is a <a href="/thoughts/" class="wikilink" data-title="Thoughts" data-description="These are generally my thoughts on a web page or some sort of url, except a rare few don&#39;t have a link. These are dual published off of my..." data-date="2024-04-01">thought</a>. It's a short note that I make
    about someone else's content online <a href="/tags/thoughts/" class="hashtag-tag" data-tag="thoughts" data-count=2 data-reading-time=3 data-reading-time-text="3 minutes">#thoughts</a>
