Skip to content

Latest commit

 

History

History
86 lines (70 loc) · 1.39 KB

README.md

File metadata and controls

86 lines (70 loc) · 1.39 KB

learn-grpc-protobuf

Learning gRPC and protocol buffers based on this tutorial blog.

Requirements

  • python3
  • virtualenv

Usage

Virtualenv

create virtual environment directory for python

virtualenv venv

Spin-up Python gRPC Server

start virtualenv

source venv/bin/activate

change to app directory

cd app/

install python packages

pip install -r requirements.txt

generate gRPC class files from .proto files

python \
-m grpc_tools.protoc \
--proto_path=autogenerated=proto \
--python_out=. \
--grpc_python_out=. \
proto/*.proto

spin-up gRPC server

python server.py

OR.. Spin-up Python gRPC Server Container via Docker

docker build -t=learn-grpc-protobuf .
docker run -p 50051:50051 learn-grpc-protobuf

Run Client Script

in another terminal, start virtualenv

source venv/bin/activate

change to app directory

cd app/

make a request to the gRPC server via the client script

python client.py

you should see this output:

result of square_root(16):  4.0
result of add(4,5):  9.0
result of say_hello(My name is Harry): Hello, your request message was: My name is Harry

Cleanup

spin-down python gRPC server in 1st terminal

ctrl+c

deactivate virtualenv in both terminals

deactivate