Built-in Functions and Types

aiter()

Obtain the asynchronous iterator from an object supporting the async iteration protocol. The result can be advanced with await anext(iterator) or consumed with async for. Unlike iter(), there is no callable-and-sentinel form. A normal synchronous list is not an asynchronous iterable; an invalid __aiter__ result raises TypeError.

Formal Syntax & Structure

python syntaxpython
aiter(async_iterable, /)

Parameters & Attributes

NameTypeDescription
async_iterableasynchronous iterableObject implementing the asynchronous iteration protocol; positional only.

Return Value

asynchronous iterator

Iterator supplied by __aiter__(); it may be the original object.

Working Example

Example Snippetpython
async def readings():    yield 12    yield 18
async def main():    iterator = aiter(readings())    print(await anext(iterator))    print(await anext(iterator))
import asyncioasyncio.run(main())
Python Reference