Proto Schema Parser

2.1.0 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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

view raw JSON →