from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker import json, __main__ from os import path config = json.load( open(path.join(path.dirname(__main__.__file__), 'conf', 'db.json'))) engine = create_engine( "{0[type]}://{0[user]}:{0[pass]}@{0[host]}/{0[name]}?{0[opts]}".format(config)) Session = sessionmaker(bind=engine)