Support for (de-)serializing SQLAlchemy models
See original GitHub issueQuestion | Feature Request
Maybe I’m missing something obvious but I’m wondering whether there already is or if you can see in future support for creating schemata directly from SQLAlchemy models. Maybe in a similar way to the from pydantic.dataclasses import dataclass
decorator?
There exists a marshallow extension that does this quite nicely.
I’m especially interested in this in combination with FastAPI so maybe a plugin there is also an option @tiangolo?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
How to serialize SqlAlchemy result to JSON? - python
It allows you to create serializers to represent your model instances with support to relations and nested objects. Here is a truncated example...
Read more >Support for (de-)serializing SQLAlchemy models #491 - GitHub
A plug-in/package that integrates Pydantic with SQLAlchemy would indeed be quite nice. If it's based on Pydantic, it would automatically be supported by...
Read more >Part 1: Serializing SQLAlchemy Models as JSON - Medium
To add a serialization method have all your SQLAlchemy models inherit from an abstract base class. This base class defines the to_dict method ......
Read more >(De)serialization in SQLAlchemy - Xemedo
The serialization class automatically detects all fields in the model class and maps these fields on the serialization class.
Read more >SQLAthanor — SQLAthanor 0.7.0 documentation
SQLAthanor is a Python library that extends SQLAlchemy's fantastic Declarative ORM to provide easy-to-use record serialization/de-serialization with support for ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think this should be a separate package, happy to give my support and even run tests against it here so compatibility is maintained, but I don’t think it should be part of pydantic core.
If I can just clarify your observation in terms of SQLAlchemy’s approach, SQLAlchemy’s expression language is structurally as identical to real SQL as possible. The cognitive paradigm one must follow when writing SQLAlchemy queries is to think relationally, which is the same way that we think when we write SQL. IMO one should not be using a relational database if they don’t want to be thinking in terms of columns, rows, and joins. But there’s really no leap between “thinking in SQL” vs “thinking in Python” any more than there is if you were writing a SQL query for PostgreSQL but you were very used to writing them for Oracle, which has syntactical differences.