Typing and Generics

typing.AsyncGenerator

An asynchronous generator that yields values and can receive sent values. Unlike a synchronous generator it cannot return a value; SendType defaults to None in 3.13. Deprecated typing alias; prefer collections.abc.AsyncGenerator in modern code (3.9+).

Formal Syntax & Structure

python syntaxpython
typing.AsyncGenerator[YieldType, SendType]

Return Value

type expression

Typing construct or runtime result as described; static typing rules are not runtime validation.

Working Example

Example Snippetpython
from typing import AsyncGenerator
import asyncioasync def values()->AsyncGenerator[int,None]:    yield 2    yield 4async def read(): return [x async for x in values()]print(asyncio.run(read()))
Python Reference