question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for (de-)serializing SQLAlchemy models

See original GitHub issue

Question | 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:closed
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
samuelcolvincommented, Apr 28, 2019

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.

1reaction
zzzeekcommented, Mar 4, 2021

I find when using SQLAlchemy you have to “think in sql” then reverse back to python.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found