{"id":21001,"library":"betterproto2-compiler","title":"BetterProto2 Compiler","description":"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.","status":"active","version":"0.9.0","language":"python","source_language":"en","source_url":"https://github.com/betterproto/python-betterproto2","tags":["protobuf","compiler","code-generation","grpc","pydantic"],"install":[{"cmd":"pip install betterproto2-compiler","lang":"bash","label":"Standard install"},{"cmd":"pip install betterproto2-compiler[grpclib]","lang":"bash","label":"Install with gRPC support"}],"dependencies":[{"reason":"Optional dependency for gRPC service generation.","package":"grpclib","optional":true},{"reason":"Runtime library required for generated code.","package":"betterproto2","optional":false}],"imports":[{"note":"betterproto2 is the new package; betterproto is the older v1 package.","wrong":"from betterproto.compiler import Compile","symbol":"Compile","correct":"from betterproto2.compiler import Compile"}],"quickstart":{"code":"from betterproto2.compiler import Compile\nfrom pathlib import Path\n\n# Generate Python code from .proto files\nCompile.from_path(Path(\"my_protos\")).compile(Path(\"output/\"))","lang":"python","description":"Compile all .proto files in 'my_protos' directory into Python modules in 'output/'."},"warnings":[{"fix":"Update to betterproto2-compiler >=0.7.0 and use the new Compile class.","message":"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.","severity":"breaking","affected_versions":"<0.7.0"},{"fix":"Uninstall betterproto and install betterproto2-compiler.","message":"The old betterproto (v1) compiler is deprecated and incompatible with betterproto2. Do not mix packages.","severity":"deprecated","affected_versions":"all"},{"fix":"Use Python 3.10 to 3.12 (3.13 not yet tested).","message":"The compiler requires Python >=3.10 and <4.0. Older Python versions will fail to install.","severity":"gotcha","affected_versions":"0.9.0"},{"fix":"Install both: pip install betterproto2 betterproto2-compiler","message":"Generated code imports runtime library 'betterproto2'. If you only install the compiler, generated code will fail at runtime without betterproto2 installed.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"pip install betterproto2","cause":"Generated code imports betterproto2 but runtime package is missing.","error":"pkg_resources.DistributionNotFound: The 'betterproto2' distribution was not found"},{"fix":"Use: from betterproto2.compiler import Compile","cause":"Using old import pattern from betterproto v1.","error":"AttributeError: module 'betterproto2.compiler' has no attribute 'Compile'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}