MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / create_async_engine

Function create_async_engine

lib/sqlalchemy/ext/asyncio/engine.py:70–121  ·  view source on GitHub ↗

Create a new async engine instance. Arguments passed to :func:`_asyncio.create_async_engine` are mostly identical to those passed to the :func:`_sa.create_engine` function. The specified dialect must be an asyncio-compatible dialect such as :ref:`dialect-postgresql-asyncpg`. ..

(url: Union[str, URL], **kw: Any)

Source from the content-addressed store, hash-verified

68
69
70def create_async_engine(url: Union[str, URL], **kw: Any) -> AsyncEngine:
71 """Create a new async engine instance.
72
73 Arguments passed to :func:`_asyncio.create_async_engine` are mostly
74 identical to those passed to the :func:`_sa.create_engine` function.
75 The specified dialect must be an asyncio-compatible dialect
76 such as :ref:`dialect-postgresql-asyncpg`.
77
78 .. versionadded:: 1.4
79
80 :param async_creator: an async callable which returns a driver-level
81 asyncio connection. If given, the function should take no arguments,
82 and return a new asyncio connection from the underlying asyncio
83 database driver; the connection will be wrapped in the appropriate
84 structures to be used with the :class:`.AsyncEngine`. Note that the
85 parameters specified in the URL are not applied here, and the creator
86 function should use its own connection parameters.
87
88 This parameter is the asyncio equivalent of the
89 :paramref:`_sa.create_engine.creator` parameter of the
90 :func:`_sa.create_engine` function.
91
92 .. versionadded:: 2.0.16
93
94 """
95
96 if kw.get("server_side_cursors", False):
97 raise async_exc.AsyncMethodRequired(
98 "Can't set server_side_cursors for async engine globally; "
99 "use the connection.stream() method for an async "
100 "streaming result set"
101 )
102 kw["_is_async"] = True
103 async_creator = kw.pop("async_creator", None)
104 if async_creator:
105 if kw.get("creator", None):
106 raise ArgumentError(
107 "Can only specify one of 'async_creator' or 'creator', "
108 "not both."
109 )
110
111 def creator() -> Any:
112 # note that to send adapted arguments like
113 # prepared_statement_cache_size, user would use
114 # "creator" and emulate this form here
115 return sync_engine.dialect.dbapi.connect( # type: ignore
116 async_creator_fn=async_creator
117 )
118
119 kw["creator"] = creator
120 sync_engine = _create_engine(url, **kw)
121 return AsyncEngine(sync_engine)
122
123
124def async_engine_from_config(

Callers 15

typed_results.pyFile · 0.90
asyncioFunction · 0.90
async_mainFunction · 0.90
async_stuff.pyFile · 0.90
sessionmakers.pyFile · 0.90
async_mainFunction · 0.90
async_mainFunction · 0.90
async_mainFunction · 0.90

Calls 4

ArgumentErrorClass · 0.85
AsyncEngineClass · 0.85
getMethod · 0.45
popMethod · 0.45