skillfed

protobuf_to_pydantic

Generate the `pydantic.BaseModel` class (and the corresponding source code) with parameter verification function through the Protobuf file

protobuf-to-pydantic v0.3.3.1 520.8K downloads/30d#6,208 on PyPI148
Permissive license Apache Software License Active released

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-pydantic

uv

uv add protobuf-to-pydantic

poetry

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 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

License :: Other/Proprietary LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

protobuf to pydantic conversiongenerate pydantic models from protoprotoc plugin for pydanticproto3 validation with pydanticprotobuf schema to python modelsruntime protobuf to pydanticproto message validation
code-generationprotobufschema-validation

More Build Tools packages