protobuf_to_pydantic
Generate the `pydantic.BaseModel` class (and the corresponding source code) with parameter verification function through the Protobuf file
What it is and what it does
protobuf_to_pydantic bridges Protobuf message definitions and Pydantic models, letting you generate validated Python dataclasses from .proto files. It works in two modes: as a protoc plugin that generates source code files (the recommended approach), or at runtime by parsing Protobuf Message objects directly into Pydantic classes. The generated models inherit Pydantic's validation rules and are compatible with both Pydantic V1 and V2.
The package supports multiple validation rule sets including proto-gen-validate, and allows customization through template configuration. It depends on pydantic and protobuf at runtime, making integration straightforward for projects already using either library. The plugin mode generates files with a _p2p.py suffix, keeping generated code separate from hand-written code.
Use it for:
- Generate type-safe Pydantic models from existing .proto schemas to avoid manual dataclass duplication and keep definitions synchronized.
- Add Pydantic validation to Protobuf messages in gRPC services without rewriting message definitions.
- Convert Protobuf validation rules into Pydantic field constraints during code generation.
- Dynamically instantiate Pydantic models from Protobuf Message objects at runtime for serialization or API responses.
- Maintain a single source of truth for message schemas across Protobuf and Python codebases with automatic synchronization.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts Protobuf message definitions into Pydantic models with validation, either as generated source code via a protoc plugin or as runtime-instantiated classes in Python.
Yes. The package solves a real friction point—keeping Protobuf schemas and Pydantic models in sync—with low install overhead, active maintenance, permissive licensing, and no known vulnerabilities. It supports Python 3.7 through 3.12 and integrates cleanly into existing protoc workflows. Install it if your project uses both protobuf and pydantic and you want to avoid hand-maintaining duplicate message definitions.
Install
protobuf-to-pydantic on PyPI
pip
pip install protobuf-to-pydanticuv
uv add protobuf-to-pydanticpoetry
poetry add protobuf-to-pydanticInstalling protobuf_to_pydantic
Before you install
Low friction install with just pydantic and protobuf as runtime dependencies. Repository is active with a recent commit on 2026-06-07 and 148 stars; last release was 433 days ago, suggesting stable maintenance rather than rapid iteration.
License in practice
Licensed under Apache Software License, a permissive license that allows commercial and private use with minimal restrictions, making it safe to adopt in most projects.
Quickstart
pip install protobuf_to_pydantic
# Plugin mode (recommended):
python -m grpc_tools.protoc -I. --protobuf-to-pydantic_out=. example.proto
# Runtime mode:
from protobuf_to_pydantic import message_to_pydantic
Plugin mode requires mypy-protobuf as an additional dependency; protoc or grpc_tools must be available in your environment.
Verify before relying
- Exact scope of proto-gen-validate compatibility and which validation rules are currently supported versus planned.
- Whether template customization is documented with concrete examples beyond the configuration file structure shown.
- Performance characteristics when converting large or deeply nested Protobuf schemas.
- Specific API surface and function names available in runtime mode for instantiating Pydantic models from protobuf messages.
Package facts
| License | Apache Software License (permissive) |
| Python support | supports the current Python release (<4.0,>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pydantic, protobuf |
| Maintenance | actively maintained — 433 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 520,804/month — #6,208 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: protobuf_to_pydantic-0.3.3.1-py3-none-any.whl
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
mypy-protobufGenerates mypy-compatible stub files (.pyi)…
permissive · top 5,000 on PyPI
aristaprotoGenerates Python gRPC stubs and message classes…
permissive · top 15,000 on PyPI
hatch-protobufA Hatch build plugin that generates Python…
copyleft · top 15,000 on PyPI
betterprotoGenerates idiomatic Python code from Protobuf 3…
permissive · top 5,000 on PyPI
setuptools-protobufA setuptools plugin that automates compilation…
permissive · top 15,000 on PyPI
pbsparkConverts protobuf messages to and from PySpark…
permissive · top 15,000 on PyPI
proto-schema-parserParses and generates Protobuf schema files…
permissive · top 15,000 on PyPI
betterproto-fwGenerates idiomatic Python code from Protobuf 3…
permissive · top 15,000 on PyPI
sigstore-modelsProvides Pydantic-based data models that mirror…
unclear · top 15,000 on PyPI
sigstore-protobuf-specsProvides Python protobuf message definitions…
permissive · top 15,000 on PyPI