BetterProto2 Compiler

raw JSON →
0.9.0 verified Mon Apr 27 auth: no python

Compiler for betterproto2, a Python protobuf library with async support, Pydantic integration, and typed generated code. Current version 0.9.0. Releases are coupled with the betterproto2 library; compiler versions match library releases with a 'compiler-v' tag. Released monthly or on-demand.

pip install betterproto2-compiler
error pkg_resources.DistributionNotFound: The 'betterproto2' distribution was not found
cause Generated code imports betterproto2 but runtime package is missing.
fix
pip install betterproto2
error AttributeError: module 'betterproto2.compiler' has no attribute 'Compile'
cause Using old import pattern from betterproto v1.
fix
Use: from betterproto2.compiler import Compile
breaking The Compile API changed in compiler v0.7.0. Old code using Compiler or compiler.Compile may break. Use Compile.from_path() and .compile() methods.
fix Update to betterproto2-compiler >=0.7.0 and use the new Compile class.
deprecated The old betterproto (v1) compiler is deprecated and incompatible with betterproto2. Do not mix packages.
fix Uninstall betterproto and install betterproto2-compiler.
gotcha The compiler requires Python >=3.10 and <4.0. Older Python versions will fail to install.
fix Use Python 3.10 to 3.12 (3.13 not yet tested).
gotcha Generated code imports runtime library 'betterproto2'. If you only install the compiler, generated code will fail at runtime without betterproto2 installed.
fix Install both: pip install betterproto2 betterproto2-compiler
pip install betterproto2-compiler[grpclib]

Compile all .proto files in 'my_protos' directory into Python modules in 'output/'.

from betterproto2.compiler import Compile
from pathlib import Path

# Generate Python code from .proto files
Compile.from_path(Path("my_protos")).compile(Path("output/"))