It&#x27;s sad that ORMs are always restrictive and raw SQL can&#x27;t be safely and easily modified. I&#x27;d always wished for a library that one could <i>just</i> write SQL, and the library could do the transformations.<p>I.e. one writes plain SQL strings, but they&#x27;re parsed under the hood, so AST transformations can be applied, like adding extra WHERE clauses conditionally or applying LIMIT.<p>Sadly, I haven&#x27;t found any good Python SQL parsing library. That was long time ago, though - maybe someone had written one already.