wrt basic behaviour, this library seems to save all of two lines which can easily be bundled in a convenience function:
def query(connection, q):
cursor = connection.cursor(cursor_factory=psycopg2.extras.DictCursor)
cursor.execute(q)
return iter(cursor.fetchone, None)
# db = records.Database('postgres://...')
db = psycopg2.connect('postgres://...')
# rows = db.query('select * from active_users')
rows = query(db, 'select * from active_users')
# rows.next()
next(rows)
# for row in rows:
# spam_user(name=row['name'], email=row['user_email'])
for row in rows:
spam_user(name=row['name'], email=row['user_email'])
# rows.all()
list(rows)