title: How to query a SQL View from flask-SQLAlchemy
body: <p>I have been given access to  a database (MySQL, in case it matters) to access some data that I need, but I don't have direct access to the tables, the data is exposed through a SQL View.</p>
  <p>I want to wrap this in a small API using flask. For the database connection I intend to use SQLAlchemy (just because it's the only databse wrapper that I know in python).</p>
  <p>The thing is, I have read a lot of documentation, and dozens of stackoverflow posts and guides through the Internet, and I can't seem to find a way to query SQL Views from flask-SQLAlchemy.</p>
  <p>In the documentation, they always use Models. I tried to define my View as a Model, but I get <code>could not assemble any primary key columns for mapped table 'MySQLView'</code>.</p>
  <p>What I tried to do:</p>
  <pre class="lang-py prettyprint-override"><code>class MyView(db.Model):
      __tablename__ = &quot;my_view_name_in_sql&quot;
      db.Column(&quot;id&quot;, db.Integer, primary_key=True)
      db.Column(&quot;sample_id&quot;, db.String)
      {...etc}
  </code></pre>
  <p>Is there a way to do this, or maybe I should opt-out of using flask-SQLAlchemy and use something else instead?</p>