class documentation

class AsyncSession(ReversibleProxy[Session]): (source)

View In Hierarchy

Asyncio version of :class:`_orm.Session`. The :class:`_asyncio.AsyncSession` is a proxy for a traditional :class:`_orm.Session` instance. .. versionadded:: 1.4 To use an :class:`_asyncio.AsyncSession` with custom :class:`_orm.Session` implementations, see the :paramref:`_asyncio.AsyncSession.sync_session_class` parameter.

Async Class Method close_all Close all :class:`_asyncio.AsyncSession` sessions.
Class Method identity_key Return an identity key.
Class Method object_session Return the :class:`.Session` to which an object belongs.
Async Method __aenter__ Undocumented
Async Method __aexit__ Undocumented
Method __contains__ Return True if the instance is associated with this session.
Method __init__ Construct a new :class:`_asyncio.AsyncSession`.
Method __iter__ Iterate over all pending or persistent instances within this Session.
Method add Place an object into this :class:`_orm.Session`.
Method add_all Add the given collection of instances to this :class:`_orm.Session`.
Method autoflush.setter Undocumented
Method begin Return an :class:`_asyncio.AsyncSessionTransaction` object.
Method begin_nested Return an :class:`_asyncio.AsyncSessionTransaction` object which will begin a "nested" transaction, e.g. SAVEPOINT.
Async Method close Close out the transactional resources and ORM objects used by this :class:`_asyncio.AsyncSession`.
Async Method commit Commit the current transaction in progress.
Async Method connection Return a :class:`_asyncio.AsyncConnection` object corresponding to this :class:`.Session` object's transactional state.
Async Method delete Mark an instance as deleted.
Async Method execute Execute a statement and return a buffered :class:`_engine.Result` object.
Method expire Expire the attributes on an instance.
Method expire_all Expires all persistent instances within this Session.
Method expunge Remove the `instance` from this ``Session``.
Method expunge_all Remove all object instances from this ``Session``.
Async Method flush Flush all the object changes to the database.
Async Method get Return an instance based on the given primary key identifier, or ``None`` if not found.
Method get_bind Return a "bind" to which the synchronous proxied :class:`_orm.Session` is bound.
Method get_nested_transaction Return the current nested transaction in progress, if any.
Method get_transaction Return the current root transaction in progress, if any.
Method identity_map.setter Undocumented
Method in_nested_transaction Return True if this :class:`_orm.Session` has begun a nested transaction, e.g. SAVEPOINT.
Method in_transaction Return True if this :class:`_orm.Session` has begun a transaction.
Async Method invalidate Close this Session, using connection invalidation.
Method is_modified Return ``True`` if the given instance has locally modified attributes.
Async Method merge Copy the state of a given instance into a corresponding instance within this :class:`_asyncio.AsyncSession`.
Async Method refresh Expire and refresh the attributes on the given instance.
Async Method rollback Rollback the current transaction in progress.
Async Method run_sync Invoke the given sync callable passing sync self as the first argument.
Async Method scalar Execute a statement and return a scalar result.
Async Method scalars Execute a statement and return scalar results.
Async Method stream Execute a statement and return a streaming :class:`_asyncio.AsyncResult` object.
Async Method stream_scalars Execute a statement and return a stream of scalar results.
Class Variable dispatch Undocumented
Instance Variable bind Undocumented
Instance Variable binds Undocumented
Instance Variable sync_session Reference to the underlying :class:`_orm.Session` this :class:`_asyncio.AsyncSession` proxies requests towards.
Instance Variable sync_session_class The class or callable that provides the underlying :class:`_orm.Session` instance for a particular :class:`_asyncio.AsyncSession`.
Property autoflush Proxy for the :attr:`_orm.Session.autoflush` attribute on behalf of the :class:`_asyncio.AsyncSession` class.
Property deleted The set of all instances marked as 'deleted' within this ``Session``
Property dirty The set of all persistent instances considered dirty.
Property identity_map Proxy for the :attr:`_orm.Session.identity_map` attribute on behalf of the :class:`_asyncio.AsyncSession` class.
Property info A user-modifiable dictionary.
Property is_active True if this :class:`.Session` not in "partial rollback" state.
Property new The set of all instances marked as 'new' within this ``Session``.
Property no_autoflush Return a context manager that disables autoflush.
Class Method _no_async_engine_events Undocumented
Method _maker_context_manager Undocumented
Class Variable _is_asyncio Undocumented
Instance Variable _proxied Undocumented

