Skip to content

SocialFinanceDigitalLabs/prpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prpc - pyodide remote procedure calls

A very simple RPC-like library to make writing Pyodide applications easier.

At the core of the library is a simple App + Decorator based approach inspired by Flask. In fact, Flask is one of the possible ways of interacting with your application.

The principle here is that when writing a javascript-based front-end talking to a "server" running in Pyodide, you do not need to change your code at all to switch between a local pyodide and a web-based development mode.

In javascript, it is as simple as:

const response = await api.callAPI({method: 'sum', value: {a: 1, b: 2}});

And you do not need to know anything about the underlying implementation.

On the Python side it is the same:

from prpc_python import RpcApp

app = RpcApp("Sample App")

@app.call(name='sum')
def sum_two(a: int, b: int) -> int:
    return a + b

Launching a Python application

To launch a python application, you need to install the prpc-python package:

pip install "prpc-python[simple]"

Then you can launch the sample application with:

prpc run -s sum '{"a": 1, "b": 2}' 

In this example -s means that we launch the sample app, sum is the command we're going to launch, then follows the json encoded input.

You can also get a list of all commands your application exposes with:

prpc commands -s

You can launch the Flask server with:

prpc flask -s

and test it using curl:

curl -X POST http://localhost:8000 -d 'method=sum&value={"a": 1, "b": 2}'   

or use the built-in test page which can be launched by clicking the URL printed by the prpc flask command, e.g. http://127.0.0.1:8000

Want to know more?

Check out the javascript or python for more information.