Skip to content

Instantly share code, notes, and snippets.

@motionrus
Last active June 17, 2019 23:41
Show Gist options
  • Save motionrus/82dd62fb7024f65a6bb61b0e916da9f5 to your computer and use it in GitHub Desktop.
Save motionrus/82dd62fb7024f65a6bb61b0e916da9f5 to your computer and use it in GitHub Desktop.
from sqlalchemy import pool as alchemy_pool
import configparser, pymssql
PATH_TO_CONFIG = 'config_local.ini'
def get_db_config():
config = configparser.ConfigParser()
config.read(PATH_TO_CONFIG)
return config['DB.CONFIG']
def getconn():
db = get_db_config()
return pymssql.connect(
host=db['db.host'] + ':' + db['db.port'],
user=db['db.user'],
password=db['db.password'],
database=db['db.database'],
as_dict=True
)
pool = alchemy_pool.QueuePool(getconn, pool_size=30)
conn = pool.connect()
curs = conn.cursor()
# example usage
# curs.execute(query, params)
# conn.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment