Plugin Options¶
Options control how protoc-gen-pydantic generates Python output. They are passed via:
- buf:
opt:inbuf.gen.yaml - protoc:
--pydantic_opt=flag(s)
Summary¶
| Option | Default | Description |
|---|---|---|
preserving_proto_field_name |
true |
Use snake_case proto names instead of camelCase |
auto_trim_enum_prefix |
true |
Remove enum type prefix from value names |
use_integers_for_enums |
false |
Use integer values instead of string names |
disable_field_description |
false |
Omit description= from field annotations |
use_none_union_syntax_instead_of_optional |
true |
Use T \| None instead of Optional[T] |
disable_validate |
false |
Omit all buf.validate constraints and CEL validators from generated models |
preserving_proto_field_name¶
Controls whether field names use the proto snake_case name or the camelCase JSON name.
Default: true (snake_case)
buf.gen.yaml:
protoc:
auto_trim_enum_prefix¶
Removes the enum type name prefix (case-insensitive, with trailing _) from value names.
Default: true (trim prefix)
buf.gen.yaml:
use_integers_for_enums¶
When enabled, enums use int as the mixin type and integer values instead of string names.
Default: false (string values)
buf.gen.yaml:
disable_field_description¶
When enabled, omits description= from generated _Field() calls even when the proto field
has a comment. The inline Python comment is still emitted.
Default: false (include descriptions)
buf.gen.yaml:
use_none_union_syntax_instead_of_optional¶
Controls how nullable types are expressed in annotations.
Default: true (T | None union syntax)
The
T | Nonesyntax requires Python 3.10+ for runtime evaluation. Generated files use string annotations ("T | None") so they are forward-compatible with Python 3.9.
buf.gen.yaml:
disable_validate¶
When enabled, all buf.validate constraints and CEL validators are omitted from the generated
output. The result is identical to what would be produced if the proto files had no
import "buf/validate/validate.proto" and no (buf.validate.field) or
(buf.validate.message) options.
Fields that would otherwise be required due to constraints (e.g., a string.email field with
no valid zero value) revert to their proto3 zero-value defaults ("", 0, false, etc.).
Default: false (include buf.validate constraints)
buf.gen.yaml:
protoc:
Combining options¶
Multiple options can be specified together: