aiomas – A library for multi-agent systems and RPC based on asyncio

aiomas is an easy-to-use library for request-reply channels, remote
procedure calls (RPC) and multi-agent systems (MAS). It’s written in pure
Python on top of asyncio.

Here are three simple examples that show the different layers of aiomas and
what they add on top of each other:

The request-reply channel has the lowest level of abstraction (but already
offers more then vanilla asyncio):

>>>importaiomas>>>>>>>>>asyncdefhandle_client(channel):..."""Handle a client connection."""...req=awaitchannel.recv()...print(req.content)...awaitreq.reply('cya')...awaitchannel.close()>>>>>>>>>asyncdefclient():..."""Client coroutine: Send a greeting to the server and wait for a
... reply."""...channel=awaitaiomas.channel.open_connection(('localhost',5555))...rep=awaitchannel.send('ohai')...print(rep)...awaitchannel.close()>>>>>>>>>server=aiomas.run(aiomas.channel.start_server(('localhost',5555),handle_client))>>>aiomas.run(client())ohaicya>>>server.close()>>>aiomas.run(server.wait_closed())

Features

The top-layer provides a simple base class for your own agents. All agents
live in a container.

Containers take care of creating agent instances and performing the
communication between them.

The container provides a clock for the agents. This clock can either be
synchronized with the real (wall-clock) time or be set by an external process
(e.g., other simulators).

RPC:

The rpc layer implements remote procedure calls which let you call methods
on remote objects nearly as if they were normal objects:

Instead of ret = obj.meth(arg) you write ret = await obj.meth(arg).

Request-reply channel:

The channel layer is the basis for the rpc layer. It sends JSON or
MsgPack encoded byte strings over TCP or unix domain sockets. It also maps
replies (of success or failure) to their corresponding request.

Other features:

TLS support for authorization and encrypted communication.

Interchangeable and extensible codecs: JSON and MsgPack (the latter
optionally compressed with Blosc) are built-in. You can add custom codecs or
write (de)serializers for your own objects to extend a codec.

Deterministic, emulated sockets: A LocalQueue transport lets you send and
receive message in a deterministic and reproducible order within a single
process. This helps testing and debugging distributed algorithms.

Support

License

The project is licensed under the MIT license.

Changelog

1.0.3 – 2016-05-09

[FIX] The function asyncio.ensure_future() called in
aiomas.util.create_task() was introduced in Python 3.4.4 and is not
available in Python 3.4.0–3.4.3 (which is, e.g., used on Ubuntu 14.04).
There is now a fallback to asyncio.async() if asyncio.ensure_future()
is not available.

1.0.2 – 2016-05-04

[CHANGE] aiomas.util.create_task() replaces aiomas.util.async().
aiomas.util.async() is now deprecated and will be removed in aiomas 2 and
when a new Python release no longer allows to use async as name.

[NEW] Added developer documentation.

1.0.1 – 2016-04-22

[BREAKING CHANGE] Renamed the async argument for Container.create()
and Container.shutdown() to as_coro. Realized to late that it will
come to name clashes with the async keyword added to Python 3.5.
I assume that no one really uses this project yet, thus I mark it as bug-fix
relaese rather then bumping aiomas to v2.