{"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,"search_vec":"'1.27.2':21 'beauti':11 'buffer':18,27 'current':19 'interfac':13 'librari':7 'maintain':22 'plus':2 'proto':1 'protobuf':30 'protocol':17,26 'provid':9 'python':4,6,12,28 'regular':24 'serial':29 'updat':25 'version':20 'work':15","created_at":"2026-03-28T10:52:23.429259+00:00","updated_at":"2026-04-16T19:09:08.989632+00:00","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,"quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"1.28.4","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/googleapis/google-cloud-python","docs":"https://googleapis.dev/python/proto-plus/latest/","changelog":null,"pypi":"https://pypi.org/project/proto-plus/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}