Registry / serialization / proto-schema-parser

proto-schema-parser

JSON →
library2.1.0pypypi✓ verified 85d ago

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.

pip install proto-schema-parser
INSTALL
IMPORT
SIG · PROTO-SCHEMA-PARSE
P
proto-schema-parser
serializationpythonv2.1.0
Install
1.7s avg
Import
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.7MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.7s · import 0.000s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Parser
from proto_schema_parser import Parser
from proto_schema_parser import ProtoParser
Message
from proto_schema_parser import Message
Field
from proto_schema_parser import Field

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`.

from proto_schema_parser import ProtoParser proto_content = """ syntax = "proto3"; package my.package; message MyMessage { string name = 1; int32 age = 2; } """ parser = ProtoParser() parsed_proto = parser.parse(proto_content) print(f"Syntax: {parsed_proto.syntax}") # Output: Syntax: proto3 print(f"Package: {parsed_proto.package}") # Output: Package: my.package print(f"Message Name: {parsed_proto.messages[0].name}") # Output: Message Name: MyMessage
Debug
Known issues
breakingVersion 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.
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.
affects: >=2.0.0 (when upgrading from <2.0.0)
gotchaThe 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.
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.
affects: all
Upgrade
Version history
2.1.0latest on PyPI · released Nov 5, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
proto-schema-parser — pip install proto-schema-parser · libregistry