Enums
Protobuf enums map to Python IntEnum subclasses.
Values compare equal to plain integers and can be used anywhere an integer is expected.
Open and closed enums
In proto3 and editions, enums are open by default: unknown integer values are accepted during parsing and preserved for round-tripping. Proto2 enums are closed: unknown values are rejected during parsing.
The desc().open attribute indicates which behavior applies:
JSON representation
By default, enum values serialize to their string name in ProtoJSON:
To serialize as integers instead, pass print_enums_as_ints=True:
See Serialization for the full list of JSON options.
For details on how enum value names are generated, see Enum value prefix stripping.