Inherited from ReversibleProxy:

Class Variable __slots__ Undocumented
Class Method _regenerate_proxy_for_target Undocumented
Class Method _retrieve_proxy_for_target Undocumented
Class Method _target_gced Undocumented
Method _assign_proxied Undocumented
Class Variable _proxy_objects Undocumented
@classmethod
async def close_all(self): (source)

Close all :class:`_asyncio.AsyncSession` sessions.

@classmethod
def identity_key(cls, class_: Optional[Type[Any]] = None, ident: Union[Any, Tuple[Any, ...]] = None, *, instance: Optional[Any] = None, row: Optional[Union[Row[Any], RowMapping]] = None, identity_token: Optional[Any] = None) -> _IdentityKeyType[Any]: (source)

Return an identity key. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. This is an alias of :func:`.util.identity_key`.

@classmethod
def object_session(cls, instance: object) -> Optional[Session]: (source)

Return the :class:`.Session` to which an object belongs. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. This is an alias of :func:`.object_session`.

async def __aenter__(self: _AS) -> _AS: (source)

Undocumented

async def __aexit__(self, type_: Any, value: Any, traceback: Any): (source)

Undocumented

def __contains__(self, instance: object) -> bool: (source)

Return True if the instance is associated with this session. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. The instance may be pending or persistent within the Session for a result of True.

def __init__(self, bind: Optional[_AsyncSessionBind] = None, *, binds: Optional[Dict[_SessionBindKey, _AsyncSessionBind]] = None, sync_session_class: Optional[Type[Session]] = None, **kw: Any): (source)

Construct a new :class:`_asyncio.AsyncSession`. All parameters other than ``sync_session_class`` are passed to the ``sync_session_class`` callable directly to instantiate a new :class:`_orm.Session`. Refer to :meth:`_orm.Session.__init__` for parameter documentation. :param sync_session_class: A :class:`_orm.Session` subclass or other callable which will be used to construct the :class:`_orm.Session` which will be proxied. This parameter may be used to provide custom :class:`_orm.Session` subclasses. Defaults to the :attr:`_asyncio.AsyncSession.sync_session_class` class-level attribute. .. versionadded:: 1.4.24

def __iter__(self) -> Iterator[object]: (source)

Iterate over all pending or persistent instances within this Session. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class.

def add(self, instance: object, _warn: bool = True): (source)

Place an object into this :class:`_orm.Session`. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. Objects that are in the :term:`transient` state when passed to the :meth:`_orm.Session.add` method will move to the :term:`pending` state, until the next flush, at which point they will move to the :term:`persistent` state. Objects that are in the :term:`detached` state when passed to the :meth:`_orm.Session.add` method will move to the :term:`persistent` state directly. If the transaction used by the :class:`_orm.Session` is rolled back, objects which were transient when they were passed to :meth:`_orm.Session.add` will be moved back to the :term:`transient` state, and will no longer be present within this :class:`_orm.Session`. .. seealso:: :meth:`_orm.Session.add_all` :ref:`session_adding` - at :ref:`session_basics`

def add_all(self, instances: Iterable[object]): (source)

Add the given collection of instances to this :class:`_orm.Session`. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. See the documentation for :meth:`_orm.Session.add` for a general behavioral description. .. seealso:: :meth:`_orm.Session.add` :ref:`session_adding` - at :ref:`session_basics`

@autoflush.setter
def autoflush(self, attr: bool): (source)

Undocumented

