Python 3.5+collectionsterm
collections.abc.AsyncIterator
collections.abc — protocols
The async iterator protocol: has __anext__ and __aiter__.
Syntax
isinstance(obj, collections.abc.AsyncIterator)
The isinstance check is structural: anything defining __anext__ and __aiter__ passes, no subclassing or registration needed, but only the presence of the methods is verified, never their behaviour. An async generator is single-pass, so once an async for has drained it, a second loop yields nothing. You rarely implement the protocol by hand — an async def with yield in it gives you one for free.
Examples
import collections.abc as abc
async def ag():
yield 1
print(isinstance(ag(), abc.AsyncIterator)) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy