Matt Eva
Dec 13, 2023

--

Great Article, Eleanor! This was always one of the trickiest problems to solve with complex data models and SQLAlchemy.

I've also found serialize_only to be very helpful. It allows you to specify which exact fields from related pieces of data you want to send back - it also blocks all non-specified fields (if memory serves correctly), which should help solve the recursion problem.

It also makes it easy to filter out sensitive information that shouldn't be return from an API call, or unnecessary data that you just don't need.

There's a little bit of documentation about this here: https://pypi.org/project/SQLAlchemy-serializer/

Cheers!

--

--

Matt Eva
Matt Eva

Written by Matt Eva

I write about coding, web development, and various other programming topics!

Responses (1)