Skip to content

hsadler/learn-grpc-protobuf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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