"""Replace the placeholders with values
    Works both with :1 and %(foo)s type placeholders"""
query = query.replace(':%s' % k, v)
How to use SQLAlchemy to dump an SQL file from query expressions to bulk-insert into a DBMS?