title: SQLAlchemy, Generating python declarative_base classes using reflection AND/OR Persisting reflected metadata and automap_base
body: <p>I am using SQlAlchemy automap extension for my preference to avoid manually writing up the declarative base classes. Mostly because I am not very familiar with the db schema and need to interact only with a small subset of tables and columns</p>
  
  <p>I am using the following code to set up a SQlAlchemy session and then interact with my database.  Things seem to work well using this.</p>
  
  <pre><code>        engine = create_engine('mssql+pymssql://xx:xxx@xxx/xxx', implicit_returning=False)
          metadata = MetaData()
          tables = ['xxx', 'xxx', 'xxx']
          metadata.reflect(engine, only=tables)
          base = automap_base(metadata=metadata)
          base.prepare()
          session_maker = sessionmaker(bind=engine)
          session = session_maker()
  </code></pre>
  
  <p>Since the database has a large number of tables and columns, it takes a fair amount of time for the session to load, since each time reflection has to be done.</p>
  
  <p>Also, the IDE I use (PyCharm) gives me very useful auto completion when it can infer the object type correctly. It does not work when I use automap, for obvious reasons. It is often a challenge to get the column name strings right, and requires me to repeatedly verify them from db management studio.</p>
  
  <p>Is there a way to generate declarative base classes using reflection? Can I at least persist the reflected metadata in some other way? It is safe to assume that db schema won't change.</p>