Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Rapid RPC Framework for your Python services using Asyncio + MsgPack

Project description


Rapid RPC Framework for building Python 3.7+ services using Asyncio + MsgPack


$ pip install electron-rpc

How does it work?

Create a server instance with a single endpoint sum() which outputs the sum of two values:

from electron import Server

app = Server()

async def sum(a, b, **kwargs):
    return f"Result: {a + b}"
        __          __                      
  ___  / /__  _____/ /__________  ____      
 / _ \/ / _ \/ ___/ __/ ___/ __ \/ __ \     
/  __/ /  __/ /__/ /_/ /  / /_/ / / / /     
\___/_/\___/\___/\__/_/   \____/_/ /_/      

⚡ electron build v0.0.4                              

Listening on

Registered Endpoints:
- sum

Calling the endpoint from a client

electron uses MsgPack-RPC, so craft a payload and send it over TCP:

import socket

from electron.messages import RemoteProcedureCall

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

sock.connect(("", 9999))
sock.send(RemoteProcedureCall(endpoint="sum", args=[1, 2]).encode())

data = sock.recv(1024)
print(f"Received: \n{data.decode()}")
Result: 3

Background Tasks

To create a background task, decorate it with @app.background(time_in_seconds):

async def some_background_task():
    print("Running background task every 3 seconds")

Now the task will execute every 3 seconds.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
electron_rpc-0.0.4-py3-none-any.whl (8.0 kB) Copy SHA256 hash SHA256 Wheel py3
electron-rpc-0.0.4.tar.gz (4.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page