Skip to content
μRPC - oversimplistic RPC/message bus implementation on top of Redis
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples move back to processexecpool because some customers said they are usi… Jul 21, 2018
scripts Fix noargs and add moronic documentation Feb 3, 2017
.gitignore [from now] 2018/04/24 22:04:36 Apr 24, 2018
Dockerfile OMG. What a typo I found :( Mar 15, 2017
LICENSE Initial commit Nov 29, 2016 docs and version up Jul 19, 2018
requirements.txt setuptools Nov 29, 2016
setup.cfg setuptools Nov 29, 2016 add nonwaitable calls (just because theres no reason to add new queue… Jul 22, 2018 add nonwaitable calls (just because theres no reason to add new queue… Jul 22, 2018

μRPC - simple rpc over Redis in less that 100 lines of code

It's all about hidden magic and syntax corn syrup. For more documentation please read through code.


For your RPC server:

from urpc import uRPC

class AddServer(uRPC):
	def worker(self, params):
		if 'a' not in params or 'b' not in params:
			return {'error': 'you need to provide params "a" and "b"!'}
		return {'summ': params['a'] + params['b']}

server = AddServer()

Please note that with no arguments AddServer will provide function "add" (lowercase "addserver" without "server"). Also by default it's connected to Redis at localhost and database 1. All defaults can be overridden by environment variable URPC or with .env file. URPC variable must contain string with host and database number, which must be used for rpc. For example, URPC="localhost:9". It works for both, server and client.

Since version 0.3 it's possible to do server.main_loop_many(N) where N is number of workers which run in parallel.


On the client side you can use it like this:

from urpc import uRPC

add = uRPC('add')
print(add(a=10, b=20))

By default call timeout is 10 seconds. If you need more (or less) call it like

add = uRPC('add').timeout(5)
print(add(a="test", b=" or not"))

Methods fabric

If you have more than 1 rpc method, you can use uRPCClientFabric class to generate it

from urpc import uRPCClientFabric
rpc = uRPCClientFabric({'host': 'localhost', 'db': 3, 'socket_timeout': 10})

Async client

If you don't want to wait until rpc request will be processed, you can use asynchronous version of this call

fetch = uRPC('urlfetch')
goo = fetch.wait('')
while not goo.ready():

wait and result also compatible with uRPCClientFabric variants.

There's also asyncio-compatible version of uRPC, you can use it by import aiourpc:

from aiourpc import aiouRPCClientFabric

async with aiouRPCClientFabric() as rpc:
    pprint(await rpc.fetch(''))

Command Line tool

For convenience urpc also installs urpc-cli script for commandline invocation of calls.

$ urpc-cli add a=10 b=20
{'result': 30}
$ urpc-cli echo say="blahblahblah"
{"echo": "blahblahblah"}
You can’t perform that action at this time.