aiomas is an easy-to-use library for remote procedure calls (RPC) and multi-agent systems (MAS). It’s written in pure Python on top of asyncio.
Here is an example how you can write a simple multi-agent system:
>>> import asyncio >>> import aiomas >>> >>> class TestAgent(aiomas.Agent): ... def __init__(self, container, addr): ... super().__init__(container, addr) ... print('Ohai, I am %s' % self) ... ... @asyncio.coroutine ... def run(self, addr): ... remote_agent = yield from self.container.connect(addr) ... ret = yield from remote_agent.service(42) ... print('%s got %s from %s' % (self, ret, remote_agent)) ... ... @aiomas.expose ... def service(self, value): ... return value >>> >>> c = aiomas.Container(('localhost', 5555)) >>> agents = [c.spawn(TestAgent) for i in range(2)] Ohai, I am TestAgent('tcp://localhost:5555/0') Ohai, I am TestAgent('tcp://localhost:5555/1') >>> aiomas.run(until=agents.run(agents.addr)) TestAgent('tcp://localhost:5555/0') got 42 from TestAgentProxy('tcp://localhost:5555/1') >>> c.shutdown()
aiomas is released under the MIT license. It requires Python 3.4 and above and runs on Linux, OS X, and Windows.
aiomas requires Python >= 3.4. It uses the JSON codec by default and only has pure Python dependencies.
Install aiomas via pip by running:
$ pip install aiomas
$ pip install aiomas[mp] # Enables the MsgPack codec $ pip install aiomas[mpb] # Enables the MsgPack and MsgPackBlosc codecs
aiomas just puts three layers of abstraction around raw TCP / unix domain sockets provided by asyncio:
- Agents and agent containers:
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).
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 = yield from 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.
Although you usually want to use the agent layer, it is perfectly okay to only use the rpc or channel layer.
Some ideas for future releases:
- SSL/TLS support for TCP sockets
- Optional automatic re-connect after connection loss
- Helper for binding a socket to a random free port
- Issue Tracker: https://bitbucket.org/sscherfke/aiomas/issues?status=new&status=open
- Source Code: https://bitbucket.org/sscherfke/aiomas/src
Set-up a development environment with:
$ virtualenv -p `which python3` aiomas $ pip install -r requirements.txt
Run the tests with:
$ py.test $ # or $ tox
The project is licensed under the MIT license.
7 months ago passed
.. image:: https://readthedocs.org/projects/aiomas/badge/?version=latest :target: http://aiomas.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status
<a href='http://aiomas.readthedocs.io/en/latest/?badge=latest'> <img src='https://readthedocs.org/projects/aiomas/badge/?version=latest' alt='Documentation Status' /> </a>
Project has no tags.
Project Privacy Level