def get_tm_session(session_factory, transaction_manager):
dbsession = session_factory()<EOL>zope.sqlalchemy.register(<EOL>dbsession, transaction_manager=transaction_manager)<EOL>return dbsession<EOL>
Get a ``sqlalchemy.orm.Session`` instance backed by a transaction.

This function will hook the session to the transaction manager which
will take care of committing any changes.

- When using pyramid_tm it will automatically be committed or aborted
  depending on whether an exception is raised.

- When using scripts you should wrap the session in a manager yourself.
  For example::

      import transaction

      engine = get_engine(settings)
      session_factory = get_session_factory(engine)
      with transaction.manager:
          dbsession = get_tm_session(session_factory, transaction.manager)