How to create a Connection Pool using python and sqlAlchemy?


Hi ! Well I'm studying python and I started looking for material about connection pool using sqlalchemy but unfortunately I didn't find any example on the internet that shows the process of creating a connection pool using python and sqlalchemy. If you know good materials, please let me know. Thanks in advance !


The documentation page follows:

See an example:

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

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

import sqlalchemy.pool as pool
import psycopg2

def getconn():
    c = psycopg2.connect(username='ed', host='', 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")
Scroll to Top