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

Class AsyncSession

lib/sqlalchemy/ext/asyncio/session.py:204–1604  ·  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

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

Calls

no outgoing calls