You can have SQLAlchemy check for the liveness of the connection with the parameter pool_pre_ping: https://docs.sqlalchemy.org/en/13/core/engines.html#sqlalchemy.create_engine.params.pool_pre_ping
if True will enable the connection pool “pre-ping” feature that tests connections for liveness upon each checkout.
Simply enable it by using when you create your engine.