Мой прием с использованием (слишком много?) словарей:
def serialize(_query):
#d = dictionary written to per row
#D = dictionary d is written to each time, then reset
#Master = dictionary of dictionaries; the id Key (int, unique from database) from D is used as the Key for the dictionary D entry in Master
Master = {}
D = {}
x = 0
for u in _query:
d = u.__dict__
D = {}
for n in d.keys():
if n != '_sa_instance_state':
D[n] = d[n]
x = d['id']
Master[x] = D
return Master
Работа с флягой (включая jsonify) и flask_sqlalchemy для вывода на печать в виде JSON.
Вызвать функцию с помощью jsonify (serialize ()).
Работает со всеми запросами SQLAlchemy, которые я пробовал до сих пор (работает SQLite3)