skillfed

betterproto2-compiler

Compiler for betterproto2

betterproto2-compiler v0.10.1 119.2K downloads/30d#12,079 on PyPI170
Permissive license MIT Active released

What it is and what it does

betterproto2-compiler is a code generator that transforms Protobuf 3 and gRPC definitions into readable, idiomatic Python code. It reimplements Google's protoc plugin from the ground up, prioritizing modern Python idioms—dataclasses, async/await, type hints, and built-in datetime objects—over legacy patterns. The generated code includes both binary and JSON serialization, supports Pydantic model generation, and produces importable modules with proper `__init__.py` files.

The package addresses long-standing limitations of the official protoc plugin: it adds native async support, full type checking and IDE completion, relative imports that work in Python 3, and avoids name-collision bugs. While the wire format remains compatible with standard Protobuf, the generated API differs—using Pythonic method names and patterns instead of capitalized functions like `HasField()` or `SerializeToString()`. The project is actively developed but explicitly subject to breaking changes, and documentation is incomplete.

Use it for:

  • Generate async gRPC service stubs and client code without requiring additional plugins or manual async wrapping.
  • Create type-hinted, IDE-friendly Python dataclasses from Protobuf schemas for better developer experience and static analysis.
  • Build Pydantic-compatible models directly from Protobuf definitions for validation and serialization workflows.
  • Modernize Protobuf-based Python projects by replacing Google's protoc plugin with idiomatic, readable generated code.
  • Develop microservices that use Protobuf for serialization while leveraging Python's async/await and modern language features.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Generates idiomatic Python code from Protobuf 3 and gRPC definitions, with built-in async/await support, type hints, and modern Python features like dataclasses and timezone-aware datetime objects.

Yes, with conditions. Install if you need async gRPC support, type hints, and idiomatic Python code generation from Protobuf 3 schemas. The low install friction, active maintenance, and MIT license support adoption. However, accept that the project is under active development with incomplete documentation and potential breaking changes—unsuitable for production systems requiring stability guarantees.

Install

betterproto2-compiler on PyPI

pip

pip install betterproto2-compiler

uv

uv add betterproto2-compiler

poetry

poetry add betterproto2-compiler

Installing betterproto2-compiler

Before you install

Low install friction with a pure-wheel distribution. The package is actively maintained with a recent commit history, though it explicitly notes ongoing development and potential breaking changes.

License in practice

MIT license permits free use, modification, and distribution with minimal restrictions, making it suitable for both open-source and commercial projects.

Quickstart

pip install betterproto2-compiler

from betterproto2 import Message

class Example(Message):
    name: str = 1

Requires Python 3.10 or higher; the package is under active development and may introduce breaking changes.

Verify before relying

  • Exact scope of breaking changes expected during active development and timeline for stabilization
  • Whether generated code is fully compatible with standard gRPC tooling and ecosystems
  • Performance characteristics compared to the original betterproto or Google's protoc plugin

Package facts

License MIT (permissive)
Python support supports the current Python release (<4.0,>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 5 — betterproto2, ruff, jinja2, typing-extensions, strenum
Maintenance actively maintained — 93 days since the last release
Last repo commit
First released
Downloads 119,230/month — #12,079 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: betterproto2_compiler-0.10.1-py3-none-any.whl

Keywords: protobuf, gRPC, compiler

Tags

protobuf code generation pythongrpc compiler async pythonprotobuf to python dataclassmodern protobuf pythongrpc code generatorprotobuf3 python compilerasync grpc python
protobufgrpccode-generation

More Build Tools packages