{"id":366,"library":"proto-plus","title":"Proto Plus for Python","description":"A Python library that provides a beautiful, Pythonic interface for working with protocol buffers. Current version: 1.27.2. Maintained with regular updates.","status":"active","version":"1.27.2","language":"python","source_language":"en","source_url":"https://github.com/googleapis/proto-plus-python","tags":["protocol buffers","Python","serialization","protobuf"],"install":[{"cmd":"pip install proto-plus","lang":"bash","label":"Install Proto Plus"}],"dependencies":[{"reason":"Required for protocol buffer support","package":"protobuf"}],"imports":[{"note":"Ensure 'proto' is imported to access the library's functionalities.","symbol":"proto","correct":"import proto"},{"note":"Import 'Message' from 'proto' to define protocol buffer messages.","symbol":"proto.Message","correct":"from proto import Message"}],"quickstart":{"code":"import proto\n\nclass Composer(proto.Message):\n    given_name = proto.Field(proto.STRING, number=1)\n    family_name = proto.Field(proto.STRING, number=2)\n\nclass Song(proto.Message):\n    composer = proto.Field(Composer, number=1)\n    title = proto.Field(proto.STRING, number=2)\n    lyrics = proto.Field(proto.STRING, number=3)\n    year = proto.Field(proto.INT32, number=4)\n\nsong = Song(\n    composer={'given_name': 'Johann', 'family_name': 'Pachelbel'},\n    title='Canon in D',\n    year=1680,\n)\nprint(song.composer.family_name)  # Output: Pachelbel\nprint(song.title)  # Output: Canon in D","lang":"python","description":"A simple example demonstrating how to define and use protocol buffer messages with Proto Plus."},"warnings":[{"fix":"Update your 'Field' class instantiations to include 'type' and 'number' arguments.","message":"Proto Plus 1.27.0 introduced changes to the 'Field' class constructor, requiring explicit 'type' and 'number' arguments.","severity":"breaking","affected_versions":"1.27.0"},{"fix":"Define nested message classes before the parent class to prevent 'NameError' during instantiation.","message":"When defining nested messages, ensure that the nested class is defined before the parent class to avoid 'NameError'.","severity":"gotcha","affected_versions":"All"},{"fix":"It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv","message":"Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-05-12T13:19:25.104Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Generate the Python code from your '.proto' files using the `protoc` compiler and ensure the output directory is in your `PYTHONPATH` or added to `sys.path`:\n`protoc --python_out=. --proto_path=. your_service.proto`","cause":"This error occurs because the Python protobuf code has not been generated from your '.proto' file, or the generated files are not in a directory included in your Python import path (PYTHONPATH).","error":"ModuleNotFoundError: No module named 'your_app_name.proto.your_service_pb2'"},{"fix":"Ensure `proto-plus` is installed (`pip install proto-plus`) and that your environment allows it to patch the protobuf classes. These methods should become available automatically when `proto-plus` is active.","cause":"The `to_dict()` and `from_dict()` methods are enhancements provided by `proto-plus`, and this error indicates that `proto-plus` is either not installed, not correctly applied to your protobuf classes, or an older version is in use.","error":"AttributeError: 'MyProtoMessage' object has no attribute 'to_dict'"},{"fix":"Decode the `bytes` data into a `str` (unicode string) before assigning it to a protobuf `string` field, typically using `.decode('utf-8')`.","cause":"This error arises when you attempt to assign a `bytes` object that is not a valid UTF-8 sequence to a protobuf field defined as a `string` type, which expects a Python `str` (unicode).","error":"TypeError: cannot interpret bytestring as UTF-8"},{"fix":"Always assign an iterable (even a list with a single item) to a repeated field.","cause":"This error occurs when you try to assign a single scalar value (e.g., a string or integer) directly to a protobuf repeated field, which expects an iterable (like a list or tuple) of values.","error":"TypeError: Can't set repeated field to non-iterable"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.22,"mem_mb":5.2,"disk_size":"19.8M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":4.1,"disk_size":"21M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.59,"mem_mb":5.8,"disk_size":"22.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.15,"mem_mb":4.7,"disk_size":"23M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.49,"mem_mb":5.7,"disk_size":"14.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.15,"mem_mb":4.6,"disk_size":"15M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.46,"mem_mb":6.1,"disk_size":"13.6M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.16,"mem_mb":5.1,"disk_size":"14M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":5.1,"disk_size":"19.3M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.09,"mem_mb":4,"disk_size":"20M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}