begin_retval = db.engine.execute('BEGIN;')
retval = db.engine.execute(
    'SELECT * FROM add_purchase(%s, %s, %s, %s, %s, %s, %s);', clean_data.
    account_id, amount, tax, deposit, clean_data.pos_id, g.token_id,
    clean_data.external_reference_id).first()
Commiting a transaction from a PostgreSQL function in flask