Return an :class:`_asyncio.AsyncSessionTransaction` object. The underlying :class:`_orm.Session` will perform the "begin" action when the :class:`_asyncio.AsyncSessionTransaction` object is entered:: async with async_session.begin(): # .. ORM transaction is begun Note that database IO will not normally occur when the session-level transaction is begun, as database transactions begin on an on-demand basis. However, the begin block is async to accommodate for a :meth:`_orm.SessionEvents.after_transaction_create` event hook that may perform IO. For a general description of ORM begin, see :meth:`_orm.Session.begin`.

def begin_nested(self) -> AsyncSessionTransaction: (source)

Return an :class:`_asyncio.AsyncSessionTransaction` object which will begin a "nested" transaction, e.g. SAVEPOINT. Behavior is the same as that of :meth:`_asyncio.AsyncSession.begin`. For a general description of ORM begin nested, see :meth:`_orm.Session.begin_nested`.

async def close(self): (source)

Close out the transactional resources and ORM objects used by this :class:`_asyncio.AsyncSession`. This expunges all ORM objects associated with this :class:`_asyncio.AsyncSession`, ends any transaction in progress and :term:`releases` any :class:`_asyncio.AsyncConnection` objects which this :class:`_asyncio.AsyncSession` itself has checked out from associated :class:`_asyncio.AsyncEngine` objects. The operation then leaves the :class:`_asyncio.AsyncSession` in a state which it may be used again. .. tip:: The :meth:`_asyncio.AsyncSession.close` method **does not prevent the Session from being used again**. The :class:`_asyncio.AsyncSession` itself does not actually have a distinct "closed" state; it merely means the :class:`_asyncio.AsyncSession` will release all database connections and ORM objects. .. seealso:: :ref:`session_closing` - detail on the semantics of :meth:`_asyncio.AsyncSession.close`

async def commit(self): (source)

Commit the current transaction in progress.

async def connection(self, **kw: Any) -> AsyncConnection: (source)

Return a :class:`_asyncio.AsyncConnection` object corresponding to this :class:`.Session` object's transactional state. This method may also be used to establish execution options for the database connection used by the current transaction. .. versionadded:: 1.4.24 Added \**kw arguments which are passed through to the underlying :meth:`_orm.Session.connection` method. .. seealso:: :meth:`_orm.Session.connection` - main documentation for "connection"

async def delete(self, instance: object): (source)

Mark an instance as deleted. The database delete operation occurs upon ``flush()``. As this operation may need to cascade along unloaded relationships, it is awaitable to allow for those queries to take place. .. seealso:: :meth:`_orm.Session.delete` - main documentation for delete

@overload
async def execute(self, statement: TypedReturnsRows[_T], params: Optional[_CoreAnyExecuteParams] = None, *, execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, bind_arguments: Optional[_BindArguments] = None, _parent_execute_state: Optional[Any] = None, _add_event: Optional[Any] = None) -> Result[_T]:
@overload
async def execute(self, statement: Executable, params: Optional[_CoreAnyExecuteParams] = None, *, execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, bind_arguments: Optional[_BindArguments] = None, _parent_execute_state: Optional[Any] = None, _add_event: Optional[Any] = None) -> Result[Any]:
(source)

Execute a statement and return a buffered :class:`_engine.Result` object. .. seealso:: :meth:`_orm.Session.execute` - main documentation for execute

def expire(self, instance: object, attribute_names: Optional[Iterable[str]] = None): (source)

Expire the attributes on an instance. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. Marks the attributes of an instance as out of date. When an expired attribute is next accessed, a query will be issued to the :class:`.Session` object's current transactional context in order to load all expired attributes for the given instance. Note that a highly isolated transaction will return the same values as were previously read in that same transaction, regardless of changes in database state outside of that transaction. To expire all objects in the :class:`.Session` simultaneously, use :meth:`Session.expire_all`. The :class:`.Session` object's default behavior is to expire all state whenever the :meth:`Session.rollback` or :meth:`Session.commit` methods are called, so that new state can be loaded for the new transaction. For this reason, calling :meth:`Session.expire` only makes sense for the specific case that a non-ORM SQL statement was emitted in the current transaction. :param instance: The instance to be refreshed. :param attribute_names: optional list of string attribute names indicating a subset of attributes to be expired. .. seealso:: :ref:`session_expire` - introductory material :meth:`.Session.expire` :meth:`.Session.refresh` :meth:`_orm.Query.populate_existing`

