{"library":"pbtools","title":"Google Protocol Buffers Tools","description":"`pbtools` is a Python library for working with Google Protocol Buffers. It provides tools to read, write, encode, and decode Protocol Buffers messages (both binary and text) directly from `.proto` definitions, *without* requiring generated Python code. This simplifies field access and enables decoding of unknown messages. The current version is 0.47.0, and it maintains an active release cadence with incremental updates.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pbtools"],"cli":null},"imports":["from pbtools import build_database","from pbtools import Database","from pbtools import Message","from pbtools import Field"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pbtools\nimport os\n\n# Example .proto file content\nproto_file_content = \"\"\"\nsyntax = \"proto3\";\n\nmessage MyMessage {\n    int32 id = 1;\n    string name = 2;\n    repeated int32 values = 3;\n}\n\"\"\"\n# For simplicity, write to a temporary file\nproto_path = \"my_message.proto\"\nwith open(proto_path, \"w\") as f:\n    f.write(proto_file_content)\n\n# Build a database from .proto files\ndatabase = pbtools.build_database([proto_path])\n\n# Get the message type from the database\nMyMessage = database.MyMessage\n\n# Create a message instance\nmessage = MyMessage(id=1, name=\"hello\", values=[10, 20, 30])\nprint(f\"Original message: {message}\")\n\n# Encode to binary\nencoded = message.encode()\nprint(f\"Encoded bytes: {encoded}\")\n\n# Decode from binary\ndecoded = MyMessage.decode(encoded)\nprint(f\"Decoded message: {decoded}\")\n\n# Access fields\nprint(f\"Decoded ID: {decoded.id}\")\nprint(f\"Decoded Name: {decoded.name}\")\nprint(f\"Decoded Values: {decoded.values}\")\n\n# Clean up the temporary file\nos.remove(proto_path)","lang":"python","description":"This quickstart demonstrates how to define a Protocol Buffer message, build a database from its `.proto` definition, create a message instance, encode it to binary, and then decode it back using `pbtools`. It highlights the direct interaction with messages without code generation.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}