{"id":8840,"library":"aristaproto","title":"Arista Protobuf / Python gRPC bindings generator & library","description":"Arista Protobuf / Python gRPC bindings generator & library (version 0.1.4). It provides tools to compile `.proto` files into Python classes, offering features like JSON serialization/deserialization, one-of support, and customized handling of Google Well-known Types. Forked from `python-betterproto`, it maintains compatibility with `grpclib` for async gRPC support. The project is actively maintained by Arista Networks, with development ongoing, though official PyPI releases have an irregular cadence.","status":"active","version":"0.1.4","language":"en","source_language":"en","source_url":"https://github.com/aristanetworks/python-aristaproto","tags":["protobuf","grpc","arista","code-generation","dataclasses","pydantic"],"install":[{"cmd":"pip install \"aristaproto[compiler]\"","lang":"bash","label":"Install with compiler support"},{"cmd":"pip install aristaproto","lang":"bash","label":"Install library only"}],"dependencies":[{"reason":"Required for invoking protoc via `python -m grpc_tools.protoc` to compile .proto files.","package":"grpcio-tools","optional":true},{"reason":"Required when generating Pydantic dataclasses using the `--python_aristaproto_opt=pydantic_dataclasses` option.","package":"pydantic","optional":true}],"imports":[{"note":"Base class for generated protobuf messages.","symbol":"Message","correct":"import aristaproto\nfrom generated_proto_file import MyMessage\n\nclass MyMessage(aristaproto.Message): ..."},{"note":"Helper to determine which field in a 'oneof' group is set.","symbol":"which_one_of","correct":"import aristaproto\n\nfield_name, value = aristaproto.which_one_of(message_instance, 'oneof_group_name')"},{"note":"Checks if a message field (Proto 3 only) was sent on the wire, not applicable to scalar fields.","symbol":"serialized_on_wire","correct":"import aristaproto\n\nif aristaproto.serialized_on_wire(message_instance.field_name): ..."}],"quickstart":{"code":"# 1. Create a .proto file (e.g., example.proto)\n# syntax = \"proto3\";\n# package hello;\n# message Greeting {\n#     string message = 1;\n# }\n\n# 2. Compile the .proto file (assuming 'example.proto' is in current dir)\n# mkdir -p lib\n# protoc -I . --python_aristaproto_out=lib example.proto\n# OR using grpcio-tools (after pip install grpcio-tools):\n# python -m grpc_tools.protoc -I . --python_aristaproto_out=lib example.proto\n\n# 3. Use the generated code (e.g., from lib/hello/__init__.py)\nimport os\nimport sys\n# Add the 'lib' directory to Python path if not already added\n# In a real project, 'lib' would likely be part of your package structure\n# or installed.\nif os.path.exists('lib') and 'lib' not in sys.path:\n    sys.path.insert(0, 'lib')\n\nfrom hello import Greeting\n\ng = Greeting(message=\"Hello, Arista!\")\nprint(f\"Created message: {g.message}\")\n\n# Example of serialization\njson_output = g.to_json()\nprint(f\"JSON representation: {json_output}\")\n\n# Example of deserialization\ng_from_json = Greeting.from_json(json_output)\nprint(f\"Message from JSON: {g_from_json.message}\")","lang":"python","description":"This quickstart demonstrates compiling a simple `.proto` file and then importing and using the generated Python message classes for creation, serialization to JSON, and deserialization from JSON. It requires `protoc` to be installed and accessible in your PATH, or `grpcio-tools` if using the Python `grpc_tools.protoc` module for compilation."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Python versions older than 3.9 are no longer supported. Attempting to install or run on older versions will fail.","severity":"breaking","affected_versions":"All versions >= 0.1.0 (after the fork from betterproto)"},{"fix":"Review the `aristaproto` GitHub README for a list of changes compared to the base project, especially regarding `Timestamp` precision and `serialized_on_wire` behavior.","message":"`aristaproto` is a fork of `python-betterproto`. While many concepts are similar, direct migrations may require adjustments due to renaming, specific behavior changes (e.g., Timestamp handling), and updated dependencies.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of this limitation when designing your protobuf messages and logic. For scalar fields, you might need to use wrapper types (e.g., `google.protobuf.StringValue`) if differentiating between unset and default values is critical.","message":"The `aristaproto.serialized_on_wire()` function only supports checking if Proto 3 *message* fields were sent on the wire. It cannot be used to determine if *scalar* fields (like strings, integers) were explicitly sent or are just default values.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `pydantic` is listed as a dependency in your project (e.g., `pip install pydantic`).","message":"When using the `--python_aristaproto_opt=pydantic_dataclasses` option for Pydantic model generation, you must explicitly install `pydantic` in your project. It is not included by default with `aristaproto`.","severity":"gotcha","affected_versions":"All versions supporting Pydantic dataclass generation"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the `grpcio-tools` package: `pip install grpcio-tools`. Alternatively, ensure the full `aristaproto[compiler]` is installed: `pip install \"aristaproto[compiler]\"`.","cause":"The `grpcio-tools` package, which contains the `grpc_tools.protoc` module for Python-based compilation, is not installed.","error":"ModuleNotFoundError: No module named 'grpc_tools'"},{"fix":"When converting between `aristaproto.Timestamp` and standard `datetime` objects, be mindful of the subclassing. If you need a pure `datetime` object, explicitly convert it, but be aware of potential loss of nanosecond precision if not handled correctly. Refer to `aristaproto` documentation on `Timestamp` conversions.","cause":"`aristaproto` customizes `Timestamp` handling by subclassing Python's `datetime` to maintain nanosecond precision. Direct interactions expecting standard `datetime` behavior without considering this subclassing can lead to issues.","error":"TypeError: 'Timestamp' object has no attribute 'tzinfo' (or similar datetime related errors)"},{"fix":"Upgrade your Python environment to version 3.9 or newer. Consider using `pyenv` or `conda` for managing multiple Python versions.","cause":"You are attempting to install `aristaproto` on a Python version older than 3.9.","error":"ERROR: Package 'aristaproto' requires a different Python: <4.0, >=3.9"}]}