def begin(self, close=True, expire_on_commit=False, session=None,
              commit=False, **options):
        """Provide a transactional scope around a series of operations.

        By default, ``expire_on_commit`` is set to False so that instances
        can be used outside the session.
        """
        if not session:
            commit = True
            session = self.session(expire_on_commit=expire_on_commit,
                                   **options)
        else:
            close = False
        try:
            yield session
            if commit:
                session.commit()
        except Exception:
            session.rollback()
            raise
        finally:
            if close:
                session.close()