grpc package¶
Subpackages¶
Module contents¶
gRPC’s Python API.
-
exception
grpc.
FutureTimeoutError
[source]¶ Bases:
exceptions.Exception
Indicates that a method call on a Future timed out.
-
exception
grpc.
FutureCancelledError
[source]¶ Bases:
exceptions.Exception
Indicates that the computation underlying a Future was cancelled.
-
class
grpc.
Future
[source]¶ Bases:
object
A representation of a computation in another control flow.
Computations represented by a Future may be yet to be begun, may be ongoing, or may have already completed.
-
add_done_callback
(fn)[source]¶ Adds a function to be called at completion of the computation.
The callback will be passed this Future object describing the outcome of the computation.
If the computation has already completed, the callback will be called immediately.
Parameters: fn – A callable taking this Future object as its single parameter.
-
cancel
()[source]¶ Attempts to cancel the computation.
This method does not block.
Returns: - True if the computation has not yet begun, will not be allowed to take
- place, and determination of both was possible without blocking. False under all other circumstances including but not limited to the computation’s already having begun, the computation’s already having finished, and the computation’s having been scheduled for execution on a remote system for which a determination of whether or not it commenced before being cancelled cannot be made without blocking.
-
cancelled
()[source]¶ Describes whether the computation was cancelled.
This method does not block.
Returns: - True if the computation was cancelled any time before its result became
- immediately available. False under all other circumstances including but not limited to this object’s cancel method not having been called and the computation’s result having become immediately available.
-
done
()[source]¶ Describes whether the computation has taken place.
This method does not block.
Returns: - True if the computation is known to have either completed or have been
- unscheduled or interrupted. False if the computation may possibly be executing or scheduled to execute later.
-
exception
(timeout=None)[source]¶ Return the exception raised by the computation.
This method may return immediately or may block.
Parameters: timeout – The length of time in seconds to wait for the computation to terminate or be cancelled, or None if this method should block until the computation is terminated or is cancelled no matter how long that takes.
Returns: - The exception raised by the computation, or None if the computation did
not raise an exception.
Raises: FutureTimeoutError
– If a timeout value is passed and the computation does not terminate within the allotted time.FutureCancelledError
– If the computation was cancelled.
-
result
(timeout=None)[source]¶ Accesses the outcome of the computation or raises its exception.
This method may return immediately or may block.
Parameters: timeout – The length of time in seconds to wait for the computation to finish or be cancelled, or None if this method should block until the computation has finished or is cancelled no matter how long that takes.
Returns: The return value of the computation.
Raises: FutureTimeoutError
– If a timeout value is passed and the computation does not terminate within the allotted time.FutureCancelledError
– If the computation was cancelled.Exception
– If the computation raised an exception, this call will raise the same exception.
-
running
()[source]¶ Describes whether the computation is taking place.
This method does not block.
Returns: - True if the computation is scheduled to take place in the future or is
- taking place now, or False if the computation took place in the past or was cancelled.
-
traceback
(timeout=None)[source]¶ Access the traceback of the exception raised by the computation.
This method may return immediately or may block.
Parameters: timeout – The length of time in seconds to wait for the computation to terminate or be cancelled, or None if this method should block until the computation is terminated or is cancelled no matter how long that takes.
Returns: - The traceback of the exception raised by the computation, or None if the
computation did not raise an exception.
Raises: FutureTimeoutError
– If a timeout value is passed and the computation does not terminate within the allotted time.FutureCancelledError
– If the computation was cancelled.
-
-
class
grpc.
ChannelConnectivity
[source]¶ Bases:
enum.Enum
Mirrors grpc_connectivity_state in the gRPC Core.
-
IDLE
¶ The channel is idle.
-
CONNECTING
¶ The channel is connecting.
-
READY
¶ The channel is ready to conduct RPCs.
-
TRANSIENT_FAILURE
¶ The channel has seen a failure from which it expects to recover.
-
SHUTDOWN
¶ The channel has seen a failure from which it cannot recover.
-
CONNECTING
= (1, 'connecting')
-
IDLE
= (0, 'idle')
-
READY
= (2, 'ready')
-
SHUTDOWN
= (4, 'shutdown')
-
TRANSIENT_FAILURE
= (3, 'transient failure')
-
-
class
grpc.
StatusCode
[source]¶ Bases:
enum.Enum
Mirrors grpc_status_code in the gRPC Core.
-
ABORTED
= (10, 'aborted')¶
-
ALREADY_EXISTS
= (6, 'already exists')¶
-
CANCELLED
= (1, 'cancelled')¶
-
DATA_LOSS
= (15, 'data loss')¶
-
DEADLINE_EXCEEDED
= (4, 'deadline exceeded')¶
-
FAILED_PRECONDITION
= (9, 'failed precondition')¶
-
INTERNAL
= (13, 'internal')¶
-
INVALID_ARGUMENT
= (3, 'invalid argument')¶
-
NOT_FOUND
= (5, 'not found')¶
-
OK
= (0, 'ok')¶
-
OUT_OF_RANGE
= (11, 'out of range')¶
-
PERMISSION_DENIED
= (7, 'permission denied')¶
-
RESOURCE_EXHAUSTED
= (8, 'resource exhausted')¶
-
UNAUTHENTICATED
= (16, 'unauthenticated')¶
-
UNAVAILABLE
= (14, 'unavailable')¶
-
UNIMPLEMENTED
= (12, 'unimplemented')¶
-
UNKNOWN
= (2, 'unknown')¶
-
-
exception
grpc.
RpcError
[source]¶ Bases:
exceptions.Exception
Raised by the gRPC library to indicate non-OK-status RPC termination.
-
class
grpc.
RpcContext
[source]¶ Bases:
object
Provides RPC-related information and action.
-
add_callback
(callback)[source]¶ Registers a callback to be called on RPC termination.
Parameters: callback – A no-parameter callable to be called on RPC termination. Returns: - True if the callback was added and will be called later; False if the
- callback was not added and will not later be called (because the RPC already terminated or some other reason).
-
-
class
grpc.
Call
[source]¶ Bases:
grpc.RpcContext
Invocation-side utility object for an RPC.
-
code
()[source]¶ Accesses the status code emitted by the service-side of the RPC.
This method blocks until the value is available.
Returns: The StatusCode value for the RPC.
-
details
()[source]¶ Accesses the details value emitted by the service-side of the RPC.
This method blocks until the value is available.
Returns: The details string of the RPC.
-
-
class
grpc.
ChannelCredentials
(credentials)[source]¶ Bases:
object
A value encapsulating the data required to create a secure Channel.
This class has no supported interface - it exists to define the type of its instances and its instances exist to be passed to other functions.
-
class
grpc.
CallCredentials
(credentials)[source]¶ Bases:
object
A value encapsulating data asserting an identity over a channel.
A CallCredentials may be composed with ChannelCredentials to always assert identity for every call over that Channel.
This class has no supported interface - it exists to define the type of its instances and its instances exist to be passed to other functions.
-
class
grpc.
AuthMetadataContext
[source]¶ Bases:
object
Provides information to call credentials metadata plugins.
-
service_url
¶ A string URL of the service being called into.
-
method_name
¶ A string of the fully qualified method name being called.
-
-
class
grpc.
AuthMetadataPluginCallback
[source]¶ Bases:
object
Callback object received by a metadata plugin.
-
class
grpc.
AuthMetadataPlugin
[source]¶ Bases:
object
A specification for custom authentication.
-
__call__
(context, callback)[source]¶ Implements authentication by passing metadata to a callback.
Implementations of this method must not block.
Parameters: - context – An AuthMetadataContext providing information on the RPC that the plugin is being called to authenticate.
- callback – An AuthMetadataPluginCallback to be invoked either synchronously or asynchronously.
-
-
class
grpc.
ServerCredentials
(credentials)[source]¶ Bases:
object
A value encapsulating the data required to open a secure port on a Server.
This class has no supported interface - it exists to define the type of its instances and its instances exist to be passed to other functions.
-
class
grpc.
UnaryUnaryMultiCallable
[source]¶ Bases:
object
Affords invoking a unary-unary RPC.
-
__call__
(request, timeout=None, metadata=None, credentials=None)[source]¶ Synchronously invokes the underlying RPC.
Parameters: - request – The request value for the RPC.
- timeout – An optional duration of time in seconds to allow for the RPC.
- metadata – Optional metadata to be transmitted to the service-side of the RPC.
- credentials – An optional CallCredentials for the RPC.
Returns: The response value for the RPC.
Raises: RpcError
– Indicating that the RPC terminated with non-OK status. The raised RpcError will also be a Call for the RPC affording the RPC’s metadata, status code, and details.
-
future
(request, timeout=None, metadata=None, credentials=None)[source]¶ Asynchronously invokes the underlying RPC.
Parameters: - request – The request value for the RPC.
- timeout – An optional duration of time in seconds to allow for the RPC.
- metadata – Optional metadata to be transmitted to the service-side of the RPC.
- credentials – An optional CallCredentials for the RPC.
Returns: - An object that is both a Call for the RPC and a Future. In the event of
RPC completion, the return Call-Future’s result value will be the response message of the RPC. Should the event terminate with non-OK status, the returned Call-Future’s exception value will be an RpcError.
-
with_call
(request, timeout=None, metadata=None, credentials=None)[source]¶ Synchronously invokes the underlying RPC.
Parameters: - request – The request value for the RPC.
- timeout – An optional durating of time in seconds to allow for the RPC.
- metadata – Optional metadata to be transmitted to the service-side of the RPC.
- credentials – An optional CallCredentials for the RPC.
Returns: The response value for the RPC and a Call value for the RPC.
Raises: RpcError
– Indicating that the RPC terminated with non-OK status. The raised RpcError will also be a Call for the RPC affording the RPC’s metadata, status code, and details.
-
-
class
grpc.
UnaryStreamMultiCallable
[source]¶ Bases:
object
Affords invoking a unary-stream RPC.
-
__call__
(request, timeout=None, metadata=None, credentials=None)[source]¶ Invokes the underlying RPC.
Parameters: - request – The request value for the RPC.
- timeout – An optional duration of time in seconds to allow for the RPC.
- metadata – An optional metadata to be transmitted to the service-side of the RPC.
- credentials – An optional CallCredentials for the RPC.
Returns: - An object that is both a Call for the RPC and an iterator of response
values. Drawing response values from the returned Call-iterator may raise RpcError indicating termination of the RPC with non-OK status.
-
-
class
grpc.
StreamUnaryMultiCallable
[source]¶ Bases:
object
Affords invoking a stream-unary RPC in any call style.
-
__call__
(request_iterator, timeout=None, metadata=None, credentials=None)[source]¶ Synchronously invokes the underlying RPC.
Parameters: - request_iterator – An iterator that yields request values for the RPC.
- timeout – An optional duration of time in seconds to allow for the RPC.
- metadata – Optional metadata to be transmitted to the service-side of the RPC.
- credentials – An optional CallCredentials for the RPC.
Returns: The response value for the RPC.
Raises: RpcError
– Indicating that the RPC terminated with non-OK status. The raised RpcError will also be a Call for the RPC affording the RPC’s metadata, status code, and details.
-
future
(request_iterator, timeout=None, metadata=None, credentials=None)[source]¶ Asynchronously invokes the underlying RPC.
Parameters: - request_iterator – An iterator that yields request values for the RPC.
- timeout – An optional duration of time in seconds to allow for the RPC.
- metadata – Optional metadata to be transmitted to the service-side of the RPC.
- credentials – An optional CallCredentials for the RPC.
Returns: - An object that is both a Call for the RPC and a Future. In the event of
RPC completion, the return Call-Future’s result value will be the response message of the RPC. Should the event terminate with non-OK status, the returned Call-Future’s exception value will be an RpcError.
-
with_call
(request_iterator, timeout=None, metadata=None, credentials=None)[source]¶ Synchronously invokes the underlying RPC.
Parameters: - request_iterator – An iterator that yields request values for the RPC.
- timeout – An optional duration of time in seconds to allow for the RPC.
- metadata – Optional metadata to be transmitted to the service-side of the RPC.
- credentials – An optional CallCredentials for the RPC.
Returns: The response value for the RPC and a Call for the RPC.
Raises: RpcError
– Indicating that the RPC terminated with non-OK status. The raised RpcError will also be a Call for the RPC affording the RPC’s metadata, status code, and details.
-
-
class
grpc.
StreamStreamMultiCallable
[source]¶ Bases:
object
Affords invoking a stream-stream RPC in any call style.
-
__call__
(request_iterator, timeout=None, metadata=None, credentials=None)[source]¶ Invokes the underlying RPC.
Parameters: - request_iterator – An iterator that yields request values for the RPC.
- timeout – An optional duration of time in seconds to allow for the RPC.
- metadata – Optional metadata to be transmitted to the service-side of the RPC.
- credentials – An optional CallCredentials for the RPC.
Returns: - An object that is both a Call for the RPC and an iterator of response
values. Drawing response values from the returned Call-iterator may raise RpcError indicating termination of the RPC with non-OK status.
-
-
class
grpc.
Channel
[source]¶ Bases:
object
Affords RPC invocation via generic methods.
-
stream_stream
(method, request_serializer=None, response_deserializer=None)[source]¶ Creates a StreamStreamMultiCallable for a stream-stream method.
Parameters: - method – The name of the RPC method.
- request_serializer – Optional behaviour for serializing the request message. Request goes unserialized in case None is passed.
- response_deserializer – Optional behaviour for deserializing the response message. Response goes undeserialized in case None is passed.
Returns: A StreamStreamMultiCallable value for the named stream-stream method.
-
stream_unary
(method, request_serializer=None, response_deserializer=None)[source]¶ Creates a StreamUnaryMultiCallable for a stream-unary method.
Parameters: - method – The name of the RPC method.
- request_serializer – Optional behaviour for serializing the request message. Request goes unserialized in case None is passed.
- response_deserializer – Optional behaviour for deserializing the response message. Response goes undeserialized in case None is passed.
Returns: A StreamUnaryMultiCallable value for the named stream-unary method.
-
subscribe
(callback, try_to_connect=False)[source]¶ Subscribes to this Channel’s connectivity.
Parameters: - callback – A callable to be invoked and passed a ChannelConnectivity value describing this Channel’s connectivity. The callable will be invoked immediately upon subscription and again for every change to this Channel’s connectivity thereafter until it is unsubscribed or this Channel object goes out of scope.
- try_to_connect – A boolean indicating whether or not this Channel should attempt to connect if it is not already connected and ready to conduct RPCs.
-
unary_stream
(method, request_serializer=None, response_deserializer=None)[source]¶ Creates a UnaryStreamMultiCallable for a unary-stream method.
Parameters: - method – The name of the RPC method.
- request_serializer – Optional behaviour for serializing the request message. Request goes unserialized in case None is passed.
- response_deserializer – Optional behaviour for deserializing the response message. Response goes undeserialized in case None is passed.
Returns: A UnaryStreamMultiCallable value for the name unary-stream method.
-
unary_unary
(method, request_serializer=None, response_deserializer=None)[source]¶ Creates a UnaryUnaryMultiCallable for a unary-unary method.
Parameters: - method – The name of the RPC method.
- request_serializer – Optional behaviour for serializing the request message. Request goes unserialized in case None is passed.
- response_deserializer – Optional behaviour for deserializing the response message. Response goes undeserialized in case None is passed.
Returns: A UnaryUnaryMultiCallable value for the named unary-unary method.
-
-
class
grpc.
ServicerContext
[source]¶ Bases:
grpc.RpcContext
A context object passed to method implementations.
-
invocation_metadata
()[source]¶ Accesses the metadata from the invocation-side of the RPC.
Returns: The invocation metadata.
-
peer
()[source]¶ Identifies the peer that invoked the RPC being serviced.
Returns: A string identifying the peer that invoked the RPC being serviced.
-
send_initial_metadata
(initial_metadata)[source]¶ Sends the initial metadata value to the invocation-side of the RPC.
This method need not be called by method implementations if they have no service-side initial metadata to transmit.
Parameters: initial_metadata – The initial metadata.
-
set_code
(code)[source]¶ Accepts the status code of the RPC.
This method need not be called by method implementations if they wish the gRPC runtime to determine the status code of the RPC.
Parameters: code – A StatusCode value to be transmitted to the invocation side of the RPC as the status code of the RPC.
-
-
class
grpc.
RpcMethodHandler
[source]¶ Bases:
object
An implementation of a single RPC method.
-
request_streaming
¶ Whether the RPC supports exactly one request message or any arbitrary number of request messages.
-
response_streaming
¶ Whether the RPC supports exactly one response message or any arbitrary number of response messages.
-
request_deserializer
¶ A callable behavior that accepts a byte string and returns an object suitable to be passed to this object’s business logic, or None to indicate that this object’s business logic should be passed the raw request bytes.
-
response_serializer
¶ A callable behavior that accepts an object produced by this object’s business logic and returns a byte string, or None to indicate that the byte strings produced by this object’s business logic should be transmitted on the wire as they are.
-
unary_unary
¶ This object’s application-specific business logic as a callable value that takes a request value and a ServicerContext object and returns a response value. Only non-None if both request_streaming and response_streaming are False.
-
unary_stream
¶ This object’s application-specific business logic as a callable value that takes a request value and a ServicerContext object and returns an iterator of response values. Only non-None if request_streaming is False and response_streaming is True.
-
stream_unary
¶ This object’s application-specific business logic as a callable value that takes an iterator of request values and a ServicerContext object and returns a response value. Only non-None if request_streaming is True and response_streaming is False.
-
stream_stream
¶ This object’s application-specific business logic as a callable value that takes an iterator of request values and a ServicerContext object and returns an iterator of response values. Only non-None if request_streaming and response_streaming are both True.
-
-
class
grpc.
HandlerCallDetails
[source]¶ Bases:
object
Describes an RPC that has just arrived for service. .. attribute:: method
The method name of the RPC.
-
class
grpc.
GenericRpcHandler
[source]¶ Bases:
object
An implementation of arbitrarily many RPC methods.
-
class
grpc.
ServiceRpcHandler
[source]¶ Bases:
grpc.GenericRpcHandler
An implementation of RPC methods belonging to a service.
A service handles RPC methods with structured names of the form ‘/Service.Name/Service.MethodX’, where ‘Service.Name’ is the value returned by service_name(), and ‘Service.MethodX’ is the service method name. A service can have multiple service methods names, but only a single service name.
-
class
grpc.
Server
[source]¶ Bases:
object
Services RPCs.
-
add_generic_rpc_handlers
(generic_rpc_handlers)[source]¶ Registers GenericRpcHandlers with this Server.
This method is only safe to call before the server is started.
Parameters: generic_rpc_handlers – An iterable of GenericRpcHandlers that will be used to service RPCs after this Server is started.
-
add_insecure_port
(address)[source]¶ Reserves a port for insecure RPC service once this Server becomes active.
This method may only be called before calling this Server’s start method is called.
Parameters: address – The address for which to open a port. Returns: - An integer port on which RPCs will be serviced after this link has been
- started. This is typically the same number as the port number contained in the passed address, but will likely be different if the port number contained in the passed address was zero.
-
add_secure_port
(address, server_credentials)[source]¶ Reserves a port for secure RPC service after this Server becomes active.
This method may only be called before calling this Server’s start method is called.
Parameters: - address – The address for which to open a port.
- server_credentials – A ServerCredentials.
Returns: - An integer port on which RPCs will be serviced after this link has been
started. This is typically the same number as the port number contained in the passed address, but will likely be different if the port number contained in the passed address was zero.
-
start
()[source]¶ Starts this Server’s service of RPCs.
This method may only be called while the server is not serving RPCs (i.e. it is not idempotent).
-
stop
(grace)[source]¶ Stops this Server’s service of RPCs.
All calls to this method immediately stop service of new RPCs. When existing RPCs are aborted is controlled by the grace period parameter passed to this method.
This method may be called at any time and is idempotent. Passing a smaller grace value than has been passed in a previous call will have the effect of stopping the Server sooner. Passing a larger grace value than has been passed in a previous call will not have the effect of stopping the server later.
This method does not block for any significant length of time. If None is passed as the grace value, existing RPCs are immediately aborted and this method blocks until this Server is completely stopped.
Parameters: grace – A duration of time in seconds or None. If a duration of time in seconds, the time to allow existing RPCs to complete before being aborted by this Server’s stopping. If None, all RPCs will be aborted immediately and this method will block until this Server is completely stopped. Returns: A threading.Event that will be set when this Server has completely stopped. The returned event may not be set until after the full grace period (if some ongoing RPC continues for the full length of the period) of it may be set much sooner (such as if this Server had no RPCs underway at the time it was stopped or if all RPCs that it had underway completed very early in the grace period).
-
-
grpc.
unary_unary_rpc_method_handler
(behavior, request_deserializer=None, response_serializer=None)[source]¶ Creates an RpcMethodHandler for a unary-unary RPC method.
Parameters: - behavior – The implementation of an RPC method as a callable behavior taking a single request value and returning a single response value.
- request_deserializer – An optional request deserialization behavior.
- response_serializer – An optional response serialization behavior.
Returns: - An RpcMethodHandler for a unary-unary RPC method constructed from the given
parameters.
-
grpc.
unary_stream_rpc_method_handler
(behavior, request_deserializer=None, response_serializer=None)[source]¶ Creates an RpcMethodHandler for a unary-stream RPC method.
Parameters: - behavior – The implementation of an RPC method as a callable behavior taking a single request value and returning an iterator of response values.
- request_deserializer – An optional request deserialization behavior.
- response_serializer – An optional response serialization behavior.
Returns: - An RpcMethodHandler for a unary-stream RPC method constructed from the
given parameters.
-
grpc.
stream_unary_rpc_method_handler
(behavior, request_deserializer=None, response_serializer=None)[source]¶ Creates an RpcMethodHandler for a stream-unary RPC method.
Parameters: - behavior – The implementation of an RPC method as a callable behavior taking an iterator of request values and returning a single response value.
- request_deserializer – An optional request deserialization behavior.
- response_serializer – An optional response serialization behavior.
Returns: - An RpcMethodHandler for a stream-unary RPC method constructed from the
given parameters.
-
grpc.
stream_stream_rpc_method_handler
(behavior, request_deserializer=None, response_serializer=None)[source]¶ Creates an RpcMethodHandler for a stream-stream RPC method.
Parameters: - behavior – The implementation of an RPC method as a callable behavior taking an iterator of request values and returning an iterator of response values.
- request_deserializer – An optional request deserialization behavior.
- response_serializer – An optional response serialization behavior.
Returns: - An RpcMethodHandler for a stream-stream RPC method constructed from the
given parameters.
-
grpc.
method_handlers_generic_handler
(service, method_handlers)[source]¶ Creates a grpc.GenericRpcHandler from RpcMethodHandlers.
Parameters: - service – A service name to be used for the given method handlers.
- method_handlers – A dictionary from method name to RpcMethodHandler implementing the named method.
Returns: A GenericRpcHandler constructed from the given parameters.
-
grpc.
ssl_channel_credentials
(root_certificates=None, private_key=None, certificate_chain=None)[source]¶ Creates a ChannelCredentials for use with an SSL-enabled Channel.
Parameters: - root_certificates – The PEM-encoded root certificates or unset to ask for them to be retrieved from a default location.
- private_key – The PEM-encoded private key to use or unset if no private key should be used.
- certificate_chain – The PEM-encoded certificate chain to use or unset if no certificate chain should be used.
Returns: A ChannelCredentials for use with an SSL-enabled Channel.
-
grpc.
metadata_call_credentials
(metadata_plugin, name=None)[source]¶ Construct CallCredentials from an AuthMetadataPlugin.
Parameters: - metadata_plugin – An AuthMetadataPlugin to use as the authentication behavior in the created CallCredentials.
- name – A name for the plugin.
Returns: A CallCredentials.
-
grpc.
access_token_call_credentials
(access_token)[source]¶ Construct CallCredentials from an access token.
Parameters: access_token – A string to place directly in the http request authorization header, ie “authorization: Bearer <access_token>”. Returns: A CallCredentials.
-
grpc.
composite_call_credentials
(*call_credentials)[source]¶ Compose multiple CallCredentials to make a new CallCredentials.
Parameters: *call_credentials – At least two CallCredentials objects. Returns: A CallCredentials object composed of the given CallCredentials objects.
-
grpc.
composite_channel_credentials
(channel_credentials, *call_credentials)[source]¶ Compose a ChannelCredentials and one or more CallCredentials objects.
Parameters: - channel_credentials – A ChannelCredentials.
- *call_credentials – One or more CallCredentials objects.
Returns: - A ChannelCredentials composed of the given ChannelCredentials and
CallCredentials objects.
-
grpc.
ssl_server_credentials
(private_key_certificate_chain_pairs, root_certificates=None, require_client_auth=False)[source]¶ Creates a ServerCredentials for use with an SSL-enabled Server.
Parameters: - private_key_certificate_chain_pairs – A nonempty sequence each element of which is a pair the first element of which is a PEM-encoded private key and the second element of which is the corresponding PEM-encoded certificate chain.
- root_certificates – PEM-encoded client root certificates to be used for verifying authenticated clients. If omitted, require_client_auth must also be omitted or be False.
- require_client_auth – A boolean indicating whether or not to require clients to be authenticated. May only be True if root_certificates is not None.
Returns: A ServerCredentials for use with an SSL-enabled Server.
-
grpc.
channel_ready_future
(channel)[source]¶ Creates a Future tracking when a Channel is ready.
Cancelling the returned Future does not tell the given Channel to abandon attempts it may have been making to connect; cancelling merely deactivates the returned Future’s subscription to the given Channel’s connectivity.
Parameters: channel – A Channel. Returns: - A Future that matures when the given Channel has connectivity
- ChannelConnectivity.READY.
-
grpc.
insecure_channel
(target, options=None)[source]¶ Creates an insecure Channel to a server.
Parameters: - target – The target to which to connect.
- options – A sequence of string-value pairs according to which to configure the created channel.
Returns: A Channel to the target through which RPCs may be conducted.
-
grpc.
secure_channel
(target, credentials, options=None)[source]¶ Creates a secure Channel to a server.
Parameters: - target – The target to which to connect.
- credentials – A ChannelCredentials instance.
- options – A sequence of string-value pairs according to which to configure the created channel.
Returns: A Channel to the target through which RPCs may be conducted.
-
grpc.
server
(thread_pool, handlers=None, options=None, maximum_concurrent_rpcs=None)[source]¶ Creates a Server with which RPCs can be serviced.
Parameters: - thread_pool – A futures.ThreadPoolExecutor to be used by the returned Server to service RPCs.
- handlers – An optional sequence of GenericRpcHandlers to be used to service RPCs after the returned Server is started. These handlers need not be the only handlers the server will use to service RPCs; other handlers may later be added by calling add_generic_rpc_handlers any time before the returned Server is started.
- options – A sequence of string-value pairs according to which to configure the created server.
- maximum_concurrent_rpcs – The maximum number of concurrent RPCs this server will service before returning status RESOURCE_EXHAUSTED, or None to indicate no limit.
Returns: A Server with which RPCs can be serviced.
Glossary¶
- metadatum
- A key-value pair included in the HTTP header. It is a
2-tuple where the first entry is the key and the
second is the value, i.e. (key, value). The metadata key is an ASCII str,
and must be a valid HTTP header name. The metadata value can be
either a valid HTTP ASCII str, or bytes. If bytes are provided,
the key must end with ‘-bin’, i.e.
('binary-metadata-bin', b'\x00\xFF')
- metadata
- A sequence of metadatum.