liveBook · Manning

Proto file

As explained in Designing AI Systems

A proto file is a Protocol Buffers definition file that declares structured messages and service operations for code generation.

A proto file defines the contract for a service: structured message types and operations such as GetOrCreateSession and AddMessages. It is declarative rather than executable code. section 4.5

The Protocol Buffer compiler turns the definition into Python artifacts. One module provides message classes; another provides a gRPC stub whose methods serialize requests, perform remote calls, and deserialize responses. section 4.5

Treat the proto file as the boundary between service design and client implementation:

  • Define request and response messages with fields such as user_id and session_id. section 4.5
  • Declare service operations that become methods on the generated stub. section 4.5
  • Regenerate the Protocol Buffer stubs whenever the definition changes, preventing stale accessors and client mismatches. section 4.5
Listing 4.16 SessionClient setup
from proto import sessions_pb2, sessions_pb2_grpc
from .base import BaseClient
 
class SessionClient(BaseClient):
    
    def __init__(self, platform):
        super().__init__(platform, 
➥service_name="sessions")    #A
        self._stub = sessions_pb2_grpc.
➥SessionServiceStub(self._channel)    #B
 

Shows how a generated SessionServiceStub is attached to a client channel. section 4.5

How Designing AI Systems covers it

How deep it goes
Explains declarations, generated modules, serialization, remote calls, and regeneration, but not proto syntax in detail.
Examples
Uses GetOrCreateSession, AddMessages, generated request classes, and SessionServiceStub as concrete artifacts.
What you can do after
Builds a generated Python client that invokes declared service operations through a gRPC stub.
How it connects
Connects Protocol Buffers, gRPC, code generation, service definitions, message types, and RPC operations.

This explainer was generated by Manning's knowledge graph from the text of Designing AI Systems. The section links point to the parts of the book it draws on.