There are some sections in the docs that may help you understand things a bit more.
1. Connections- Disposal https://docs.sqlalchemy.org/en/13/core/connections.html#engine-disposal 2. Connections- Threadlocal https://docs.sqlalchemy.org/en/13/core/connections.html#using-the-threadlocal-execution-strategy 3. Connections FAQ - https://docs.sqlalchemy.org/en/13/faq/connections.html 4. Sessions FAQ - https://docs.sqlalchemy.org/en/13/faq/sessions.html Generally you only need to call `dispose` when you're dealing with multiple processes or forks - as it's designed to help get around situations where you have database connections that are not safe to cross boundaries. Personally, I prefer to wrap the database intialization in a function. using your example... something more like this: *database.py * DB_ENGINE = None DB_SESSION = None def initialize_db(): global DB_ENGINE, DB_SESSION DB_ENGINE = create_engine(DB_CONNECTION_STRING, pool_size=5, max_overflow=10) DB_SESSION = sessionmaker(bind=DB_ENGINE, autocommit=False, autoflush =True, expire_on_commit=False) This way you can import the file without establishing a db connection at that moment, and can then control exactly when the connection is made. My usage patterns are a bit different than yours, so I'm usually stashing everything in a dict that handles the application context... and not using globals. this seemed easier to explain though. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/e2db032c-6c54-4b3a-9b2b-87050763366a%40googlegroups.com.