All Projects → Ananto30 → zero

Ananto30 / zero

Licence: MIT License
Zero: A simple, fast, high performance and low latency Python framework (RPC + PubSub) for building microservices or distributed servers

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to zero

Purerpc
Asynchronous pure Python gRPC client and server implementation supporting asyncio, uvloop, curio and trio
Stars: ✭ 125 (-57.77%)
Mutual labels:  rpc, asyncio, rpc-framework
callosum
An RPC Transport Library for asyncio
Stars: ✭ 17 (-94.26%)
Mutual labels:  zeromq, rpc, asyncio
jigsaw-rpc
jigsaw-rpc is an RPC framework written in TypeScript under Node.js
Stars: ✭ 14 (-95.27%)
Mutual labels:  rpc, rpc-framework
trellio
Python3 asyncio based microframework for microservice architecture
Stars: ✭ 19 (-93.58%)
Mutual labels:  rpc, asyncio
libcorpc
Libcorpc is a high performance coroutine base RPC framework
Stars: ✭ 20 (-93.24%)
Mutual labels:  rpc, rpc-framework
Aiozmq
Asyncio (pep 3156) integration with ZeroMQ
Stars: ✭ 358 (+20.95%)
Mutual labels:  zeromq, asyncio
Notes
let me know if my notes help you :D (it's a mess, I know)
Stars: ✭ 119 (-59.8%)
Mutual labels:  zeromq, asyncio
nodejs grpc
GRPC based API CRUD using Nodejs at both server and client side
Stars: ✭ 17 (-94.26%)
Mutual labels:  rpc, rpc-framework
Hprose Php
Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP
Stars: ✭ 1,952 (+559.46%)
Mutual labels:  rpc, rpc-framework
zerorpc-dotnet
A .NET implementation of ZeroRPC
Stars: ✭ 21 (-92.91%)
Mutual labels:  zeromq, rpc
hprose-as3
Hprose for ActionScript 3.0
Stars: ✭ 18 (-93.92%)
Mutual labels:  rpc, rpc-framework
simpleRPC
Simple RPC implementation for Arduino.
Stars: ✭ 28 (-90.54%)
Mutual labels:  rpc, rpc-framework
Sleuth
A Go library for master-less peer-to-peer autodiscovery and RPC between HTTP services
Stars: ✭ 331 (+11.82%)
Mutual labels:  zeromq, rpc
Fpnn
Fast Programmable Nexus Network
Stars: ✭ 220 (-25.68%)
Mutual labels:  rpc, rpc-framework
hrpc
Common interface definition based rpc implementation
Stars: ✭ 21 (-92.91%)
Mutual labels:  rpc, rpc-framework
Rpc
Simple RPC style APIs with generated clients & servers.
Stars: ✭ 192 (-35.14%)
Mutual labels:  rpc, rpc-framework
Pudding
Pudding 是一款迷你级分布式服务框架
Stars: ✭ 24 (-91.89%)
Mutual labels:  rpc, rpc-framework
Doge
Doge is a high-performance, Python based, open source RPC framework
Stars: ✭ 144 (-51.35%)
Mutual labels:  rpc, rpc-framework
Pulsar
Event driven concurrent framework for Python
Stars: ✭ 1,867 (+530.74%)
Mutual labels:  rpc, asyncio
http
Extension module of golang http service
Stars: ✭ 57 (-80.74%)
Mutual labels:  rpc, rpc-framework

Zero is a simple RPC like framework to build fast and high performance Python microservices or distributed servers


Features:

  • Zero provides faster communication (see benchmarks) between the microservices using zeromq under the hood.
  • Zero uses messages for communication and traditional client-server or request-reply pattern is supported.
  • Support for both Async and sync.
  • The base server (ZeroServer) utilizes all cpu cores.
  • Code generation! See example 👇

Philosophy behind Zero:

  • Zero learning curve: The learning curve is tends to zero. You just add your functions and spin up a server, literally that's it! The framework hides the complexity of messaging pattern that enables faster communication.
  • ZeroMQ: An awesome messaging library enables the power of Zero.

Let's get started!

Getting started 🚀

Ensure Python 3.8+

pip install zeroapi
  • Create a server.py
from zero import ZeroServer

def echo(msg: str) -> str:
    return msg

async def hello_world() -> str:
    return "hello world"


if __name__ == "__main__":
    app = ZeroServer(port=5559)
    app.register_rpc(echo)
    app.register_rpc(hello_world)
    app.run()

Please note that server RPC methods are type hinted. Type hint is must in Zero server.

See the method type async or sync, doesn't matter. 😃

  • Run it
python -m server
  • Call the rpc methods
from zero import ZeroClient

zero_client = ZeroClient("localhost", 5559)

def echo():
    resp = zero_client.call("echo", "Hi there!")
    print(resp)

def hello():
    resp = zero_client.call("hello_world", None)
    print(resp)


if __name__ == "__main__":
    echo()
    hello()

Or using async client -

import asyncio

from zero import AsyncZeroClient

zero_client = AsyncZeroClient("localhost", 5559)

async def echo():
    resp = await zero_client.call("echo", "Hi there!")
    print(resp)

async def hello():
    resp = await zero_client.call("hello_world", None)
    print(resp)


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(echo())
    loop.run_until_complete(hello())

Code Generation! 🙌

You can also use our code generation tool to generate Python client code!

After running the server, like above, you can call the server to get the client code.

python -m zero.generate_client --host localhost --port 5559 --overwrite-dir ./my_client

It will generate client like this -

import typing  # remove this if not needed
from typing import List, Dict, Union, Optional, Tuple  # remove this if not needed
from zero import ZeroClient


zero_client = ZeroClient("localhost", 5559)


class RpcClient:
    def __init__(self, zero_client: ZeroClient):
        self._zero_client = zero_client

    def echo(self, msg: str) -> str:
        return self._zero_client.call("echo", msg)

    def hello_world(self, msg: str) -> str:
        return self._zero_client.call("hello_world", msg)

You can just use this -

from my_client import RpcClient, zero_client

client = RpcClient(zero_client)

if __name__ == "__main__":
    client.echo("Hi there!")
    client.hello_world(None)

Using zero.generate_client you can generate client code for even remote servers using the --host and --port options. You don't need access to the code 😃

Important notes 📝

  • ZeroServer should always be run under if __name__ == "__main__":, as it uses multiprocessing.
  • The methods which are under register_rpc() in ZeroServer should have type hinting, like def echo(msg: str):

Let's do some benchmarking 🤘

Zero is talking about inter service communication. In most real life scenarios, we need to call another microservice.

So we will be testing a gateway calling another server for some data. Check the benchmark/dockerize folder for details.

There are two endpoints in every tests,

  • /hello: Just call for a hello world response 😅
  • /order: Save a Order object in redis

Compare the results! 👇

Benchmarks 🏆

11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz, 4 cores, 8 threads, 12GB RAM

(Sorted alphabetically)

Framework "hello world" (req/s) 99% latency (ms) redis save (req/s) 99% latency (ms)
aiohttp 9553.16 25.48 5497.03 27.90
aiozmq 13241.74 12.12 5087.68 21.59
fastApi 6036.61 31.28 3648.11 50.76
sanic 13195.99 20.04 7226.72 25.24
zero 18867.00 11.48 12293.81 11.68

Todo list 📃

  • Add pydantic support
  • Code generation for pydantic models
  • Improve error handling
  • Fault tolerance

Contribution

Contributors are welcomed 🙏

Please leave a star if you like Zero!

"Buy Me A Coffee"

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].