I wrote up Using plain Jinja[1] or SQLAlchemy+Jinja[2] as complementary techniques. The post is a bit dated but the principles should still work.
- [1](https://github.com/gregn610/plpgsql/wiki/meta-sql-with-pytho...)
- [2](https://github.com/gregn610/plpgsql/wiki/meta-sql-with-pytho...)