to achieve this for all new connections immediately, use a connect event:
fromsqlalchemyimporteventfromsqlalchemyimportcreate_engineengine=create_engine("postgresql://...")@event.listens_for(engine,"connect")defset_schema(dbapi_connection,connection_record):withdbapi_connection.cursor()ascursor:cursor.execute("SET search_path TO myschema,public")
to achieve it for an arbitrary connection from the engine:
conn=engine.connect()conn.execute("SET search_path TO myschema,public")
keep in mind if you are using a connection pool, that search path doesn't get automatically reset.