def expire_all(self): (source)

Expires all persistent instances within this Session. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. When any attributes on a persistent instance is next accessed, a query will be issued using the :class:`.Session` object's current transactional context in order to load all expired attributes for the given instance. Note that a highly isolated transaction will return the same values as were previously read in that same transaction, regardless of changes in database state outside of that transaction. To expire individual objects and individual attributes on those objects, use :meth:`Session.expire`. The :class:`.Session` object's default behavior is to expire all state whenever the :meth:`Session.rollback` or :meth:`Session.commit` methods are called, so that new state can be loaded for the new transaction. For this reason, calling :meth:`Session.expire_all` is not usually needed, assuming the transaction is isolated. .. seealso:: :ref:`session_expire` - introductory material :meth:`.Session.expire` :meth:`.Session.refresh` :meth:`_orm.Query.populate_existing`

def expunge(self, instance: object): (source)

Remove the `instance` from this ``Session``. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. This will free all internal references to the instance. Cascading will be applied according to the *expunge* cascade rule.

def expunge_all(self): (source)

Remove all object instances from this ``Session``. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. This is equivalent to calling ``expunge(obj)`` on all objects in this ``Session``.

async def flush(self, objects: Optional[Sequence[Any]] = None): (source)

Flush all the object changes to the database. .. seealso:: :meth:`_orm.Session.flush` - main documentation for flush

async def get(self, entity: _EntityBindKey[_O], ident: _PKIdentityArgument, *, options: Optional[Sequence[ORMOption]] = None, populate_existing: bool = False, with_for_update: Optional[ForUpdateArg] = None, identity_token: Optional[Any] = None, execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT) -> Optional[_O]: (source)

Return an instance based on the given primary key identifier, or ``None`` if not found. .. seealso:: :meth:`_orm.Session.get` - main documentation for get

def get_bind(self, mapper: Optional[_EntityBindKey[_O]] = None, clause: Optional[ClauseElement] = None, bind: Optional[_SessionBind] = None, **kw: Any) -> Union[Engine, Connection]: (source)

Return a "bind" to which the synchronous proxied :class:`_orm.Session` is bound. Unlike the :meth:`_orm.Session.get_bind` method, this method is currently **not** used by this :class:`.AsyncSession` in any way in order to resolve engines for requests. .. note:: This method proxies directly to the :meth:`_orm.Session.get_bind` method, however is currently **not** useful as an override target, in contrast to that of the :meth:`_orm.Session.get_bind` method. The example below illustrates how to implement custom :meth:`_orm.Session.get_bind` schemes that work with :class:`.AsyncSession` and :class:`.AsyncEngine`. The pattern introduced at :ref:`session_custom_partitioning` illustrates how to apply a custom bind-lookup scheme to a :class:`_orm.Session` given a set of :class:`_engine.Engine` objects. To apply a corresponding :meth:`_orm.Session.get_bind` implementation for use with a :class:`.AsyncSession` and :class:`.AsyncEngine` objects, continue to subclass :class:`_orm.Session` and apply it to :class:`.AsyncSession` using :paramref:`.AsyncSession.sync_session_class`. The inner method must continue to return :class:`_engine.Engine` instances, which can be acquired from a :class:`_asyncio.AsyncEngine` using the :attr:`_asyncio.AsyncEngine.sync_engine` attribute:: # using example from "Custom Vertical Partitioning" import random from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import create_async_engine from sqlalchemy.ext.asyncio import async_sessionmaker from sqlalchemy.orm import Session # construct async engines w/ async drivers engines = { 'leader':create_async_engine("sqlite+aiosqlite:///leader.db"), 'other':create_async_engine("sqlite+aiosqlite:///other.db"), 'follower1':create_async_engine("sqlite+aiosqlite:///follower1.db"), 'follower2':create_async_engine("sqlite+aiosqlite:///follower2.db"), } class RoutingSession(Session): def get_bind(self, mapper=None, clause=None, **kw): # within get_bind(), return sync engines if mapper and issubclass(mapper.class_, MyOtherClass): return engines['other'].sync_engine elif self._flushing or isinstance(clause, (Update, Delete)): return engines['leader'].sync_engine else: return engines[ random.choice(['follower1','follower2']) ].sync_engine # apply to AsyncSession using sync_session_class AsyncSessionMaker = async_sessionmaker( sync_session_class=RoutingSession ) The :meth:`_orm.Session.get_bind` method is called in a non-asyncio, implicitly non-blocking context in the same manner as ORM event hooks and functions that are invoked via :meth:`.AsyncSession.run_sync`, so routines that wish to run SQL commands inside of :meth:`_orm.Session.get_bind` can continue to do so using blocking-style code, which will be translated to implicitly async calls at the point of invoking IO on the database drivers.

