A Pure Python Protobuf 3 .proto Parser
Project description
Protobuf Schema Parser
Protobuf Schema Parser is a pure-Python library that parses Protobuf schemas into an abstract syntax tree (AST).
The lexer and parser are autogenerated from Buf's ANTLR lexer and parser grammar files. The library then proto_schema_parser.parser.Parser
to parse the CST into an AST.
Features
- ✅ proto2 and proto3 support
- ✅ message, field, enum, optional, required, repeated
- ✅ import, package, oneof, map, and option
- ✅ group and extend (in proto2)
- ⬜ service, rpc, and stream
Installation
Install the package via pip:
pip install protobuf-schema-parser
Usage
To parse a protobuf schema, create a Parser
object and call the parse
method:
from proto_schema_parser.parser import Parser
text = """
syntax = "proto3";
message SearchRequest {
string query = 1;
int32 page_number = 2;
int32 result_per_page = 3;
}
"""
result = Parser().parse(text)
This will return an AST object (ast.File
) representing the parsed protobuf schema.
File(syntax='proto3',
file_elements=[Message(name='SearchRequest',
elements=[Field(name='query',
number=1,
type='string',
cardinality=None,
options=[]),
Field(name='page_number',
number=2,
type='int32',
cardinality=None,
options=[]),
Field(name='result_per_page',
number=3,
type='int32',
cardinality=None,
options=[])])])
Contributing
I welcome contributions!
- Submit a PR and I'll review it as soon as I can.
- Open an issue if you find a bug or have a feature request.
License
Protobuf Schema Parser is licensed under the MIT license.
Project details
Release history Release notifications | RSS feed
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.2.0.tar.gz
(56.3 kB
view hashes)
Built Distribution
Close
Hashes for proto_schema_parser-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 463549990b3ecbaa6cc0584ab27bfc63e084f55b1639cef9cd877cf5a9f3911b |
|
MD5 | 21c92a11629d7c1ab27b133789a304d5 |
|
BLAKE2b-256 | ae2d5a824f2c515f3349578680748490024cfcdaecd76acf9bdb220a41afbd46 |
Close
Hashes for proto_schema_parser-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d30521d3b6c0225dcf7b89536b7ebfdbefdef8b638b88346f29b7dead66dea58 |
|
MD5 | 68ed75d7de46e823baf68f351fd261c9 |
|
BLAKE2b-256 | 37d789dd93f92a71b987b39ca7fd940b351264abc99426a079e79fea1e24d261 |