class documentation

class AsyncEngine(ProxyComparable, AsyncConnectable):

View In Hierarchy

An asyncio proxy for a _engine.Engine.

_asyncio.AsyncEngine is acquired using the _asyncio.create_async_engine function:

from sqlalchemy.ext.asyncio import create_async_engine
engine = create_async_engine("postgresql+asyncpg://user:pass@host/dbname")
New in version 1.4.
Class ​_trans​_ctx Undocumented
Class Method ​_regenerate​_proxy​_for​_target Undocumented
Method __init__ Undocumented
Method begin Return a context manager which when entered will deliver an _asyncio.AsyncConnection with an _asyncio.AsyncTransaction established.
Method connect Return an _asyncio.AsyncConnection object.
Async Method dispose Dispose of the connection pool used by this _asyncio.AsyncEngine.
Method execution​_options Return a new _asyncio.AsyncEngine that will provide _asyncio.AsyncConnection objects with the given execution options.
Async Method raw​_connection Return a "raw" DBAPI connection from the connection pool.
Class Variable __slots__ Undocumented
Class Variable ​_option​_cls Undocumented
Instance Variable ​_proxied Undocumented
Instance Variable sync​_engine Reference to the sync-style _engine.Engine this _asyncio.AsyncEngine proxies requests towards.

Inherited from ProxyComparable:

Method __eq__ Undocumented
Method __hash__ Undocumented
Method __ne__ Undocumented

Inherited from ReversibleProxy (via ProxyComparable):

Class Method ​_retrieve​_proxy​_for​_target Undocumented
Class Method ​_target​_gced Undocumented
Method ​_assign​_proxied Undocumented
Class Variable ​_proxy​_objects Undocumented
@classmethod
def _regenerate_proxy_for_target(cls, target):
def __init__(self, sync_engine):

Undocumented

def begin(self):

Return a context manager which when entered will deliver an _asyncio.AsyncConnection with an _asyncio.AsyncTransaction established.

E.g.:

async with async_engine.begin() as conn:
    await conn.execute(
        text("insert into table (x, y, z) values (1, 2, 3)")
    )
    await conn.execute(text("my_special_procedure(5)"))
def connect(self):

Return an _asyncio.AsyncConnection object.

The _asyncio.AsyncConnection will procure a database connection from the underlying connection pool when it is entered as an async context manager:

async with async_engine.connect() as conn:
    result = await conn.execute(select(user_table))

The _asyncio.AsyncConnection may also be started outside of a context manager by invoking its _asyncio.AsyncConnection.start method.

async def dispose(self):

Dispose of the connection pool used by this _asyncio.AsyncEngine.

This will close all connection pool connections that are currently checked in. See the documentation for the underlying _future.Engine.dispose method for further notes.

See Also

_future.Engine.dispose

def execution_options(self, **opt):

Return a new _asyncio.AsyncEngine that will provide _asyncio.AsyncConnection objects with the given execution options.

Proxied from _future.Engine.execution_options. See that method for details.

async def raw_connection(self):

Return a "raw" DBAPI connection from the connection pool.

__slots__: tuple[str, ...] =
_option_cls: type =

Undocumented

_proxied =

Undocumented

sync_engine: Engine =

Reference to the sync-style _engine.Engine this _asyncio.AsyncEngine proxies requests towards.

This instance can be used as an event target.