def get_nested_transaction(self) -> Optional[AsyncSessionTransaction]: (source)

Return the current nested transaction in progress, if any. :return: an :class:`_asyncio.AsyncSessionTransaction` object, or ``None``. .. versionadded:: 1.4.18

def get_transaction(self) -> Optional[AsyncSessionTransaction]: (source)

Return the current root transaction in progress, if any. :return: an :class:`_asyncio.AsyncSessionTransaction` object, or ``None``. .. versionadded:: 1.4.18

@identity_map.setter
def identity_map(self, attr: IdentityMap): (source)

Undocumented

def in_nested_transaction(self) -> bool: (source)

Return True if this :class:`_orm.Session` has begun a nested transaction, e.g. SAVEPOINT. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. .. versionadded:: 1.4

def in_transaction(self) -> bool: (source)

Return True if this :class:`_orm.Session` has begun a transaction. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. .. versionadded:: 1.4 .. seealso:: :attr:`_orm.Session.is_active`

async def invalidate(self): (source)

Close this Session, using connection invalidation. For a complete description, see :meth:`_orm.Session.invalidate`.

def is_modified(self, instance: object, include_collections: bool = True) -> bool: (source)

Return ``True`` if the given instance has locally modified attributes. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. This method retrieves the history for each instrumented attribute on the instance and performs a comparison of the current value to its previously committed value, if any. It is in effect a more expensive and accurate version of checking for the given instance in the :attr:`.Session.dirty` collection; a full test for each attribute's net "dirty" status is performed. E.g.:: return session.is_modified(someobject) A few caveats to this method apply: * Instances present in the :attr:`.Session.dirty` collection may report ``False`` when tested with this method. This is because the object may have received change events via attribute mutation, thus placing it in :attr:`.Session.dirty`, but ultimately the state is the same as that loaded from the database, resulting in no net change here. * Scalar attributes may not have recorded the previously set value when a new value was applied, if the attribute was not loaded, or was expired, at the time the new value was received - in these cases, the attribute is assumed to have a change, even if there is ultimately no net change against its database value. SQLAlchemy in most cases does not need the "old" value when a set event occurs, so it skips the expense of a SQL call if the old value isn't present, based on the assumption that an UPDATE of the scalar value is usually needed, and in those few cases where it isn't, is less expensive on average than issuing a defensive SELECT. The "old" value is fetched unconditionally upon set only if the attribute container has the ``active_history`` flag set to ``True``. This flag is set typically for primary key attributes and scalar object references that are not a simple many-to-one. To set this flag for any arbitrary mapped column, use the ``active_history`` argument with :func:`.column_property`. :param instance: mapped instance to be tested for pending changes. :param include_collections: Indicates if multivalued collections should be included in the operation. Setting this to ``False`` is a way to detect only local-column based properties (i.e. scalar columns or many-to-one foreign keys) that would result in an UPDATE for this instance upon flush.

async def merge(self, instance: _O, *, load: bool = True, options: Optional[Sequence[ORMOption]] = None) -> _O: (source)

