{"id":22059911,"url":"https://github.com/criccomini/proto-schema-parser","last_synced_at":"2025-04-07T15:10:23.745Z","repository":{"id":175921369,"uuid":"654722132","full_name":"criccomini/proto-schema-parser","owner":"criccomini","description":"A pure Python protobuf parser","archived":false,"fork":false,"pushed_at":"2025-03-28T01:04:31.000Z","size":2237,"stargazers_count":51,"open_issues_count":1,"forks_count":24,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T12:06:16.852Z","etag":null,"topics":["abstract-syntax-tree","antlr","bufbuild","data-engineering","data-science","lexer","lexer-parser","parser","protobuf","protocol-buffers","python","schema"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/criccomini.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-16T19:35:48.000Z","updated_at":"2025-03-27T20:51:09.000Z","dependencies_parsed_at":"2023-11-30T19:31:29.484Z","dependency_job_id":"9c1db239-9146-49a3-9221-dac5e0e5b150","html_url":"https://github.com/criccomini/proto-schema-parser","commit_stats":null,"previous_names":["criccomini/pyprotoparser","criccomini/proto-schema-parser","recap-build/proto-schema-parser"],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criccomini%2Fproto-schema-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criccomini%2Fproto-schema-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criccomini%2Fproto-schema-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criccomini%2Fproto-schema-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/criccomini","download_url":"https://codeload.github.com/criccomini/proto-schema-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675607,"owners_count":20977378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstract-syntax-tree","antlr","bufbuild","data-engineering","data-science","lexer","lexer-parser","parser","protobuf","protocol-buffers","python","schema"],"created_at":"2024-11-30T17:34:27.530Z","updated_at":"2025-04-07T15:10:23.725Z","avatar_url":"https://github.com/criccomini.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Protobuf Schema Parser\n\nProtobuf Schema Parser is a pure-Python library that parses and writes Protobuf schemas to and from an abstract syntax tree (AST).\n\nThe library uses `proto_schema_parser.parser.Parser` to parse the [CST into an AST](https://stackoverflow.com/questions/29971097/how-to-create-ast-with-antlr4). The `proto_schema_parser.generator.Generator` class converts the AST back into a CST (a Protobuf schema string).\n\n_The lexer and parser are autogenerated from [Buf](https://buf.build/)'s ANTLR [lexer and parser](https://github.com/bufbuild/protobuf.com/tree/main/examples/antlr) grammar files._\n\n## Features\n\n- ✅ proto2 and proto3 support\n- ✅ message, field, enum, optional, required, repeated\n- ✅ import, package, oneof, map, and option\n- ✅ group and extend (in proto2)\n- ✅ service, rpc, and stream\n- ✅ line and block comment preservation\n\n## Installation\n\nInstall the package via pip:\n\n```bash\npip install proto-schema-parser\n```\n\n## Usage\n\nTo parse a protobuf schema, create a `Parser` object and call the `parse` method:\n\n```python\nfrom proto_schema_parser.parser import Parser\n\ntext = \"\"\"\nsyntax = \"proto3\";\n\nmessage SearchRequest {\n  string query = 1;\n  int32 page_number = 2;\n  int32 result_per_page = 3;\n}\n\"\"\"\n\nresult = Parser().parse(text)\n```\n\nThis will return an AST object (`ast.File`) representing the parsed protobuf schema.\n\n```python\nFile(\n  syntax='proto3',\n  file_elements=[\n    Message(\n      name='SearchRequest',\n      elements=[\n        Field(\n          name='query',\n          number=1,\n          type='string',\n          cardinality=None,\n          options=[]),\n        Field(\n          name='page_number',\n          number=2,\n          type='int32',\n          cardinality=None,\n          options=[]),\n        Field(\n          name='result_per_page',\n          number=3,\n          type='int32',\n          cardinality=None,\n          options=[])])])\n```\n\nTo write the AST back to a protobuf schema, create a `Generator` object and call the `generate` method:\n\n```python\nfrom proto_schema_parser.generator import Generator\n\nproto = Generator().generate(result)\n```\n\nThe `proto` variable now contains the string:\n\n```proto\nsyntax = \"proto3\";\nmessage SearchRequest {\n  string query = 1;\n  int32 page_number = 2;\n  int32 result_per_page = 3;\n}\n```\n\n## Contributing\n\nI welcome contributions!\n\n- Submit a PR and I'll review it as soon as I can.\n- Open an issue if you find a bug or have a feature request.\n\n## License\n\nProtobuf Schema Parser is licensed under the [MIT license](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcriccomini%2Fproto-schema-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcriccomini%2Fproto-schema-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcriccomini%2Fproto-schema-parser/lists"}