py2
from sqlalchemy import create_engine,Column,String
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
MYSQL_URI = 'mysql+mysqldb://root:111111@127.0.0.1:3306/blog?charset=utf8'
Base = declarative_base() #table的基类
class User(Base): #创建表的orm框架
__tablename__ = 'user'
id = Column(String(20), primary_key=True)
name = Column(String(20))
Base.metadata.create_all(engine) #生成表
#CRUD
engine = create_engine(MYSQL_URI) #连接数据库
DBSession = sessionmaker(bind=engine) #创建会话
user = session.query(User).filter_by(name="user1").first()