Copy the state of a given instance into a corresponding instance within this :class:`_asyncio.AsyncSession`. .. seealso:: :meth:`_orm.Session.merge` - main documentation for merge

async def refresh(self, instance: object, attribute_names: Optional[Iterable[str]] = None, with_for_update: Optional[ForUpdateArg] = None): (source)

Expire and refresh the attributes on the given instance. A query will be issued to the database and all attributes will be refreshed with their current database value. This is the async version of the :meth:`_orm.Session.refresh` method. See that method for a complete description of all options. .. seealso:: :meth:`_orm.Session.refresh` - main documentation for refresh

async def rollback(self): (source)

Rollback the current transaction in progress.

async def run_sync(self, fn: Callable[..., Any], *arg: Any, **kw: Any) -> Any: (source)

Invoke the given sync callable passing sync self as the first argument. This method maintains the asyncio event loop all the way through to the database connection by running the given callable in a specially instrumented greenlet. E.g.:: with AsyncSession(async_engine) as session: await session.run_sync(some_business_method) .. note:: The provided callable is invoked inline within the asyncio event loop, and will block on traditional IO calls. IO within this callable should only call into SQLAlchemy's asyncio database APIs which will be properly adapted to the greenlet context. .. seealso:: :ref:`session_run_sync`

@overload
async def scalar(self, statement: TypedReturnsRows[Tuple[_T]], params: Optional[_CoreSingleExecuteParams] = None, *, execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, bind_arguments: Optional[_BindArguments] = None, **kw: Any) -> Optional[_T]:
@overload
async def scalar(self, statement: Executable, params: Optional[_CoreSingleExecuteParams] = None, *, execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, bind_arguments: Optional[_BindArguments] = None, **kw: Any) -> Any:
(source)

Execute a statement and return a scalar result. .. seealso:: :meth:`_orm.Session.scalar` - main documentation for scalar

@overload
async def scalars(self, statement: TypedReturnsRows[Tuple[_T]], params: Optional[_CoreSingleExecuteParams] = None, *, execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, bind_arguments: Optional[_BindArguments] = None, **kw: Any) -> ScalarResult[_T]:
@overload
async def scalars(self, statement: Executable, params: Optional[_CoreSingleExecuteParams] = None, *, execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, bind_arguments: Optional[_BindArguments] = None, **kw: Any) -> ScalarResult[Any]:
(source)

Execute a statement and return scalar results. :return: a :class:`_result.ScalarResult` object .. versionadded:: 1.4.24 Added :meth:`_asyncio.AsyncSession.scalars` .. versionadded:: 1.4.26 Added :meth:`_asyncio.async_scoped_session.scalars` .. seealso:: :meth:`_orm.Session.scalars` - main documentation for scalars :meth:`_asyncio.AsyncSession.stream_scalars` - streaming version

@overload
async def stream(self, statement: TypedReturnsRows[_T], params: Optional[_CoreAnyExecuteParams] = None, *, execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, bind_arguments: Optional[_BindArguments] = None, **kw: Any) -> AsyncResult[_T]:
@overload
async def stream(self, statement: Executable, params: Optional[_CoreAnyExecuteParams] = None, *, execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, bind_arguments: Optional[_BindArguments] = None, **kw: Any) -> AsyncResult[Any]:
(source)

Execute a statement and return a streaming :class:`_asyncio.AsyncResult` object.

@overload
async def stream_scalars(self, statement: TypedReturnsRows[Tuple[_T]], params: Optional[_CoreSingleExecuteParams] = None, *, execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, bind_arguments: Optional[_BindArguments] = None, **kw: Any) -> AsyncScalarResult[_T]:
@overload
async def stream_scalars(self, statement: Executable, params: Optional[_CoreSingleExecuteParams] = None, *, execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, bind_arguments: Optional[_BindArguments] = None, **kw: Any) -> AsyncScalarResult[Any]:
(source)

