title: How to convert SQLAlchemy row object to a Python dict?
body: <p>Is there a simple way to iterate over column name and value pairs?</p>
  <p>My version of SQLAlchemy is 0.5.6</p>
  <p>Here is the sample code where I tried using <code>dict(row)</code>:</p>
  <pre><code>import sqlalchemy
  from sqlalchemy import *
  from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy.orm import sessionmaker
  
  print &quot;sqlalchemy version:&quot;,sqlalchemy.__version__ 
  
  engine = create_engine('sqlite:///:memory:', echo=False)
  metadata = MetaData()
  users_table = Table('users', metadata,
       Column('id', Integer, primary_key=True),
       Column('name', String),
  )
  metadata.create_all(engine) 
  
  class User(declarative_base()):
      __tablename__ = 'users'
      
      id = Column(Integer, primary_key=True)
      name = Column(String)
      
      def __init__(self, name):
          self.name = name
  
  Session = sessionmaker(bind=engine)
  session = Session()
  
  user1 = User(&quot;anurag&quot;)
  session.add(user1)
  session.commit()
  
  # uncommenting next line throws exception 'TypeError: 'User' object is not iterable'
  #print dict(user1)
  # this one also throws 'TypeError: 'User' object is not iterable'
  for u in session.query(User).all():
      print dict(u)
  </code></pre>
  <p>Running this code on my system outputs:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;untitled-1.py&quot;, line 37, in &lt;module&gt;
      print dict(u)
  TypeError: 'User' object is not iterable
  </code></pre>