sqlalchemy Using a Connection


Example

You can open a connection (i.e. request one from the pool) using a context manager:

with engine.connect() as conn:
    result = conn.execute('SELECT price FROM products')
    for row in result:
        print('Price:', row['price'])

Or without, but it must be closed manually:

conn = engine.connect()
result = conn.execute('SELECT price FROM products')
for row in result:
    print('Price:', row['price'])
conn.close()