项目作者: codemation

项目描述 :
An easy to use rpc framework for enabling fast inter-process, inter-container, or inter-host communication
高级语言: Python
项目地址: git://github.com/codemation/easyrpc.git
创建时间: 2020-10-14T12:49:38Z
项目社区:https://github.com/codemation/easyrpc

开源协议:MIT License

下载


An easy to use rpc framework for enabling fast inter-process, inter-container, or inter-host communication

Easily share functions between hosts, processes, containers without the complexity of defining non-native python types or proxy modules.

Documentation Status PyPI version

Documentation

easyrpc.readthedocs.io

Key Features

  • No predefined proxy functions at the remote endpoints
  • Easily group and share functons among hosts / processes using Namespaces / Namespace Groups
  • Proxy functions parameters are validated as if defined locally.
  • Optional: pre-flight encyrption
  • No strict RPC message structure / size limit
  • Flexible parameter types within pickable constraint

Quick Start

  1. $ virtualenv -p python3.7 easy-rpc-env
  2. $ source easy-rpc-env/bin/activate
  3. (easy-rpc-env)$ pip install easyrpc

Basic Usage:

  1. # server.py
  2. from fastapi import FastAPI
  3. from easyrpc.server import EasyRpcServer
  4. server = FastAPI()
  5. ws_server_a = EasyRpcServer(server, '/ws/server_a', server_secret='abcd1234')
  6. @ws_server_a.origin(namespace='public')
  7. def good_func_a(a, b, c):
  8. print(f"good_func_a {a} {b} {c}")
  9. return {"good_func_a": [a, b, c]}
  1. # client.py
  2. import asyncio
  3. from easyrpc.proxy import EasyRpcProxy
  4. async def main():
  5. proxy = await EasyRpcProxy.create(
  6. '0.0.0.0',
  7. 8090,
  8. '/ws/server_a',
  9. server_secret='abcd1234',
  10. 'namespace='public'
  11. )
  12. good_func_a = proxy['good_func_a']
  13. result = await good_func_a(1, 5, 7)
  14. print(result)
  15. asyncio.run(main())

Recipes

See other usage examples in Recipes

Supported Functions Features

  • async def & def
  • async generators & generators
  • args, *kwargs
  • positional & default parmeters
  • TODO - type annotations

Common Use Cases

  • State sharing among forked workers
  • Shared Database connections / cache
  • Shared Queues
  • Worker Pooling - Easy centralization for workers and distribution of work.
  • Function Chaining