API Reference
StreamRequest
API reference for the StreamRequest base class.
from pymediate import StreamRequest
class StreamRequest[ChunkT]: ...StreamRequest is the base class for messages dispatched with
Mediator.stream(). Its type parameter declares the type of each
yielded item.
| Type parameter | Meaning |
|---|---|
ChunkT | The type of each item yielded by the stream handler |
The generic declaration supplies element-type inference at the stream() call site. Separately,
PyMediate records the chunk type when Python defines the request class so it can validate the stream
handler's annotations.
StreamRequest is separate from Request: use stream() for the former and
send() for the latter. The same StreamRequest class is re-exported from pymediate and
pymediate.sync.
Example
from dataclasses import dataclass
from pymediate import StreamRequest
@dataclass(frozen=True)
class ExportOrders(StreamRequest[bytes]):
customer_id: intDefine stream-request subclasses with a type argument. A bare subclass has no recorded chunk type
and cannot be paired with a valid StreamRequestHandler.
See also
- StreamRequestHandler — yields the chunks
- Mediator.stream() — dispatches a stream request
- Streaming — consumption and cleanup