class StreamRequest(Generic[
Constructor: StreamRequest(channel, route, request, result_class, ...)
Lazy native async call for one of the three streaming RPC shapes.
Use server streams as async context managers when iteration may stop early:
async with client.watch(request) as stream:
async for item in stream:
if done(item):
break
The context exit calls aclose. This call cancels the native stream
and releases its address channel.
A caller-supplied asynchronous request iterator is consumed on the SDK loop. It must not contain state bound to a different event loop. The SDK cannot detect hidden loop ownership in an arbitrary iterator.
A unary request message and authentication options are copied when this
wrapper is created. Each explicit write copies a supported message
before dispatch to the SDK loop. Unknown custom values keep their previous
pass-through behavior and must be safe to share between threads.
Timeout budgets start with the first stream operation. They include time waiting for SDK-loop dispatch, authentication, and the native RPC rather than starting only after a queued operation reaches the internal loop. The authorization budget applies only when a provider is active and authorization is not explicitly disabled.
| Raises | |
ValueError | If timeout or auth_timeout is NaN or infinite. Use None for an unlimited timeout. |
| Async Method | __aenter__ |
Undocumented |
| Async Method | __aexit__ |
Undocumented |
| Method | __aiter__ |
Undocumented |
| Method | __await__ |
Undocumented |
| Method | __init__ |
Undocumented |
| Async Method | aclose |
Cancel the native call and discard its address channel. |
| Method | cancel |
Request cancellation without accessing loop-owned state off-loop. |
| Async Method | done |
Undocumented |
| Async Method | write |
Snapshot and write one request on the SDK event loop. |
| Static Method | _serialize |
Undocumented |
| Method | _abort |
Undocumented |
| Async Method | _aclose |
Abort the native call and release its leased channel. |
| Async Method | _authenticate |
Undocumented |
| Method | _cancel |
Observe asynchronous cancellation cleanup and restore retryability. |
| Method | _check |
Reject a stream inherited across fork before taking its locks. |
| Async Method | _done |
Finish explicit request writes on the call owner loop. |
| Method | _is |
Return the cancellation state under the state lock. |
| Method | _is |
Return the channel-release state under the state lock. |
| Method | _mark |
Publish native completion before the stream wrapper resumes. |
| Async Method | _next |
Read one response while serializing access to the iterator. |
| Async Method | _on |
Run an awaitable on the SDK loop when the channel supports dispatch. |
| Method | _pause |
Pause the request-only stream clock during authentication. |
| Method | _release |
Undocumented |
| Method | _release |
Release transport state without blocking an active caller loop. |
| Method | _remaining |
Return the applicable stream deadline remaining in seconds. |
| Method | _remaining |
Return the request/authentication budget before SDK-loop dispatch. |
| Async Method | _responses |
Undocumented |
| Async Method | _responses |
Yield streaming responses directly on the call owner loop. |
| Async Method | _result |
Undocumented |
| Async Method | _result |
Read a unary response and release the leased channel. |
| Method | _resume |
Resume request timeout and publish completed authentication. |
| Async Method | _start |
Undocumented |
| Async Method | _write |
Write one request on the call owner loop. |
| Instance Variable | _address |
Undocumented |
| Instance Variable | _auth |
Undocumented |
| Instance Variable | _auth |
Undocumented |
| Instance Variable | _authentication |
Undocumented |
| Instance Variable | _authorization |
Undocumented |
| Instance Variable | _authorization |
Undocumented |
| Instance Variable | _call |
Undocumented |
| Instance Variable | _cancel |
Undocumented |
| Instance Variable | _cancel |
Undocumented |
| Instance Variable | _cancelled |
Undocumented |
| Instance Variable | _channel |
Undocumented |
| Instance Variable | _client |
Undocumented |
| Instance Variable | _compression |
Undocumented |
| Instance Variable | _credentials |
Undocumented |
| Instance Variable | _deadlines |
Undocumented |
| Instance Variable | _metadata |
Undocumented |
| Instance Variable | _native |
Undocumented |
| Instance Variable | _owner |
Undocumented |
| Instance Variable | _process |
Undocumented |
| Instance Variable | _read |
Undocumented |
| Instance Variable | _released |
Undocumented |
| Instance Variable | _request |
Undocumented |
| Instance Variable | _request |
Undocumented |
| Instance Variable | _request |
Undocumented |
| Instance Variable | _request |
Undocumented |
| Instance Variable | _response |
Undocumented |
| Instance Variable | _result |
Undocumented |
| Instance Variable | _route |
Undocumented |
| Instance Variable | _server |
Undocumented |
| Instance Variable | _start |
Undocumented |
| Instance Variable | _start |
Undocumented |
| Instance Variable | _start |
Undocumented |
| Instance Variable | _state |
Undocumented |
| Instance Variable | _timeout |
Undocumented |
| Instance Variable | _wait |
Undocumented |
| Instance Variable | _write |
Undocumented |
type[ BaseException] | None, exc: BaseException | None, traceback: object | None):
(source)
¶
Undocumented
Any, route: Route, request: Any, result_class: type[ Any], client_streaming: bool, server_streaming: bool, metadata: Metadata | list[ tuple[ str, str]] | None = None, timeout: float | None = None, auth_timeout: float | None = None, auth_options: dict[ str, str] | None = None, credentials: CallCredentials | None = None, compression: Compression | None = None, wait_for_ready: bool | None = True, grpc_channel_override: AddressChannel | None = None, **unsupported: object):
(source)
¶
Undocumented
Request cancellation without accessing loop-owned state off-loop.
SDK channels dispatch cancellation to the SDK loop. A compatibility channel without immediate scheduling support—including an adapter whose run_async returns the original one-shot awaitable—uses the loop that started the stream instead. A foreign caller receives False if that owner loop is not running or closes during dispatch; it may retry after restoring the loop. As with every accepted event-loop callback, the owner must remain running long enough to execute it. A later asynchronous cleanup failure is logged and makes cancellation retryable when the transport was not released.
| Returns | |
bool | True if native cancellation was applied or accepted for dispatch; otherwise False. A terminal server stream returns False even when its remaining lease cleanup was scheduled. |
Snapshot and write one request on the SDK event loop.
| Parameters | |
request:Req | Request message to write. Supported mutable protobuf messages are copied before dispatch. Unknown custom values retain their historical pass-through behavior and must be thread-safe. |
Observe asynchronous cancellation cleanup and restore retryability.
| Parameters | |
completed:Any | Future-like cancellation submission. |
Finish explicit request writes on the call owner loop.
| Raises | |
TypeError | If the RPC does not accept explicit writes. |
Read one response while serializing access to the iterator.
| Returns | |
Res | Next streaming response. |
| Raises | |
StopAsyncIteration | If the response stream is complete. |
Awaitable[ T], *, enforce_deadline: bool = True, terminate_on_rejection: bool = False) -> T:
(source)
¶
Run an awaitable on the SDK loop when the channel supports dispatch.
| Parameters | |
awaitable:Awaitable[ | Stream work to run. |
enforcebool | Apply the stream's caller-side deadline. Close cleanup disables this limit so an expired stream can release its transport. |
terminatebool | Mark an active stream terminal and discard its lease when close cleanup cannot start. Ordinary operation rejection leaves an existing stream active. |
| Returns | |
T | Result of the stream work. |
Pause the request-only stream clock during authentication.
Queueing before stream startup is already charged. The retained request budget resumes only after authentication succeeds, while the authorization deadline continues to bound authentication plus the native stream lifetime.
Return the applicable stream deadline remaining in seconds.
The first caller-side operation fixes monotonic request and applicable authorization deadlines under the state lock. Later operations reuse those deadlines. Concurrent reads and writes cannot each obtain a new budget. SDK-loop queueing uses the same native RPC lifetime. Before authentication completes, only its overall authorization deadline is exposed to caller-side waiting; request timeout is paused during authentication and resumes for native stream work.
| Parameters | |
initialize:bool | Start the deadlines when no prior stream operation has done so. Cleanup calls leave this false because they must be able to release transport state after a deadline expires. |
| Returns | |
float | None | The smaller remaining request/authorization budget, or None when both configured limits are infinite. |