import json from os import path from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker class Session(object): engine = None def __init__(self): config = json.load( open(path.join(path.dirname( path.realpath(__file__)), '..', 'conf', 'db.json'))) db_str = "{0[type]}://{0[user]}:{0[pass]}@{0[host]}/{0[name]}".format( config) self.engine = create_engine(db_str) def get_maker(self): return sessionmaker(bind=self.engine) @staticmethod def create(): session = Session() maker = session.get_maker() return maker()