Skip to content

PGSch/grpc-greeter

Repository files navigation

gRPC Greeter

License Python gRPC

🚀 Project Overview

gRPC Greeter is a Python-based gRPC service that demonstrates the core capabilities of Remote Procedure Calls (RPC) with secure communication. It features:

  • A Greeter service that responds to client requests with personalized greetings.
  • Secure communication using TLS/SSL.
  • Flexible logging for production-grade operations.

This project is a great starting point for developers looking to explore gRPC with Python.


📂 Directory Structure

grpc-greeter/
├── greeter.proto             # Protobuf definition file
├── grpc_greeter/
│   ├── __init__.py           # Package initialization
│   ├── server.py             # Server implementation
│   ├── client.py             # Client implementation
│   ├── generated/            # Generated Protobuf and gRPC code
│   │   ├── __init__.py
│   │   ├── greeter_pb2.py
│   │   └── greeter_pb2_grpc.py
├── pyproject.toml            # Poetry configuration
├── README.md                 # Project documentation
├── server.key                # Private key for SSL/TLS
├── server.crt                # Certificate for SSL/TLS
└── tests/                    # Unit tests
    └── test_server.py

🛠️ Installation

Prerequisites

  • Python 3.12+
  • Poetry for dependency management:
    pip install poetry

Install Dependencies

  1. Clone the repository:

    git clone https://github.com/yourusername/grpc-greeter.git
    cd grpc-greeter
  2. Install dependencies:

    poetry install

📡 Running the Project

Start the Server

To start the secure gRPC server:

poetry run python -m grpc_greeter.server

Expected Output:

2024-11-14 12:00:00 - INFO - Initializing gRPC server...
2024-11-14 12:00:00 - INFO - Secure gRPC server started on port 50051.

Run the Client

To send a request to the server:

poetry run python -m grpc_greeter.client

Expected Output:

Sending request: Alice
Received response: Hello, Alice!

🔒 Security: TLS/SSL

This project uses SSL/TLS to secure client-server communication.

  • server.key: Private key for the server.
  • server.crt: Self-signed certificate.

To generate new keys and certificates, use:

openssl req -x509 -newkey rsa:2048 -keyout server.key -out server.crt -days 365 -nodes   -subj "/C=US/ST=California/L=San Francisco/O=Your Company/OU=Your Unit/CN=localhost"

🧪 Testing

Run unit tests to validate the server:

poetry run pytest

🛡️ Features

  • gRPC API:

    • SayHello: Responds with a personalized greeting.
  • Production-Ready Enhancements:

    • Secure communication using SSL/TLS.
    • Detailed logging with Python’s logging module.
    • Unit tests for reliability.

🚀 Future Enhancements

  • Add support for more advanced gRPC features like streaming.
  • Deploy the service to cloud platforms like AWS or GCP.
  • Create a Dockerized version of the application for portability.

📜 License

This project is licensed under the MIT License.


❤️ Acknowledgments

  • gRPC for enabling efficient RPC communication.
  • Poetry for modern dependency management.
  • Community contributors for making tools like OpenSSL easily accessible.

About

A gRPC service for greeting users

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published