exception aiorpcx.ConnectionError

When a connection is lost that has pending requests, this exception is set on those requests.


A simple wrapper around an asyncio.Server object (see asyncio.Server).

class aiorpcx.Server(protocol_factory, host=None, port=None, *, loop=None, **kwargs)

Creates a server that listens for connections on host and port. The server does not actually start listening until listen() is await-ed.

protocol_factory is any callable returning an asyncio.Protocol instance. You might find returning an instance of ServerSession, or a class derived from it, more useful.

loop is the event loop to use, or asyncio.get_event_loop() if None.

kwargs are passed through to loop.create_server().

A server instance has the following attributes:


The event loop being used.


The host passed to the constructor


The port passed to the constructor


The underlying asyncio.Server object when the server is listening, otherwise None.


Start listening for incoming connections. Return an asyncio.Server instance, which can also be accessed via server.

This method is a coroutine.


Close the listening socket if the server is listening, and wait for it to close. Return immediately if the server is not listening.

This does nothing to protocols and transports handling existing connections. On return server is None.


Returns when the server has closed.

This method is a coroutine.


Convenience classes are provided for client and server sessions.

class aiorpcx.ClientSession(host, port, *, rpc_protocol=None, framer=None, scheduler=None, loop=None, proxy=None, **kwargs)

An instance of an asyncio.Protocol class that represents an RPC session with a remote server at host and port, as documented in loop.create_connection().`

If proxy is not given, create_connection() uses loop.create_connection() to attempt a connection, otherwise SOCKSProxy.create_connection(). You can pass additional arguments to those functions with kwargs (host and port and loop are used as given).

rpc_protocol specifies the RPC protocol the server speaks. If None the protocol returned by default_rpc_protocol() is used.

framer handles RPC message framing, and if None then the framer returned by default_framer() is used.

scheduler should be left as None.

Logging will be sent to logger, None will use a logger specific to the ClientSession object’s class.


Make a connection attempt to the remote server. If successful this return a (transport, protocol) pair.

This method is a coroutine.


You can override this method to provide a default RPC protocol. JSONRPCv2 is returned by the default implementation.


You can override this method to provide a default message frmaer. A new NewlineFramer instance is returned by the default implementation.

The ClientSession and ServerSession classes share a base class that has the following attributes and methods: