scoped session factory

Rather than creating a new session / connection in every place that it is required use a scoped session factory (scoped to the thread) to manage connections as described here: http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html?highlight=session#using-thread-local-scope-with-web-applications