title: SQLAlchemy automap: Best practices for performance
body: <p>I'm building a python app around an existing (mysql) database and am using automap to infer tables and relationships:</p>
  
  <pre><code>    base = automap_base()
  
      self.engine = create_engine(
          'mysql://%s:%s@%s/%s?charset=utf8mb4' % (
              config.DB_USER, config.DB_PASSWD, config.DB_HOST, config.DB_NAME
          ), echo=False
      )
  
      # reflect the tables
      base.prepare(self.engine, reflect=True)
  
      self.TableName = base.classes.table_name
  </code></pre>
  
  <p>Using this I can do things like <code>session.query(TableName)</code> etc...
  However, I'm worried about performance, because every time the app runs it will do the whole inference again.</p>
  
  <ul>
  <li>Is this a legitimate concern?</li>
  <li>If so, is there a possibility to 'cache' the output of Automap?</li>
  </ul>