MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / AsyncSession

Class AsyncSession

lib/sqlalchemy/ext/asyncio/session.py:210–1664  ·  view source on GitHub ↗

Asyncio version of :class:`_orm.Session`. The :class:`_asyncio.AsyncSession` is a proxy for a traditional :class:`_orm.Session` instance. The :class:`_asyncio.AsyncSession` is **not safe for use in concurrent tasks.**. See :ref:`session_faq_threadsafe` for background. .. vers

Source from the content-addressed store, hash-verified

208 ],
209)
210class AsyncSession(ReversibleProxy[Session]):
211 """Asyncio version of :class:`_orm.Session`.
212
213 The :class:`_asyncio.AsyncSession` is a proxy for a traditional
214 :class:`_orm.Session` instance.
215
216 The :class:`_asyncio.AsyncSession` is **not safe for use in concurrent
217 tasks.**. See :ref:`session_faq_threadsafe` for background.
218
219 .. versionadded:: 1.4
220
221 To use an :class:`_asyncio.AsyncSession` with custom :class:`_orm.Session`
222 implementations, see the
223 :paramref:`_asyncio.AsyncSession.sync_session_class` parameter.
224
225
226 """
227
228 _is_asyncio = True
229
230 dispatch: dispatcher[Session]
231
232 def __init__(
233 self,
234 bind: Optional[_AsyncSessionBind] = None,
235 *,
236 binds: Optional[Dict[_SessionBindKey, _AsyncSessionBind]] = None,
237 sync_session_class: Optional[Type[Session]] = None,
238 **kw: Any,
239 ):
240 r"""Construct a new :class:`_asyncio.AsyncSession`.
241
242 All parameters other than ``sync_session_class`` are passed to the
243 ``sync_session_class`` callable directly to instantiate a new
244 :class:`_orm.Session`. Refer to :meth:`_orm.Session.__init__` for
245 parameter documentation.
246
247 :param sync_session_class:
248 A :class:`_orm.Session` subclass or other callable which will be used
249 to construct the :class:`_orm.Session` which will be proxied. This
250 parameter may be used to provide custom :class:`_orm.Session`
251 subclasses. Defaults to the
252 :attr:`_asyncio.AsyncSession.sync_session_class` class-level
253 attribute.
254
255 .. versionadded:: 1.4.24
256
257 """
258 sync_bind = sync_binds = None
259
260 if bind:
261 self.bind = bind
262 sync_bind = engine._get_sync_engine_or_connection(bind)
263
264 if binds:
265 self.binds = binds
266 sync_binds = {
267 key: engine._get_sync_engine_or_connection(b)

Callers 15

typed_results.pyFile · 0.90
async_stuff.pyFile · 0.90
async_test_exec_optionsFunction · 0.90
async_test_13091Function · 0.90
async_sessionMethod · 0.90
test_initMethod · 0.90
test_close_allMethod · 0.90

Calls

no outgoing calls