This project is a simple demonstration of using gRPC with Python. We'll implement a time service where the client can request the current server time.
The project contains two main Python scripts: a server and a client. The server creates a gRPC service that provides the current server time. The client connects to this service and prints out the server time.
- Python 3.11.3 installed. You can download it from Python's official website.
- Clone the repository.
git clone https://github.com/chuxorg/chux-py-grpc.git
cd chux-py-grpc
- Install the required packages.
Create a virtual environment (optional but recommended):
python3 -m venv env
source env/bin/activate # On Windows, use `env\Scripts\activate`
Install the required packages:
pip install -r requirements.txt
- Run the server.
python server.py
The server will start and listen on port 50051.
- In another terminal window, run the client.
python client.py
The client will connect to the server and print out the current server time.
server.py
: Contains the Python gRPC server. The server implements a simple service that provides the current server time.client.py
: Contains the Python gRPC client. The client connects to the server and prints out the server time.time_service.proto
: The Protocol Buffers file that defines theTimeService
service and theTimeRequest
andTimeResponse
message types.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.