title: Accessing Pyramid database outside of WSGI instance
body: <p>I'd like to create a Whoosh index from entries in the database connected to my Pyramid application.  However, I'm not really sure how to access the database outside of application.</p>
  
  <p>So my <code>models.py</code> is initialized as follows:</p>
  
  <pre><code>from sqlalchemy import (
      Column,
      Integer,
      Text,
      String,
      ForeignKey,
      Table
      )
  
  from sqlalchemy.ext.declarative import declarative_base
  
  from sqlalchemy.orm import (
      scoped_session,
      sessionmaker,
      relationship,
      backref
      )
  
  from sqlalchemy.dialects.mysql import DATETIME, FLOAT, TEXT
  
  from zope.sqlalchemy import ZopeTransactionExtension
  
  db_session = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
  dbBase = declarative_base()
  dbBase.query = db_session.query_property()  
  </code></pre>
  
  <p>Then in <code>__init__.py</code>, there is an example of loading in the models: </p>
  
  <pre><code>from pyramid.config import Configurator
  from sqlalchemy import engine_from_config
  from .models import db_session, Recipe
  def main(global_config, **settings):
      """ This function returns a Pyramid WSGI application.
      """
      engine = engine_from_config(settings, 'sqlalchemy.')
  
      db_session.configure(bind=engine)
  </code></pre>
  
  <p>my <code>production.ini</code> has the engine assignment:</p>
  
  <pre><code>sqlalchemy.url = mysql+pymysql://username:password@localhost:3306/database?charset=utf8
  </code></pre>
  
  <p>So main is called when the WSGI process is started, which passes the engine from the .ini file.  But I'd like to access the database through a script that does not rely on the WSGI process.  Can I just assign the engine and bind it to the session in the script?  How does the <code>extension=ZopeTransactionExtension()</code> affect the session?</p>