Debugging (displaying) SQL command sent to the db by SQLAlchemy

In addition to echo parameter of create_engine() there is a more flexible way: configuring logging to echo engine statements:

import logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)

See Configuring Logging section of documentation for more information.


You can see the SQL statements being sent to the DB by passing echo=True when the engine instance is created (usually using the create_engine() or engine_from_config() call in your code).

For example:

engine = sqlalchemy.create_engine('postgres://foo/bar', echo=True)

By default, logged statements go to stdout.