Execute a statement and return a stream of scalar results. :return: an :class:`_asyncio.AsyncScalarResult` object .. versionadded:: 1.4.24 .. seealso:: :meth:`_orm.Session.scalars` - main documentation for scalars :meth:`_asyncio.AsyncSession.scalars` - non streaming version

dispatch: dispatcher[Session] = (source)

Undocumented

Undocumented

Undocumented

sync_session: Session = (source)

Reference to the underlying :class:`_orm.Session` this :class:`_asyncio.AsyncSession` proxies requests towards. This instance can be used as an event target. .. seealso:: :ref:`asyncio_events`

sync_session_class: Type[Session] = (source)

The class or callable that provides the underlying :class:`_orm.Session` instance for a particular :class:`_asyncio.AsyncSession`. At the class level, this attribute is the default value for the :paramref:`_asyncio.AsyncSession.sync_session_class` parameter. Custom subclasses of :class:`_asyncio.AsyncSession` can override this. At the instance level, this attribute indicates the current class or callable that was used to provide the :class:`_orm.Session` instance for this :class:`_asyncio.AsyncSession` instance. .. versionadded:: 1.4.24

Proxy for the :attr:`_orm.Session.autoflush` attribute on behalf of the :class:`_asyncio.AsyncSession` class.

The set of all instances marked as 'deleted' within this ``Session`` .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class.

The set of all persistent instances considered dirty. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. E.g.:: some_mapped_object in session.dirty Instances are considered dirty when they were modified but not deleted. Note that this 'dirty' calculation is 'optimistic'; most attribute-setting or collection modification operations will mark an instance as 'dirty' and place it in this set, even if there is no net change to the attribute's value. At flush time, the value of each attribute is compared to its previously saved value, and if there's no net change, no SQL operation will occur (this is a more expensive operation so it's only done at flush time). To check if an instance has actionable net changes to its attributes, use the :meth:`.Session.is_modified` method.

Proxy for the :attr:`_orm.Session.identity_map` attribute on behalf of the :class:`_asyncio.AsyncSession` class.

A user-modifiable dictionary. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. The initial value of this dictionary can be populated using the ``info`` argument to the :class:`.Session` constructor or :class:`.sessionmaker` constructor or factory methods. The dictionary here is always local to this :class:`.Session` and can be modified independently of all other :class:`.Session` objects.

True if this :class:`.Session` not in "partial rollback" state. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. .. versionchanged:: 1.4 The :class:`_orm.Session` no longer begins a new transaction immediately, so this attribute will be False when the :class:`_orm.Session` is first instantiated. "partial rollback" state typically indicates that the flush process of the :class:`_orm.Session` has failed, and that the :meth:`_orm.Session.rollback` method must be emitted in order to fully roll back the transaction. If this :class:`_orm.Session` is not in a transaction at all, the :class:`_orm.Session` will autobegin when it is first used, so in this case :attr:`_orm.Session.is_active` will return True. Otherwise, if this :class:`_orm.Session` is within a transaction, and that transaction has not been rolled back internally, the :attr:`_orm.Session.is_active` will also return True. .. seealso:: :ref:`faq_session_rollback` :meth:`_orm.Session.in_transaction`

The set of all instances marked as 'new' within this ``Session``. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class.

@property
no_autoflush: Any = (source)

Return a context manager that disables autoflush. .. container:: class_bases Proxied for the :class:`_orm.Session` class on behalf of the :class:`_asyncio.AsyncSession` class. e.g.:: with session.no_autoflush: some_object = SomeClass() session.add(some_object) # won't autoflush some_object.related_thing = session.query(SomeRelated).first() Operations that proceed within the ``with:`` block will not be subject to flushes occurring upon query access. This is useful when initializing a series of objects which involve existing database queries, where the uncompleted object should not yet be flushed.

@classmethod
def _no_async_engine_events(cls) -> NoReturn: (source)

Undocumented

def _maker_context_manager(self: _AS) -> _AsyncSessionContextManager[_AS]: (source)

Undocumented

_is_asyncio: bool = (source)

Undocumented

_proxied = (source)

Undocumented