grpc.beta package¶
Submodules¶
grpc.beta.implementations module¶
Entry points into the Beta API of gRPC Python.
-
class
grpc.beta.implementations.
Channel
(channel)[source]¶ Bases:
object
A channel to a remote host through which RPCs may be conducted.
Only the “subscribe” and “unsubscribe” methods are supported for application use. This class’ instance constructor and all other attributes are unsupported.
-
subscribe
(callback, try_to_connect=None)[source]¶ Subscribes to this Channel’s connectivity.
Parameters: - callback – A callable to be invoked and passed an interfaces.ChannelConnectivity identifying 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.
- 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.
-
-
class
grpc.beta.implementations.
ServerOptions
(multi_method_implementation, request_deserializers, response_serializers, thread_pool, thread_pool_size, default_timeout, maximum_timeout)[source]¶ Bases:
object
A value encapsulating the various options for creation of a Server.
This class and its instances have no supported interface - it exists to define the type of its instances and its instances exist to be passed to other functions.
-
class
grpc.beta.implementations.
StubOptions
(host, request_serializers, response_deserializers, metadata_transformer, thread_pool, thread_pool_size)[source]¶ Bases:
object
A value encapsulating the various options for creation of a Stub.
This class and its instances have no supported interface - it exists to define the type of its instances and its instances exist to be passed to other functions.
-
grpc.beta.implementations.
dynamic_stub
(channel, service, cardinalities, options=None)[source]¶ Creates a face.DynamicStub with which RPCs can be invoked.
Parameters: - channel – A Channel for the returned face.DynamicStub to use.
- service – The package-qualified full name of the service.
- cardinalities – A dictionary from RPC method name to cardinality.Cardinality value identifying the cardinality of the RPC method.
- options – An optional StubOptions value further customizing the functionality of the returned face.DynamicStub.
Returns: A face.DynamicStub with which RPCs can be invoked.
-
grpc.beta.implementations.
generic_stub
(channel, options=None)[source]¶ Creates a face.GenericStub on which RPCs can be made.
Parameters: - channel – A Channel for use by the created stub.
- options – A StubOptions customizing the created stub.
Returns: A face.GenericStub on which RPCs can be made.
-
grpc.beta.implementations.
google_call_credentials
(credentials)[source]¶ Construct CallCredentials from GoogleCredentials.
Parameters: credentials – A GoogleCredentials object from the oauth2client library. Returns: A CallCredentials object for use in a GRPCCallOptions object.
-
grpc.beta.implementations.
insecure_channel
(host, port)[source]¶ Creates an insecure Channel to a remote host.
Parameters: - host – The name of the remote host to which to connect.
- port – The port of the remote host to which to connect. If None only the ‘host’ part will be used.
Returns: A Channel to the remote host through which RPCs may be conducted.
-
grpc.beta.implementations.
secure_channel
(host, port, channel_credentials)[source]¶ Creates a secure Channel to a remote host.
Parameters: - host – The name of the remote host to which to connect.
- port – The port of the remote host to which to connect. If None only the ‘host’ part will be used.
- channel_credentials – A ChannelCredentials.
Returns: A secure Channel to the remote host through which RPCs may be conducted.
-
grpc.beta.implementations.
server
(service_implementations, options=None)[source]¶ Creates an interfaces.Server with which RPCs can be serviced.
Parameters: - service_implementations – A dictionary from service name-method name pair to face.MethodImplementation.
- options – An optional ServerOptions value further customizing the functionality of the returned Server.
Returns: An interfaces.Server with which RPCs can be serviced.
-
grpc.beta.implementations.
server_options
(multi_method_implementation=None, request_deserializers=None, response_serializers=None, thread_pool=None, thread_pool_size=None, default_timeout=None, maximum_timeout=None)[source]¶ Creates a ServerOptions value to be passed at server creation.
All parameters are optional and should always be passed by keyword.
Parameters: - multi_method_implementation – A face.MultiMethodImplementation to be called to service an RPC if the server has no specific method implementation for the name of the RPC for which service was requested.
- request_deserializers – A dictionary from service name-method name pair to request deserialization behavior.
- response_serializers – A dictionary from service name-method name pair to response serialization behavior.
- thread_pool – A thread pool to use in stubs.
- thread_pool_size – The size of thread pool to create for use in stubs; ignored if thread_pool has been passed.
- default_timeout – A duration in seconds to allow for RPC service when servicing RPCs that did not include a timeout value when invoked.
- maximum_timeout – A duration in seconds to allow for RPC service when servicing RPCs no matter what timeout value was passed when the RPC was invoked.
Returns: A StubOptions value created from the passed parameters.
-
grpc.beta.implementations.
stub_options
(host=None, request_serializers=None, response_deserializers=None, metadata_transformer=None, thread_pool=None, thread_pool_size=None)[source]¶ Creates a StubOptions value to be passed at stub creation.
All parameters are optional and should always be passed by keyword.
Parameters: - host – A host string to set on RPC calls.
- request_serializers – A dictionary from service name-method name pair to request serialization behavior.
- response_deserializers – A dictionary from service name-method name pair to response deserialization behavior.
- metadata_transformer – A callable that given a metadata object produces another metadata object to be used in the underlying communication on the wire.
- thread_pool – A thread pool to use in stubs.
- thread_pool_size – The size of thread pool to create for use in stubs; ignored if thread_pool has been passed.
Returns: A StubOptions value created from the passed parameters.
grpc.beta.interfaces module¶
Constants and interfaces of the Beta API of gRPC Python.
-
class
grpc.beta.interfaces.
GRPCCallOptions
(disable_compression, subcall_of, credentials)[source]¶ Bases:
object
A value encapsulating gRPC-specific options passed on RPC invocation.
This class and its instances have no supported interface - it exists to define the type of its instances and its instances exist to be passed to other functions.
-
class
grpc.beta.interfaces.
GRPCInvocationContext
[source]¶ Bases:
object
Exposes gRPC-specific options and behaviors to code invoking RPCs.
-
class
grpc.beta.interfaces.
GRPCServicerContext
[source]¶ Bases:
object
Exposes gRPC-specific options and behaviors to code servicing RPCs.
-
class
grpc.beta.interfaces.
Server
[source]¶ Bases:
object
Services RPCs.
-
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.
Parameters: grace – A duration of time in seconds to allow existing RPCs to complete before being aborted by this Server’s stopping. May be zero for immediate abortion of all in-progress RPCs. 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.beta.interfaces.
grpc_call_options
(disable_compression=False, credentials=None)[source]¶ Creates a GRPCCallOptions value to be passed at RPC invocation.
All parameters are optional and should always be passed by keyword.
Parameters: - disable_compression – A boolean indicating whether or not compression should be disabled for the request object of the RPC. Only valid for request-unary RPCs.
- credentials – A CallCredentials object to use for the invoked RPC.
grpc.beta.utilities module¶
Utilities for the gRPC Python Beta API.
-
grpc.beta.utilities.
channel_ready_future
(channel)[source]¶ Creates a future.Future tracking when an implementations.Channel is ready.
Cancelling the returned future.Future does not tell the given implementations.Channel to abandon attempts it may have been making to connect; cancelling merely deactivates the return future.Future’s subscription to the given implementations.Channel’s connectivity.
Parameters: channel – An implementations.Channel. Returns: - A future.Future that matures when the given Channel has connectivity
- interfaces.ChannelConnectivity.READY.