Post-process request event in Pyramid/Pylons
In Pylons, each controller can have a before and after methods you can define that's then called before/after the controller method called. 
There's also the lib/base.py file which contains the controller call and you could add some custom code there, but it will be called on every request and can be dangerous if your code produces some errors.
I'm not sure in Pyramid.
If you do things in a custom middleware, you'll have access to the request and response objects, but not other material. You could in theory parse the .ini config for the db settings and such, but if it's really part of the app, I'd stick to a place there.
Is there an event or some kind of work with middlelayer where the request is already sent to the user, but we still have the information so we can do stuff on the DB later?