--- id: protobuf-to-pydantic version: "0.3.3.1" license: Apache Software License license_treatment: permissive maintenance: active --- # protobuf_to_pydantic — Generate the `pydantic.BaseModel` class (and the corresponding source code) with parameter verification function through the Protobuf file License: permissive · Maintenance: active · Downloads: 520.8K/mo ## 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 above — 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 pip install protobuf-to-pydantic uv add protobuf-to-pydantic poetry add protobuf-to-pydantic ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 520.8K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags protobuf to pydantic conversion, generate pydantic models from proto, protoc plugin for pydantic, proto3 validation with pydantic, protobuf schema to python models, runtime protobuf to pydantic, proto message validation, code-generation, protobuf, schema-validation [View on SkillFed](https://skillfed.io/packages/protobuf-to-pydantic) · [View on PyPI](https://pypi.org/project/protobuf-to-pydantic/)