Skip to main content

A Pure Python Protobuf 3 .proto Parser

Project description

Protobuf Schema Parser

A Pure Python Protobuf 3 .proto schema Parser

Install

pip install proto-schema-parser

Usage

from pprint import pprint
from proto_schema_parser import Parser

messages = Parser().parse("""
    syntax = "proto3";

    message SearchRequest {
        string query = 1 [(validate.rules).double = {gte: -90,  lte: 90}];
        optional int32 page_number = 2;
        option foo = "bar";
        int32 results_per_page = 3;
    }
""")

pprint(messages)

"""
{'SearchRequest': Message(name='SearchRequest',
                          fields=[Field(name='query',
                                        type='string',
                                        cardinality=<FieldCardinality.REQUIRED: 'REQUIRED'>,
                                        options=[Option(name='(validate.rules).double',
                                                        value='{gte:-90,lte:90}')]),
                                  Field(name='page_number',
                                        type='int32',
                                        cardinality=<FieldCardinality.OPTIONAL: 'OPTIONAL'>,
                                        options=[]),
                                  Field(name='results_per_page',
                                        type='int32',
                                        cardinality=<FieldCardinality.REQUIRED: 'REQUIRED'>,
                                        options=[])])}
"""

About

proto-schema-parser is a pure Python implementation of a .proto parser. It uses Buf.build's ANTLR Proto .g4 files to generate a Python Protocol buffer lexer and parser. The lexer and parser are complete implementations of Proto 2 and 3.

The project also includes a very simple Parser class and data model to make parsing .proto text easier.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

proto_schema_parser-0.1.0.tar.gz (53.4 kB view hashes)

Uploaded Source

Built Distribution

proto_schema_parser-0.1.0-py3-none-any.whl (55.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page