How to create a Connection Pool using python and sqlAlchemy?

2

Hello! Well I'm studying python and I started looking for connection pool material using sqlalchemy but unfortunately I did not find any example on the internet that shows the process of creating the connection pool using python and sqlalchemy. If you know good materials please let me know. Thank you!

    
asked by anonymous 05.10.2016 / 16:00

1 answer

0

Follow the documentation page: link

See an example:

engine = create_engine('postgresql://me@localhost/mydb',
                       pool_size=20, max_overflow=0)

If you want only the sqlalchemy pool system and the native drive:

import sqlalchemy.pool as pool
import psycopg2

def getconn():
    c = psycopg2.connect(username='ed', host='127.0.0.1', dbname='test')
    return c

mypool = pool.QueuePool(getconn, max_overflow=10, pool_size=5)
# get a connection
conn = mypool.connect()

# use it
cursor = conn.cursor()
cursor.execute("select foo")
    
18.12.2016 / 07:11