Skip to main content

SimRpc

Downloads

Why SimRpc

all of the popular rpc framework today, is fast and stable.

but it is kind of not good enough for you to easily start. you have to accept all the rpc's definition,learn their structure, and you have to adapt your code to them.

so if you dont like them,and you havn't have other alternatives. may be SimRpc is suit for you

Intruction

SimRpc is an rpc tools for you to easily transfer your code to rpc service(both client-side and server-side),built on top of zeromq and msgpack.

  • zeromq

    assures the message transfer extremely fast and stable

  • msgpack

    enables the message blazing small

Usage

Your Original Code

class a:
    def minus(self, x, y):
        print("x+y=", x - y)
        return x - y
def add(x, y):
    return x + y

Client Side

1) start an client instance

from simrpc.client import SimRpcClient
rpc_client = SimRpcClient()

or maybe you want to start a specific address

from simrpc.client import SimRpcClient
rpc_client = SimRpcClient(server_address="tcp://localhost:6666")

the server_address is a zeromq address.

for more information you can refer to zeromq.

2) add @rpc_client.task decorator to your code

# response_only=True means you only want the result

class a:

    @rpc_client.task(response_only=True)
    def minus(self, x, y):
        print("x+y=", x - y)
        return x - y

# func=True means this is a funcion,not a class service

@rpc_client.task(response_only=True,func=True)
def add(x, y):
    return x + y

3) Use these functions as usual

a().minus(4,5,rpc_client=True)

you must point it out this a rpc client(as use rpc_client=True prameter), otherwise will use local code

Server Side

1) start an server instance

from server import SimRpcServer
server = SimRpcServer()

like client,you can also give specific addresses to server.

parameter value instruction
device_front_address "tcp://127.0.0.1:5559" address that receive message. used for client to connect.
device_backend_address "tcp://127.0.0.1:5560" address that send message to service worker.
worker_address "tcp://127.0.0.1:5560" address that worker connect to. usually the same with device_backend_address.for advanced infomation,you can refer to zeromq

more ways of address(like ipc) are supported, you can refer to zeromq

2) register your service to server

  • initial your class service as usual
service = a()
server.register(service)
  • or you let server to initial your service(just pass your init arguments to server.)
settings = {
    "a": {
        "kwargs": {
            "name": "test"
        }
    }
}
service = a()
server.register(service)
# or you can have this class init with server
# server.register_with_init(cls_list=[a], settings=settings)

3) start your rpc server broker

server.start_broker()
# if you also want to start worker in process ,you could use server.run(),this will start a few workers.

# server.run()

with this broker,you can easily expand your service from both client-side and server-side

4) start more workers

# the same as above but without server.start_broker()
server.run()

For details,you can refer to examples

Dependence

Coding

  • like this project, star it
  • any suggestion is welcome
  • this project is under MIT lisense

more docs are writing.

Metadata

Release files for simrpc 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for simrpc 1.3.1
File Interpreter ABI Platform
simrpc-1.3.1-py3-none-any.whl Python 3 none any Details

Release files / simrpc-1.3.1-py3-none-any.whl

Download URL simrpc-1.3.1-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9886b880114c8484178d9544c64307a80dbe1fea3ca86e6ef38b8f0e24e11cb7
BLAKE2b-256 checksum
How to use checksums
01b2f1340b72b595de94c1f5dc51a3a4249075495609e6b837cc455e3e2154f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6

Release history Release notifications | RSS feed

This release

1.3.1 This release

1 release file

1.3.0

1 release file

1.2.7

1 release file

1.2.6

1 release file

1.2.5

1 release file

1.2.4

1 release file

1.2.3

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page