/grpc-example-python

A Docker-based grpc python example.

Primary LanguagePythonMIT LicenseMIT

grpc-example-python

Run in Insomnia}

A Docker-based grpc python example.

This is an experimental repo, it was heavily adapted from https://grpc.io/docs/languages/python/quickstart/ - the equivalent proto files have already been compiled and were placed here "as is"

How to run

helloworld example

To run the helloworld example (which only has simple Unary request):

  1. Clone the repo.
  2. Install Docker
  3. (Optional) Run make build or docker build --tag filfreire/grpc-example-helloworld:latest ..
  4. Run make run or docker run -it --rm -p 50051:50051 --name helloworld filfreire/grpc-example-helloworld:latest.

If all goes well you should see:

Server listening at '0.0.0.0:50051'

route_guide example

In this repo you can also find of the original gRPC Route guide example from the gRPC Basics python tutorial.

To run the route_guide example (which has Unary, client server and bidirectional streams examples):

  1. Clone the repo.
  2. Install Docker
  3. Change to route_guide/ folder (e.g. cd route_guide)
  4. (Optional) Run make build
  5. Run make run or docker run -it --rm -p 50051:50051 --name routeguide filfreire/grpc-example-routeguide:latest.

How to test

Import the Insomnia collection on this repo, https://raw.githubusercontent.com/filfreire/grpc-example-python/main/grpc_insomnia.json

Other notes

Rebuild protobuf definitions

In case you edited any of the .proto files in this repo, you can run make build-proto to build the protobuf definitions. You'll need to install some dependencies beforehand:

  1. Install protobuf compiler
  2. Install grpcio, grpcio-tools using pip. (e.g. sudo pip3 install grpcio grpcio-tools

Compile original protobuf definitions

To compile the proto files from the original repo:

  1. Clone the original repo: git clone -b v1.41.0 https://github.com/grpc/grpc
  2. Run python protobuf compiler:
python -m grpc_tools.protoc -I../../protos --python_out=. --grpc_python_out=. ../../protos/helloworld.proto