protoc turns a Protocol Buffer service definition into executable, language-specific code. For a Python gRPC client, it generates message classes and a service stub, converting a declarative API contract into callable client infrastructure. section 4.5
A typical generated Python output contains:
- sessions_pb2.py, containing classes for declared messages such as request and response types. section 4.5
- sessions_pb2_grpc.py, containing a service stub with one method for each declared RPC. section 4.5
- The stub serializes requests, sends binary data through the gRPC channel, deserializes responses, and exposes the exchange as a method call. section 4.5
Using generated code in an SDK
A SessionClient creates SessionServiceStub(self._channel), builds a generated GetOrCreateSessionRequest, invokes the RPC, and converts the generated response into a domain Session object. Regenerate the stubs whenever the proto definition changes, preferably through a pre-commit hook or CI step. section 4.5




