I don't have a compelling need for a framework. If I had the need for such a query, I would probably write a simple query to gather a superset of the candidates, or not, if it looked like most of the records would be in the set. Then I would write a Python program that would rank the candidate according to whatever. It could all be done in SQL, but Python would be quicker in elapsed time to a solution.
If this were a frequent run, I might do it purely in SQL, but not a framework, SQL is sufficiently high level that I dont see much of a gain.