{"id":10064,"library":"proto-schema-parser","title":"Proto Schema Parser","description":"A pure Python library for parsing Protobuf `.proto` files into an Abstract Syntax Tree (AST)-like structure. It provides an intuitive object model for navigating and extracting information from parsed schema definitions. As of version 2.1.0, it primarily supports `proto3` syntax and offers a robust, actively maintained solution for programmatic schema inspection.","status":"active","version":"2.1.0","language":"en","source_language":"en","source_url":"https://github.com/vjftw/proto-schema-parser","tags":["protobuf","parser","schema","ast","proto"],"install":[{"cmd":"pip install proto-schema-parser","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"ProtoParser","correct":"from proto_schema_parser import ProtoParser"}],"quickstart":{"code":"from proto_schema_parser import ProtoParser\n\nproto_content = \"\"\"\nsyntax = \"proto3\";\n\npackage my.package;\n\nmessage MyMessage {\n    string name = 1;\n    int32 age = 2;\n}\n\"\"\"\n\nparser = ProtoParser()\nparsed_proto = parser.parse(proto_content)\n\nprint(f\"Syntax: {parsed_proto.syntax}\") # Output: Syntax: proto3\nprint(f\"Package: {parsed_proto.package}\") # Output: Package: my.package\nprint(f\"Message Name: {parsed_proto.messages[0].name}\") # Output: Message Name: MyMessage\n","lang":"python","description":"This example demonstrates how to parse a basic Protobuf `.proto` string and access its top-level elements like syntax, package, and message names using the `ProtoParser`."},"warnings":[{"fix":"Review the new object model by inspecting the `ProtoNode` and related classes available in the library, or by printing the `parsed_proto` object and its attributes (e.g., using `dir()` or a debugger) to understand the new structure. Top-level accessors like `.syntax`, `.package`, and `.messages` often remain, but nested structures and attribute names within nodes may have changed.","message":"Version 2.0.0 introduced significant breaking changes due to a complete refactor of the internal Abstract Syntax Tree (AST) representation. Code written for 1.x versions that traverses the parsed object structure will likely fail when upgrading.","severity":"breaking","affected_versions":">=2.0.0 (when upgrading from <2.0.0)"},{"fix":"Ensure your `.proto` files explicitly specify `syntax = \"proto3\";` for guaranteed correct parsing. If parsing `proto2` files, carefully validate the resulting AST structure against your expectations and be prepared for potential limitations.","message":"The parser is primarily designed and tested for `proto3` syntax. While it may parse some `proto2` files, full `proto2` compatibility is not guaranteed, and some `proto2`-specific features (e.g., `optional`, `required` keywords, extensions) might not be fully represented or correctly parsed.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"This often indicates an old access pattern. For example, if you used `parsed_proto.package_name` or `parsed_proto.package.name` in `1.x`, in `2.x` you should likely use `parsed_proto.package` directly to get the package string. Refer to the current documentation or inspect the `ProtoNode` objects for the correct attribute names.","cause":"Attempting to access an attribute on a parsed AST node (e.g., `ProtoFile`, `Message`) that no longer exists or has been renamed following the v2.0.0 AST refactor.","error":"AttributeError: 'ProtoFile' object has no attribute 'package_name'"},{"fix":"Carefully review the `.proto` file for any grammatical mistakes, missing semicolons, incorrect keyword usage, or unclosed blocks. Ensure the file adheres to the Protobuf `proto3` specification (or `proto2` if you are aware of its parsing limitations with this library) at the specified line and column number in the error message.","cause":"The input `.proto` content contains a syntax error or an unsupported language construct, preventing the parser from building a valid Abstract Syntax Tree.","error":"proto_schema_parser.exceptions.ParseError: Expected one of [IDENTIFIER, INT_LIT, STRING_LIT, ...]"}]}