Skip to content

Instantly share code, notes, and snippets.

View koradon's full-sized avatar

Michał Sipa koradon

View GitHub Profile
syntax = "proto3
service UserStore {
rpc GetUserDataByEmail(UserEmailRequest) returns (UserResponse);
}
message User {
string email = 1;
string firstname = 2;
string lastname = 3;
import grpc
from protos.user_store_pb2 import User, UserResponse, UserEmailRequest,
from protos.user_store_pb2_grpc import UserStoreStub
def run():
with grpc.insecure_channel('localhost:50051') as channel:
stub = _pb2_grpc.UserStoreStub(channel)
response = stub.GetUserDataByEmail(
UserEmailRequest(email="[email protected]")
import grpc
from protos.user_store_pb2 import User, UserResponse, UserEmailRequest,
from protos.user_store_pb2_grpc import UserStoreServicer
class UserStoreServicer(UserStoreServicer):
def GetUserDataByEmail(self, request: UserEmailRequest, context):
user = … # your code for fetching the user data
return UserResponse(
JSON {'id':42} 9 bytes
XML <id>42</id> 11 bytes
protobuf 0x08 0x2a 2 bytes