14 """Entry points into the Beta API of gRPC Python."""
22 from grpc
import _auth
34 ssl_channel_credentials = grpc.ssl_channel_credentials
40 def plugin(context, callback):
43 callback(_metadata.unbeta(beta_metadata), error)
45 metadata_plugin(context, wrapped_callback)
51 """Construct CallCredentials from GoogleCredentials.
54 credentials: A GoogleCredentials object from the oauth2client library.
57 A CallCredentials object for use in a GRPCCallOptions object.
62 access_token_call_credentials = grpc.access_token_call_credentials
63 composite_call_credentials = grpc.composite_call_credentials
64 composite_channel_credentials = grpc.composite_channel_credentials
68 """A channel to a remote host through which RPCs may be conducted.
70 Only the "subscribe" and "unsubscribe" methods are supported for application
71 use. This class' instance constructor and all other attributes are
79 """Subscribes to this Channel's connectivity.
82 callback: A callable to be invoked and passed an
83 interfaces.ChannelConnectivity identifying this Channel's connectivity.
84 The callable will be invoked immediately upon subscription and again for
85 every change to this Channel's connectivity thereafter until it is
87 try_to_connect: A boolean indicating whether or not this Channel should
88 attempt to connect if it is not already connected and ready to conduct
94 """Unsubscribes a callback from this Channel's connectivity.
97 callback: A callable previously registered with this Channel from having
98 been passed to its "subscribe" method.
104 """Creates an insecure Channel to a remote host.
107 host: The name of the remote host to which to connect.
108 port: The port of the remote host to which to connect.
109 If None only the 'host' part will be used.
112 A Channel to the remote host through which RPCs may be conducted.
120 """Creates a secure Channel to a remote host.
123 host: The name of the remote host to which to connect.
124 port: The port of the remote host to which to connect.
125 If None only the 'host' part will be used.
126 channel_credentials: A ChannelCredentials.
129 A secure Channel to the remote host through which RPCs may be conducted.
132 host
if port
is None else '%s:%d' % (host, port), channel_credentials)
137 """A value encapsulating the various options for creation of a Stub.
139 This class and its instances have no supported interface - it exists to define
140 the type of its instances and its instances exist to be passed to other
144 def __init__(self, host, request_serializers, response_deserializers,
145 metadata_transformer, thread_pool, thread_pool_size):
154 _EMPTY_STUB_OPTIONS =
StubOptions(
None,
None,
None,
None,
None,
None)
158 request_serializers=None,
159 response_deserializers=None,
160 metadata_transformer=None,
162 thread_pool_size=None):
163 """Creates a StubOptions value to be passed at stub creation.
165 All parameters are optional and should always be passed by keyword.
168 host: A host string to set on RPC calls.
169 request_serializers: A dictionary from service name-method name pair to
170 request serialization behavior.
171 response_deserializers: A dictionary from service name-method name pair to
172 response deserialization behavior.
173 metadata_transformer: A callable that given a metadata object produces
174 another metadata object to be used in the underlying communication on the
176 thread_pool: A thread pool to use in stubs.
177 thread_pool_size: The size of thread pool to create for use in stubs;
178 ignored if thread_pool has been passed.
181 A StubOptions value created from the passed parameters.
183 return StubOptions(host, request_serializers, response_deserializers,
184 metadata_transformer, thread_pool, thread_pool_size)
188 """Creates a face.GenericStub on which RPCs can be made.
191 channel: A Channel for use by the created stub.
192 options: A StubOptions customizing the created stub.
195 A face.GenericStub on which RPCs can be made.
197 effective_options = _EMPTY_STUB_OPTIONS
if options
is None else options
198 return _client_adaptations.generic_stub(
200 effective_options.host,
201 effective_options.metadata_transformer,
202 effective_options.request_serializers,
203 effective_options.response_deserializers)
207 """Creates a face.DynamicStub with which RPCs can be invoked.
210 channel: A Channel for the returned face.DynamicStub to use.
211 service: The package-qualified full name of the service.
212 cardinalities: A dictionary from RPC method name to cardinality.Cardinality
213 value identifying the cardinality of the RPC method.
214 options: An optional StubOptions value further customizing the functionality
215 of the returned face.DynamicStub.
218 A face.DynamicStub with which RPCs can be invoked.
220 effective_options = _EMPTY_STUB_OPTIONS
if options
is None else options
221 return _client_adaptations.dynamic_stub(
225 effective_options.host,
226 effective_options.metadata_transformer,
227 effective_options.request_serializers,
228 effective_options.response_deserializers)
232 ssl_server_credentials = grpc.ssl_server_credentials
236 """A value encapsulating the various options for creation of a Server.
238 This class and its instances have no supported interface - it exists to define
239 the type of its instances and its instances exist to be passed to other
243 def __init__(self, multi_method_implementation, request_deserializers,
244 response_serializers, thread_pool, thread_pool_size,
245 default_timeout, maximum_timeout):
255 _EMPTY_SERVER_OPTIONS =
ServerOptions(
None,
None,
None,
None,
None,
None,
None)
259 request_deserializers=None,
260 response_serializers=None,
262 thread_pool_size=None,
263 default_timeout=None,
264 maximum_timeout=None):
265 """Creates a ServerOptions value to be passed at server creation.
267 All parameters are optional and should always be passed by keyword.
270 multi_method_implementation: A face.MultiMethodImplementation to be called
271 to service an RPC if the server has no specific method implementation for
272 the name of the RPC for which service was requested.
273 request_deserializers: A dictionary from service name-method name pair to
274 request deserialization behavior.
275 response_serializers: A dictionary from service name-method name pair to
276 response serialization behavior.
277 thread_pool: A thread pool to use in stubs.
278 thread_pool_size: The size of thread pool to create for use in stubs;
279 ignored if thread_pool has been passed.
280 default_timeout: A duration in seconds to allow for RPC service when
281 servicing RPCs that did not include a timeout value when invoked.
282 maximum_timeout: A duration in seconds to allow for RPC service when
283 servicing RPCs no matter what timeout value was passed when the RPC was
287 A StubOptions value created from the passed parameters.
289 return ServerOptions(multi_method_implementation, request_deserializers,
290 response_serializers, thread_pool, thread_pool_size,
291 default_timeout, maximum_timeout)
294 def server(service_implementations, options=None):
295 """Creates an interfaces.Server with which RPCs can be serviced.
298 service_implementations: A dictionary from service name-method name pair to
299 face.MethodImplementation.
300 options: An optional ServerOptions value further customizing the
301 functionality of the returned Server.
304 An interfaces.Server with which RPCs can be serviced.
306 effective_options = _EMPTY_SERVER_OPTIONS
if options
is None else options
307 return _server_adaptations.server(
308 service_implementations, effective_options.multi_method_implementation,
309 effective_options.request_deserializers,
310 effective_options.response_serializers, effective_options.thread_pool,
311 effective_options.thread_pool_size)