Pyramid Transaction Manager

2.6 · active · verified Wed Apr 15

pyramid_tm is a package that integrates the Python `transaction` package with the Pyramid web framework, allowing Pyramid requests to join the active transaction. It provides centralized transaction management for Pyramid applications without relying on external WSGI middleware. Maintained by the Pylons Project, it has a generally active release cadence, with version 2.6 released in November 2024.

Warnings

Install

Imports

Quickstart

This minimal Pyramid application demonstrates how to include `pyramid_tm`. Once included, any operations involving data managers (like ZODB or SQLAlchemy with `zope.sqlalchemy`) will automatically join the transaction associated with the request.

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def hello_world(request):
    # Any database operations here would automatically join the active transaction
    return Response('Hello World from pyramid_tm!')

if __name__ == '__main__':
    with Configurator() as config:
        config.include('pyramid_tm') # Enable pyramid_tm
        config.add_route('hello', '/')
        config.add_view(hello_world, route_name='hello')
        app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 6543, app)
    print("Pyramid server running on http://0.0.0.0:6543")
    server.serve_forever()

view raw JSON →