概要 sessionクラスを使う session_markerクラスを使う scoped_sessionクラスを使う(オススメ) session のクローズについて 補足(auto_flush, auto_commit設定について) 補足(トランザクションについて) 概要 SQLAlchemyでは、sessionの作成方法が複数あって結局どれがいいの?っていうのをいろいろ考えてみた。 ちなみに、Flaskなどのフレームワークを利用している場合はSQLAlchemyをラップしたFlask-SQLAlchemyなどがあるのでここら辺を利用するとsession周りは良しなにやってくれます。 フレームワークを使わないような、ツールやバッチ系などではSQLAlchemy単体で使うことも多いと思うのでそういう人向けです。 参考: SQLAlchemyのSession生成方法 - Qiita 【Pyth