module documentation

Request helper used by generated clients.

The Request class contains one RPC invocation. It controls retries, authorization, metadata extraction, and synchronous calls. A generated client creates the object. Await the object to perform the RPC. Its methods supply status metadata, synchronous calls, and configurable retries and timeouts.

Key concepts:

  • Authorization loop: If a provider exists, the request authorizes before the RPC. If permitted, it authorizes again after UNAUTHENTICATED.
  • Retry loop: transient errors are retried according to configured retry counts and per-retry timeouts.

The request logic is central to SDK call semantics. Make only small changes that do not affect behavior.

Class Request Contain an RPC invocation with retries and authorization.
Exception RequestError Base exception for errors raised while processing a request.
Exception RequestIsCancelledError Exception raised when a request is cancelled.
Exception RequestIsSentError Exception raised when a request is already sent.
Exception RequestSentNoCallError Exception raised when a request is sent without a call.
Constant DEFAULT_AUTH_TIMEOUT Default timeout including the authorization and the request itself.
Constant DEFAULT_PER_RETRY_TIMEOUT Default per-retry timeout for requests.
Constant DEFAULT_TIMEOUT Default timeout for requests not including authorization.
Type Variable Err Error type variable. Either a protobuf/message or a custom wrapper.
Type Variable Req Request type variable. Either a protobuf/message or a serializable payload.
Type Variable Res Response type variable. Either a protobuf/message or a custom wrapper.
Type Variable T Undocumented
Variable log Undocumented
Function _authorization_deadline_applies Return whether an authorization budget applies to one RPC, if known.
Function _snapshot_request_input Clone a supported message before it crosses to the SDK event loop.
Function _validate_timeout Validate one optional public timeout value.
DEFAULT_AUTH_TIMEOUT = (source)

Default timeout including the authorization and the request itself.

Value
15 * 60.0
DEFAULT_PER_RETRY_TIMEOUT = (source)

Default per-retry timeout for requests.

Value
DEFAULT_TIMEOUT / 3
DEFAULT_TIMEOUT: float = (source)

Default timeout for requests not including authorization.

Value
60.0

Error type variable. Either a protobuf/message or a custom wrapper.

Value
TypeVar('Err')

Request type variable. Either a protobuf/message or a serializable payload.

Value
TypeVar('Req')

Response type variable. Either a protobuf/message or a custom wrapper.

Value
TypeVar('Res')

Undocumented

Value
TypeVar('T')

Undocumented

def _authorization_deadline_applies(channel: Channel, auth_options: dict[str, str]) -> bool | None: (source)

Return whether an authorization budget applies to one RPC, if known.

Authorization timeout is not a second request timeout. It limits the full authorized flow, including re-authentication and request work, but must not shorten an unauthenticated request or one that explicitly disables authorization. Built-in channels expose a caller-safe probe of the provider fixed during construction; actual authentication still runs on the SDK event loop. Legacy channels without that probe return None: callers must not guess that they are unauthenticated or impose either deadline outside their owner loop. Those channels enforce both clocks inside the request authorization and retry state machine, as before.

Parameters
channel:ChannelChannel that owns the RPC.
auth_options:dict[str, str]Snapshotted authorization options for the RPC.
Returns
bool | NoneTrue when authorization applies, False when it does not, or None when only the channel's owner loop can determine it.
def _snapshot_request_input(value: T) -> T: (source)

Clone a supported message before it crosses to the SDK event loop.

Direct generated messages and provider protobuf messages expose CopyFrom. Legacy SDK wrappers expose their provider protobuf through __pb2_message__. Unknown loop-neutral payload types retain their historical pass-through behavior.

Parameters
value:TRequest value to snapshot.
Returns
TIndependent message, or value for an unknown payload type.
def _validate_timeout(value: float | None, name: str) -> float | None: (source)

Validate one optional public timeout value.

None is the documented unlimited form. Non-finite floats do not define a portable deadline for asyncio, concurrent futures, gRPC, and monotonic arithmetic, so callers must use None instead of positive infinity. Negative finite values retain their established immediate-timeout meaning.

Parameters
value:float | NoneTimeout in seconds or None.
name:strParameter name used in the error message.
Returns
float | Nonevalue unchanged.
Raises
ValueErrorIf value is NaN or infinite.