Ram consumed by single query in Postgres using SqlAlchemy
You can turn on "log_statement_stats", and look at the 'max resident size' line from the log file (or set client_min_messages TO log;).

Is is a pretty crummy interface, and the number it gives is the high water mark for the connection, so you would have to run each statement in a separate connection while testing it.