14 """Abstract base classes for server-side classes."""
17 from typing
import Generic, Iterable, Mapping, Optional, Sequence
21 from ._metadata
import Metadata
22 from ._typing
import DoneCallbackType
23 from ._typing
import MetadataType
24 from ._typing
import RequestType
25 from ._typing
import ResponseType
35 """Registers GenericRpcHandlers with this Server.
37 This method is only safe to call before the server is started.
40 generic_rpc_handlers: A sequence of GenericRpcHandlers that will be
46 """Opens an insecure port for accepting RPCs.
48 A port is a communication endpoint that used by networking protocols,
49 like TCP and UDP. To date, we only support TCP.
51 This method may only be called before starting the server.
54 address: The address for which to open a port. If the port is 0,
55 or not specified in the address, then the gRPC runtime will choose a port.
58 An integer port on which the server will accept RPC requests.
64 """Opens a secure port for accepting RPCs.
66 A port is a communication endpoint that used by networking protocols,
67 like TCP and UDP. To date, we only support TCP.
69 This method may only be called before starting the server.
72 address: The address for which to open a port.
73 if the port is 0, or not specified in the address, then the gRPC
74 runtime will choose a port.
75 server_credentials: A ServerCredentials object.
78 An integer port on which the server will accept RPC requests.
83 """Starts this Server.
85 This method may only be called once. (i.e. it is not idempotent).
89 async
def stop(self, grace: Optional[float]) ->
None:
92 This method immediately stops the server from servicing new RPCs in
95 If a grace period is specified, this method returns immediately and all
96 RPCs active at the end of the grace period are aborted. If a grace
97 period is not specified (by passing None for grace), all existing RPCs
98 are aborted immediately and this method blocks until the last RPC
101 This method is idempotent and may be called at any time. Passing a
102 smaller grace value in a subsequent call will have the effect of
103 stopping the Server sooner (passing None will have the effect of
104 stopping the server immediately). Passing a larger grace value in a
105 subsequent call will not have the effect of stopping the server later
106 (i.e. the most restrictive grace value is used).
109 grace: A duration of time in seconds or None.
114 timeout: Optional[float] =
None) -> bool:
115 """Continues current coroutine once the server stops.
117 This is an EXPERIMENTAL API.
119 The wait will not consume computational resources during blocking, and
120 it will block until one of the two following conditions are met:
122 1) The server is stopped or terminated;
123 2) A timeout occurs if timeout is not `None`.
125 The timeout argument works in the same way as `threading.Event.wait()`.
126 https://docs.python.org/3/library/threading.html#threading.Event.wait
129 timeout: A floating point number specifying a timeout for the
130 operation in seconds.
133 A bool indicates if the operation times out.
139 """A context object passed to method implementations."""
142 async
def read(self) -> RequestType:
143 """Reads one message from the RPC.
145 Only one read operation is allowed simultaneously.
148 A response message of the RPC.
151 An RpcError exception if the read failed.
155 async
def write(self, message: ResponseType) ->
None:
156 """Writes one message to the RPC.
158 Only one write operation is allowed simultaneously.
161 An RpcError exception if the write failed.
166 initial_metadata: MetadataType) ->
None:
167 """Sends the initial metadata value to the client.
169 This method need not be called by implementations if they have no
170 metadata to add to what the gRPC runtime will transmit.
173 initial_metadata: The initial :term:`metadata`.
179 code: grpc.StatusCode,
181 trailing_metadata: MetadataType = tuple()) ->
None:
182 """Raises an exception to terminate the RPC with a non-OK status.
184 The code and details passed as arguments will supercede any existing
188 code: A StatusCode object to be sent to the client.
189 It must not be StatusCode.OK.
190 details: A UTF-8-encodable string to be sent to the client upon
191 termination of the RPC.
192 trailing_metadata: A sequence of tuple represents the trailing
196 Exception: An exception is always raised to signal the abortion the
197 RPC to the gRPC runtime.
202 """Sends the trailing metadata for the RPC.
204 This method need not be called by implementations if they have no
205 metadata to add to what the gRPC runtime will transmit.
208 trailing_metadata: The trailing :term:`metadata`.
213 """Accesses the metadata sent by the client.
216 The invocation :term:`metadata`.
221 """Sets the value to be used as status code upon RPC completion.
223 This method need not be called by method implementations if they wish
224 the gRPC runtime to determine the status code of the RPC.
227 code: A StatusCode object to be sent to the client.
232 """Sets the value to be used the as detail string upon RPC completion.
234 This method need not be called by method implementations if they have
235 no details to transmit.
238 details: A UTF-8-encodable string to be sent to the client upon
239 termination of the RPC.
244 """Set the compression algorithm to be used for the entire call.
246 This is an EXPERIMENTAL method.
249 compression: An element of grpc.compression, e.g.
250 grpc.compression.Gzip.
255 """Disables compression for the next response message.
257 This is an EXPERIMENTAL method.
259 This method will override any compression configuration set during
260 server creation or set on the call.
265 """Identifies the peer that invoked the RPC being serviced.
268 A string identifying the peer that invoked the RPC being serviced.
269 The string format is determined by gRPC runtime.
274 """Gets one or more peer identity(s).
277 servicer_context.auth_context().get(servicer_context.peer_identity_key())
280 An iterable of the identities, or None if the call is not
281 authenticated. Each identity is returned as a raw bytes type.
286 """The auth property used to identify the peer.
288 For example, "x509_common_name" or "x509_subject_alternative_name" are
289 used to identify an SSL peer.
292 The auth property (string) that indicates the
293 peer identity, or None if the call is not authenticated.
298 """Gets the auth context for the call.
301 A map of strings to an iterable of bytes for each auth property.
305 """Describes the length of allowed time remaining for the RPC.
308 A nonnegative float indicating the length of allowed time in seconds
309 remaining for the RPC to complete before it is considered to have
310 timed out, or None if no deadline was specified for the RPC.
314 """Access value to be used as trailing metadata upon RPC completion.
316 This is an EXPERIMENTAL API.
319 The trailing :term:`metadata` for the RPC.
321 raise NotImplementedError()
324 """Accesses the value to be used as status code upon RPC completion.
326 This is an EXPERIMENTAL API.
329 The StatusCode value for the RPC.
331 raise NotImplementedError()
334 """Accesses the value to be used as detail string upon RPC completion.
336 This is an EXPERIMENTAL API.
339 The details string of the RPC.
341 raise NotImplementedError()
344 """Registers a callback to be called on RPC termination.
346 This is an EXPERIMENTAL API.
349 callback: A callable object will be called with the servicer context
350 object as its only argument.
354 """Return True if the RPC is cancelled.
356 The RPC is cancelled when the cancellation was requested with cancel().
358 This is an EXPERIMENTAL API.
361 A bool indicates whether the RPC is cancelled or not.
365 """Return True if the RPC is done.
367 An RPC is done if the RPC is completed, cancelled or aborted.
369 This is an EXPERIMENTAL API.
372 A bool indicates if the RPC is done.