'Cannot create SQLAlchemy engine, getting error "loaded 'mysqldb' is not async"

I'm trying to replace Databases with SQLAlchemy 1.4 async. When I try to make the engine I get the following error:

sqlalchemy.exc.InvalidRequestError: The asyncio extension requires an async driver to be used. The loaded 'mysqldb' is not async.

I'm making the engine like this:

engine = create_async_engine(SQLALCHEMY_DATABASE_URL, future=True)

What is need to get mysqldb to work with SQLAlchemy async?



Solution 1:[1]

I figured it out, I was using this URL:

'mysql://someuser:passwd1234@localhost/app_db'

But I needed to be using something like:

'mysql+asyncmy://someuser:asswd1234@localhost/app_db'

I was missing the +asyncmy part to use the asyncmy dialect. I needed to install the package too:

pip install sqlalchemy[asyncio]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1