from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, scoped_session from app.config import Config engine = create_engine(Config.SQLALCHEMY_DATABASE_URI, pool_pre_ping=True) Session = scoped_session(sessionmaker(bind=engine)) def get_db_session(): return Session() def close_db_session(exception=None): Session.remove()