title: what is the recommended way of setting up an sqlalchemy connection for view callables?
body: <p>I am using the sqlalchemy expression language for its notation and connection pooling to create dao objects for communicating with the persistence layer. I wanted to get some opinions on how I should approach setting up the metadata and engine so that they are available to the applications view callables. According to sqlalchemy's documentation <a href="http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html">http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html</a>, they are typically bound and declared global, however I've neither this or the singleton approach are good ideas. Any thoughts would be appreciated...</p>
  
  <p>This is what my <code>__init__.py</code> file looks like inside my project's directory:</p>
  
  <pre class="lang-py prettyprint-override"><code>from pyramid.config import Configurator
  from sqlalchemy import engine_from_config, MetaData, create_engine
  from pyramid_beaker import session_factory_from_settings
  
  db_url = 'postgresql://user:password@localhost/dbname'
  engine = create_engine(db_url)
  meta = MetaData()
  
  def main(global_config, **settings):
      meta.bind = engine
      .
      .
      .
      [other configuration settings]
  </code></pre>