drastega
drastega

Reputation: 1773

With statement and SQLalchemy engine

When I try to implement SQLalchemy engine using following construction

with sqlalchemy.create_engine("sqlite:///my_db.sqlite") as engine:
     (do something)

I get an error: AttributeError: __exit__

What is wrong? And how can I explicitly close my SQLalchemy engine?

Upvotes: 3

Views: 2545

Answers (1)

davidism
davidism

Reputation: 127370

A SQLAlchemy engine is not a context manager, so it can't be used in a with statement. It manages the connections in a pool for you, see the documentation on engine.execute() and engine.dispose() for an explanation of how.

Upvotes: 7

Related Questions