Skip to main content

README.md

Project description

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.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

simrpc-1.3.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file simrpc-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: simrpc-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for simrpc-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9886b880114c8484178d9544c64307a80dbe1fea3ca86e6ef38b8f0e24e11cb7
MD5 9dd6271e3763dd334b7507ee1a70f821
BLAKE2b-256 01b2f1340b72b595de94c1f5dc51a3a4249075495609e6b837cc455e3e2154f8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page