Skip to content

NF-coder/SimpleRPC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleRPC

Simple framework to create your own gRPC server with grpcio.

Installation

pip install git+https://github.com/NF-coder/SimpleRPC.git

Todo

  • Exceptions handling
  • Secure channels support
  • Autoconfigure from pydantic model
  • Source-of-truth for protos
  • Tests and docs

Quick Start

server.py

from simple_rpc import GrpcServer
from pydantic import BaseModel

class RequestModel(BaseModel):
    pass

class ResponceModel(BaseModel):
    num2: int
    num4: int

app = GrpcServer()

class Server:
    @app.grpc_method()
    async def example_method(self, request: RequestModel) -> ResponceModel:
        return ResponceModel(
            num2 = 3,
            num4 = 1
        )
    
app.configure_service(
    cls=Server(),
    port=50051
)
app.run()

client.py

from pydantic import BaseModel
from simple_rpc import GrpcClient
import asyncio

client = GrpcClient(
    proto_file_relpath="simplerpc_tmp/Server.proto", # Generates automatically on server startup
    port=50051
)
command = client.configure_command(
    functionName="example_method",
    className="Server"
)

async def run():
    print(
        await command()
    )

if __name__ == "__main__":
    asyncio.run(
        run()
    )

About

Simple framework to create your own gRPC server with grpcio

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages