Python 3.10+Built-in functionsfunction
aiter()
Built-in functions
Async analog of iter(): return an async iterator for the object (calls __aiter__).
Syntax
aiter(async_iterable)
Added in Python 3.10. It hands back the async iterator itself, not an awaitable — await aiter(obj) is wrong; the await belongs in front of anext(). It only accepts objects that define __aiter__ (async generators, async streams); a plain list raises TypeError and needs iter(). You rarely call it by hand, since async for does it for you.
Examples
import asyncio
async def main():
async def agen():
yield 1
yield 2
it = aiter(agen())
print(await anext(it)) # → 1
asyncio.run(main())
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy