I do not think you can use sqlalchemy with asyncio. The Alchemy SQL API is completely blocked and incompatible with asyncio. http://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databases/
You can use Alchemy SQL asynchronously with gevent , although you can find a gevent-compatible driver for your database. And gentent greenlents paint beautifully before scoped_session
.
EDIT: in fact, it looks like you can use SQL Alchemy with asyncio if you can find an asyncio-compatible driver for your database, for example https://github.com/aio-libs/aiopg . As for scoped_session
, use current_task
and destroy it at the end of the web frame request.
source share