Return SQLAlchemy results as dicts instead of lists
The results look like tuples/lists, but they are actually a special Row
object (KeyedTuple
for SQLAlchemy < 1.4). Use the _asdict()
method to convert each row to a dict.
return [r._asdict() for r in results]
[{'campaign_id': 3, 'title': 'campaign title', 'status_count': 1},
{'campaign_id': 4, 'title': 'campaign title', 'status_count': 1}]
in Python 3.7 / SQLAlchemy 1.3.18 this works for me:
return [dict(r) for r in results]