You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Star0 (0)You must be signed in to star a repository
About
A single Python project that demonstrates every major gRPC communication pattern, cross-cutting concern, and operational feature. Works as a learning reference and as a template for production services.
A single Python project that demonstrates every major gRPC communication
pattern, cross-cutting concern, and operational feature. Works as a learning
reference and as a template for production services.
Stack: Python 3.12+, grpcio (async grpc.aio server, both sync and async
clients), proto3, uv, pytest.
flowchart TB
subgraph Host Machine
CLIENT[Client App\nclient/main.py]
end
CLIENT -->|Port 50051\nHTTP/2| SERVER
subgraph gRPC Server
subgraph Interceptors
LOGGING[Request Logging]
AUTH[Auth Interceptor]
METRICS[Metrics Interceptor]
LOGGING --> AUTH --> METRICS
end
SERVER[grpc.aio Server\nserver/main.py]
SERVER --> LOGGING
subgraph Services
INV[InventoryService\nUnary + Streaming RPCs]
STR[StreamingService\nBidi + Server/Client Streaming]
end
METRICS --> INV
METRICS --> STR
subgraph Operational
HEALTH[Health Check]
REFLECT[Server Reflection]
CHANNELZ[Channelz]
end
end
subgraph Proto Definitions
PROTO[proto/*.proto] -->|generate_protos.sh| STUBS[generated/*_pb2.py]
end
STUBS -.->|used by| CLIENT
STUBS -.->|used by| SERVER
Loading
Setup
uv venv --python 3.13 # create virtual environment for python 3.13source .venv/bin/activate # activate the virtual environment
uv sync # install everything (incl. dev deps)
./scripts/generate_protos.sh # regenerate generated/ from proto/ (checked in)
./scripts/gen_certs.sh # local CA + server/client certs (for TLS demos)
Quick start
uv run python -m server.main # terminal 1
uv run python -m client.main # terminal 2: runs most demos in order
uv run pytest # 36 tests, in-process server, ~2s
Every demo is also runnable standalone: uv run python -m client.demos.<name>.
Server Reflection
The server enables gRPC Server Reflection out of the box, so tools like
Postman, grpcurl, and Evans can discover every service and method without
importing .proto files.
Note the grpc.aio gotcha documented in client/interceptors/auth.py: the
channel sorts each interceptor instance into exactly one category, so an
interceptor class must not implement more than one RPC kind.
Security
Feature
Where
Demo command (server flags first)
Server TLS
scripts/gen_certs.sh, server/main.py
--tls / uv run python -m client.demos.tls
Mutual TLS
_server_credentials(mtls=True)
--mtls / uv run python -m client.demos.tls --mtls
Bearer token via metadata interceptor
client/interceptors/auth.py
--tls --auth-token secret123 / uv run python -m client.demos.auth_tokens
Channel-level vs per-RPC credentials
client/demos/auth_tokens.py
same
Discovery and load balancing
Feature
Where
Demo command
Client-side round_robin over multiple backends
client/demos/load_balancing.py
see module docstring (3 local servers, ipv4: target)
DNS-based name resolution
same
docker compose up --build (dials dns:///server:50051)
Keepalive + max message size channel options
SERVER_OPTIONS in server/main.py, default_options() in client/channel.py
Load test (latency percentiles + streaming throughput)
uv run python scripts/load_test.py
About
A single Python project that demonstrates every major gRPC communication pattern, cross-cutting concern, and operational feature. Works as a learning reference and as a template for production services.