ModPy - modrpc/info GitHub Wiki
ModPy is a Python library, based on asyncio, which facilitates programming of autonomous nodes in distributed environments. A service function is one which can be called either locally or remotely. Creating a service function in a node is as simple as adding a Python decorator @modpy.func
. As an example,
@modpy.func
def sayhello(name):
return "hello, " + name
Also, calling a remote function is simple. Given that a ModPy node, named "gauss", contains the sayhello
function, another node can access it as shown below:
result = await modpy.call("gauss/sayhello", "world")
# result will be "hello, world"
Use pip to install the ModPy library.
$ pip3 install modpy
ModPy depends on the asyncio library, which was introduced in Python 3.4. Use Python 3.5 or later to use ModPy.
To test if the library is installed properly, create a node program which serves a ModPy function, add.
import modpy
@modpy.func
def add(a, b):
return a + b
modpy.init_node().start()
Use the following command to run the node.
$ python3 test.py --name gauss --rpcport 12346
Next, run the ModPy shell and call the add
function.
$ python3 -m modpy.shell.main
MODPY> call gauss/add 3 4
RESULT: 7
ModPy is a library which implements the ModRPC protocol which is a simple protocol for remote resource access. ModPy is a binding of ModRPC to the Python language. Another project for Golang binding is in progress and I have a future plan to develop C or C++ bindings (haven't decided between the two yet).