def session_context(fn):
    """
    Handles session setup and teardown
    """
    @functools.wraps(fn)
    def wrap(*args, **kwargs):
        session = args[0].Session()  # obtain from self
        result = fn(*args, session=session, **kwargs)
        session.close()
        return result
    return wrap
Handles session setup and teardown