Features
Services
Services defined in a .proto file are compiled into DescService descriptors, but no RPC stubs are generated.
They are accessible via the file descriptor:
For RPC clients and servers built on protobuf-py, see Connect for Python.
Comments
Comments in .proto files become docstrings on the generated Python classes and attributes:
Reserved names
Python keywords and names that conflict with built-in Message attributes are suffixed with a trailing underscore in the generated property name.
This has no impact on the binary encoding or on the JSON representation.
Enum value prefix stripping
Proto convention is to prefix every enum value with the enum name.
The code generator strips this prefix (derived from the snake_case form of the enum name) from the generated Python class:
The prefix is not stripped if the stripped value would start with a digit or match any other enum value.
enum PhoneType {
PHONE_TYPE_UNSPECIFIED = 0;
PHONE_TYPE_MOBILE = 1;
PHONE_TYPE_HOME = 2;
PHONE_TYPE_1800 = 3;
MOBILE = 4;
}
class PhoneType(Enum):
UNSPECIFIED = 0
PHONE_TYPE_MOBILE = 1
HOME = 2
PHONE_TYPE_1800 = 3
MOBILE = 4
See Enums for open/closed behavior and JSON representation.
Nested types
Nested messages and enums are generated as regular Python nested classes:
Access them as User.Role, User.Role.ADMIN, etc.