https://github.com/yu-iskw/python-grpc-example
Example to use gRPC in python with docker
https://github.com/yu-iskw/python-grpc-example
docker grpc microservice python
Last synced: about 1 year ago
JSON representation
Example to use gRPC in python with docker
- Host: GitHub
- URL: https://github.com/yu-iskw/python-grpc-example
- Owner: yu-iskw
- Created: 2017-12-11T02:21:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-11T05:50:59.000Z (over 8 years ago)
- Last Synced: 2025-03-22T15:04:07.143Z (about 1 year ago)
- Topics: docker, grpc, microservice, python
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gRPC example in python
This is an example to run gRPC server on docker as well as access the server from a client on a local machine.
Those files in the repository derives from an official example.
- [grpc/examples/python/helloworld at master · grpc/grpc](https://github.com/grpc/grpc/tree/master/examples/python/helloworld)
## Requirements
- Docker
- Anaconda
- Make
## Implement the files
1. Define the protocol-buffer in `helloworld.proto`.
2. Implement a command to generate python files from `helloworld.proto` in `codegen.py`.
3. Implement `grpc_server.py`.
4. Implement `greeter_server.py`.
## How to set up an environment on our local machine
The command creates an anaconda environment.
We can activate the environment with `source activate grpc-example`, since the environment name is `grpc-example`.
```
make create-conda
# If you would like to remove the anaconda envronment,
make delete-conda
```
## How to run the server and the client on our local machine
```
python grpc_server.py
python greeter_client.py
Greeter client received: Hello, cool guy!
```
## How to build and run a docker image
The docker image is used for running `grpc_server.py`.
The host name depends on your environment.
If you use `docker-machine`, we can see the IP address with `docker-machine ip YOUR_DOCKER_MACHINE`.
```
make build-docker
make run-docker
```
And then, we check if the client can access the server on docker or not:
```
# Execute it on your local machine, not a docker container.
python greeter_cliept.py --host HOST_NAME --port 50051
```