All Projects → abersheeran → Rpc.py

abersheeran / Rpc.py

Licence: apache-2.0
A fast and powerful RPC framework based on ASGI/WSGI.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Rpc.py

Spyne
A transport agnostic sync/async RPC library that focuses on exposing services with a well-defined API using popular protocols.
Stars: ✭ 992 (+912.24%)
Mutual labels:  rpc, rpc-framework, json, msgpack
Getty
a netty like asynchronous network I/O library based on tcp/udp/websocket; a bidirectional RPC framework based on JSON/Protobuf; a microservice framework based on zookeeper/etcd
Stars: ✭ 532 (+442.86%)
Mutual labels:  rpc, rpc-framework, json
Airframe
Essential Building Blocks for Scala
Stars: ✭ 442 (+351.02%)
Mutual labels:  rpc, json, msgpack
Yar
Light, concurrent RPC framework for PHP & C
Stars: ✭ 1,369 (+1296.94%)
Mutual labels:  rpc-framework, json, msgpack
Json
JSON for Modern C++
Stars: ✭ 27,824 (+28291.84%)
Mutual labels:  json, msgpack, cbor
Json
C++ header-only JSON library
Stars: ✭ 343 (+250%)
Mutual labels:  json, msgpack, cbor
Hprose Java
Hprose is a cross-language RPC. This project is Hprose 2.0 for Java
Stars: ✭ 542 (+453.06%)
Mutual labels:  rpc, rpc-framework
Grain
grain是一个极简的、组件式的RPC框架,灵活且适合渐进学习,可与任何框架整合。同时包含(系统通用多线程模型与消息通讯 || 多对多关系的分布式锁 || 基于Servlet的HTTP框架 || 基于系统通用多线程模型的Websocket框架 || 支持行级锁的多线程锁 )等组件,按需选择组件,不绑架开发者。
Stars: ✭ 577 (+488.78%)
Mutual labels:  rpc, rpc-framework
Phpboot
☕️ 🚀 tiny & fast PHP framework for building Microservices/RESTful APIs, with useful features: IOC, Hook, ORM, RPC, Swagger, Annotation, Parameters binding, Validation, etc.
Stars: ✭ 638 (+551.02%)
Mutual labels:  rpc, annotation
Libjson Rpc Cpp
C++ framework for json-rpc (json remote procedure call)
Stars: ✭ 653 (+566.33%)
Mutual labels:  rpc, json
Go Zero
go-zero is a web and rpc framework written in Go. It's born to ensure the stability of the busy sites with resilient design. Builtin goctl greatly improves the development productivity.
Stars: ✭ 13,156 (+13324.49%)
Mutual labels:  rpc, rpc-framework
Treefrog Framework
TreeFrog Framework : High-speed C++ MVC Framework for Web Application
Stars: ✭ 885 (+803.06%)
Mutual labels:  json, cbor
Sofa Rpc Node
SOFARPC Node is a high-performance, high-extensibility, production-level Nodejs RPC framework.
Stars: ✭ 520 (+430.61%)
Mutual labels:  rpc, rpc-framework
Simple Go Rpc
RPC explained by writing simple RPC framework in 300 lines of pure Golang.
Stars: ✭ 510 (+420.41%)
Mutual labels:  rpc, rpc-framework
Hprose Golang
Hprose is a cross-language RPC. This project is Hprose for Golang.
Stars: ✭ 1,143 (+1066.33%)
Mutual labels:  rpc, rpc-framework
Wheel
关于net nio os cache db rpc json web http udp tcp mq 等多个小工具的自定义实现
Stars: ✭ 45 (-54.08%)
Mutual labels:  rpc, json
Rpcx Java
rpcx implementation in Java for server side and client side
Stars: ✭ 71 (-27.55%)
Mutual labels:  rpc, rpc-framework
Easyrpc
EasyRpc is a simple, high-performance, easy-to-use RPC framework based on Netty, ZooKeeper and ProtoStuff.
Stars: ✭ 79 (-19.39%)
Mutual labels:  rpc, rpc-framework
Jsoncons
A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
Stars: ✭ 400 (+308.16%)
Mutual labels:  json, cbor
Remarshal
Convert between CBOR, JSON, MessagePack, TOML, and YAML
Stars: ✭ 421 (+329.59%)
Mutual labels:  json, msgpack

rpc.py

Codecov

An fast and powerful RPC framework based on ASGI/WSGI. Based on WSGI/ASGI, you can deploy the rpc.py server to any server and use http2 to get better performance. And based on httpx's support for multiple http protocols, the client can also use http/1.0, http/1.1 or http2.

