Is it possible to load from attributes? #185
Unanswered
fabianoengler
asked this question in
Question
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Pydantic has a
from_attributes=True
[1] option I can pass to load models (or set that as a config) that causes the loaded values to be loaded with attribute access instead of field access (object.field
instead ofobject['field']
).This is pretty awesome because it allows me to load from almost any object type, since most objects will have attributes that can access, in particular this allows me to load from ORM objects (like SQLAlchemy), other pydantic models and dataclasses.
I've went through dataclass-wizard documentation and didn't find anything like that, I'm wondering if that's possible with dataclass-wizard and if not, if there are any plans to implement this in the future.
[1] https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_validate
Beta Was this translation helpful? Give feedback.
All reactions