RPC Client¶
RPCClient
instances are high-level handlers for
making remote procedure calls to servers. Other than
RPCProxy
objects, they are what most user
applications interact with.
Clients needs to be instantiated with a protocol and a transport to function. Proxies are syntactic sugar for using clients.
-
class
tinyrpc.client.
RPCClient
(protocol: tinyrpc.protocols.RPCProtocol, transport: tinyrpc.transports.ClientTransport) Bases:
object
Client for making RPC calls to connected servers.
Parameters: - protocol (RPCProtocol) – An
RPCProtocol
instance. - transport (ClientTransport) – The data transport mechanism
-
batch_call
(calls: List[tinyrpc.client.RPCCallTo]) → tinyrpc.protocols.RPCBatchResponse Experimental, use at your own peril.
-
call
(method: str, args: List, kwargs: Dict, one_way: bool = False) → Any Calls the requested method and returns the result.
If an error occurred, an
RPCError
instance is raised.Parameters: Returns: The result of the call
Return type: any
-
call_all
(requests: List[tinyrpc.client.RPCCall]) → List[Any] Calls the methods in the request in parallel.
When the
gevent
module is already loaded it is assumed to be correctly initialized, including monkey patching if necessary. In that case the RPC calls defined byrequests
are performed in parallel otherwise the methods are called sequentially.Parameters: requests – A list of either RPCCall
orRPCCallTo
elements. When RPCCallTo is used each element defines a transport. Otherwise the default transport set when RPCClient is created is used.Returns: A list with replies matching the order of the requests.
-
get_proxy
(prefix: str = '', one_way: bool = False) → tinyrpc.client.RPCProxy Convenience method for creating a proxy.
Parameters: - prefix – Passed on to
RPCProxy
. - one_way – Passed on to
RPCProxy
.
Returns: RPCProxy
instance.- prefix – Passed on to
- protocol (RPCProtocol) – An
-
class
tinyrpc.client.
RPCProxy
(client: tinyrpc.client.RPCClient, prefix: str = '', one_way: bool = False) Bases:
object
Create a new remote proxy object.
Proxies allow calling of methods through a simpler interface. See the documentation for an example.
Parameters: - client – An
RPCClient
instance. - prefix – Prefix to prepend to every method name.
- one_way – Passed to every call of
call()
.
- client – An
-
class
tinyrpc.client.
RPCCall
(method, args, kwargs) Bases:
tuple
Defines the elements of an RPC call.
RPCCall is used with
call_all()
to provide the list of requests to be processed. Each request contains the elements defined in this tuple.-
args
Alias for field number 1
-
kwargs
Alias for field number 2
-
method
Alias for field number 0
-
-
class
tinyrpc.client.
RPCCallTo
(transport, method, args, kwargs) Bases:
tuple
Defines the elements of a RPC call directed to multiple transports.
RPCCallTo is used with
call_all()
to provide the list of requests to be processed.-
args
Alias for field number 2
-
kwargs
Alias for field number 3
-
method
Alias for field number 1
-
transport
Alias for field number 0
-