You can freely use ordinary functions and asynchronous functions for one-time response. You can also use generator functions or asynchronous generator functions to stream responses.

Install

Install from PyPi:

pip install rpc.py

# need use client
pip install rpc.py[client]

# need use pydantic type hint or OpenAPI docs
pip install rpc.py[type]

# need use msgpack to serializer
pip install rpc.py[msgpack]

# need use CBOR to serializer
pip install rpc.py[cbor]

# or install all dependencies
pip install rpc.py[full]

Install from github:

pip install git+https://github.com/abersheeran/[email protected]

Usage

Server side:

Use ASGI mode to register async def...
from typing import AsyncGenerator

import uvicorn
from rpcpy import RPC
from rpcpy.typing import TypedDict

app = RPC(mode="ASGI")


@app.register
async def none() -> None:
    return


@app.register
async def sayhi(name: str) -> str:
    return f"hi {name}"


@app.register
async def yield_data(max_num: int) -> AsyncGenerator[int, None]:
    for i in range(max_num):
        yield i


D = TypedDict("D", {"key": str, "other-key": str})


@app.register
async def query_dict(value: str) -> D:
    return {"key": value, "other-key": value}


if __name__ == "__main__":
    uvicorn.run(app, interface="asgi3", port=65432)

OR

Use WSGI mode to register def...
from typing import Generator

import uvicorn
from rpcpy import RPC
from rpcpy.typing import TypedDict

app = RPC()


@app.register
def none() -> None:
    return


@app.register
def sayhi(name: str) -> str:
    return f"hi {name}"


@app.register
def yield_data(max_num: int) -> Generator[int, None, None]:
    for i in range(max_num):
        yield i


D = TypedDict("D", {"key": str, "other-key": str})


@app.register
def query_dict(value: str) -> D:
    return {"key": value, "other-key": value}


if __name__ == "__main__":
    uvicorn.run(app, interface="wsgi", port=65432)

Client side:

Notice: Regardless of whether the server uses the WSGI mode or the ASGI mode, the client can freely use the asynchronous or synchronous mode.

Use httpx.Client() mode to register def...
from typing import Generator

import httpx
from rpcpy.client import Client
from rpcpy.typing import TypedDict

app = Client(httpx.Client(), base_url="http://127.0.0.1:65432/")


@app.remote_call
def none() -> None:
    ...


@app.remote_call
def sayhi(name: str) -> str:
    ...


@app.remote_call
def yield_data(max_num: int) -> Generator[int, None, None]:
    yield


D = TypedDict("D", {"key": str, "other-key": str})


@app.remote_call
def query_dict(value: str) -> D:
    ...

OR

Use httpx.AsyncClient() mode to register async def...
from typing import AsyncGenerator

import httpx
from rpcpy.client import Client
from rpcpy.typing import TypedDict

app = Client(httpx.AsyncClient(), base_url="http://127.0.0.1:65432/")


@app.remote_call
async def none() -> None:
    ...


@app.remote_call
async def sayhi(name: str) -> str:
    ...


@app.remote_call
async def yield_data(max_num: int) -> AsyncGenerator[int, None]:
    yield


D = TypedDict("D", {"key": str, "other-key": str})


@app.remote_call
async def query_dict(value: str) -> D:
    ...

Sub-route

If you need to deploy the rpc.py server under example.com/sub-route/*, you need to set RPC(prefix="/sub-route/") and modify the Client(base_path=https://example.com/sub-route/).

Serialization

Currently supports three serializers, JSON, Pickle, Msgpack and CBOR. JSON is used by default. You can override the default JSONSerializer with parameters.

from rpcpy.serializers import PickleSerializer, MsgpackSerializer, CBORSerializer

RPC(
    ...,
    response_serializer=MsgpackSerializer(),
)
# Or
Client(
    ...,
    request_serializer=PickleSerializer(),
)

Type hint and OpenAPI Doc

Thanks to the great work of pydantic, which makes rpc.py allow you to use type annotation to annotate the types of function parameters and response values, and perform type verification and JSON serialization . At the same time, it is allowed to generate openapi documents for human reading.

OpenAPI Documents

If you want to open the OpenAPI document, you need to initialize RPC like this RPC(openapi={"title": "TITLE", "description": "DESCRIPTION", "version": "v1"}).

Then, visit the "{prefix}openapi-docs" of RPC and you will be able to see the automatically generated OpenAPI documentation. (If you do not set the prefix, the prefix is "/")

Limitations

Currently, file upload is not supported, but you can do this by passing a bytes object.

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].