Configuration Reference

March 25, 2026 · View on GitHub

proto2pydantic accepts options via buf.gen.yaml (under opt:) or as protoc flags.

Options

preset

Preset configurations for common use cases.

ValueEffect
a2aSets alias_generator=camel + enum_style=raw for ProtoJSON compliance per ADR-001

Individual options below can override preset defaults when specified explicitly.

base_class

Override the Pydantic base class for all generated models.

DefaultBaseModel (from pydantic)
Examplea2a._base.A2ABaseModel
FormatDotted Python import path: module.path.ClassName

When set to a non-default value:

  • The base class is imported from the specified module
  • Per-model model_config is NOT emitted — the base class is expected to provide its own ConfigDict (alias generator, populate_by_name, etc.)
  • to_proto_json() is NOT emitted — the base class may provide its own serialization
  • ConfigDict and to_camel are NOT imported — not needed when base handles config

alias_generator

Controls field alias generation for camelCase JSON keys.

ValueEffect
(empty)No alias generation (default)
camelAdds model_config = ConfigDict(populate_by_name=True, alias_generator=to_camel) and a to_proto_json() method on every model

Note: When base_class is set, alias config and to_proto_json() are skipped (see above).

enum_style

Controls how proto enum values are named in Python.

ValueEffectExample
(empty)Strip prefix, lowercase, skip UNSPECIFIED (default)TASK_STATE_SUBMITTEDsubmitted
rawPreserve original proto names, include UNSPECIFIEDTASK_STATE_SUBMITTEDTASK_STATE_SUBMITTED

output_file

Override the output filename.

Default{proto_name}_pb2_pydantic.py
Exampletypes.py

strip_proto_suffix

Use a shorter output filename without _pb2_pydantic suffix.

Defaultfalse
When truea2a.protoa2a.py (instead of a2a_pb2_pydantic.py)

description

Override the module-level docstring in the generated file.

Default"Generated by proto2pydantic from {file}. DO NOT EDIT."
ExampleA2A type definitions generated from a2a.proto

Default Behaviors (always active)

These features are always generated regardless of options:

FeatureDescription
@field_serializer for TimestampSerializes datetime → RFC 3339 string with UTC Z suffix
@field_serializer for bytesSerializes bytes → base64-encoded string
google.api.field_behaviorREQUIREDField(...), OUTPUT_ONLYField(exclude=True)
buf/validate constraintsMapped to Pydantic Field() params: min_length, max_length, gt, ge, etc.
Topological sortModels ordered so dependencies are defined before dependents
__all__ exportsAll enums and models listed in __all__

Example: A2A with custom base class

# buf.gen.yaml
plugins:
  - local: protoc-gen-proto2pydantic
    out: src/a2a
    opt:
      - preset=a2a
      - base_class=a2a._base.A2ABaseModel
      - output_file=types.py
      - description=A2A type definitions generated from a2a.proto

This generates clean models that inherit config from A2ABaseModel:

from a2a._base import A2ABaseModel
from pydantic import Field

class Task(A2ABaseModel):
    """The core unit of action for A2A."""

    id: str = Field(..., description='Unique identifier')
    status: TaskStatus = Field(..., description='Current status')
    ...

No redundant model_config, no duplicate to_camel, no ConfigDict import.