https://github.com/Ed-XCF/protobuf2pydantic
generate pydantic model by protobuf.pb2 file
https://github.com/Ed-XCF/protobuf2pydantic
grpc-python pydantic
Last synced: 7 months ago
JSON representation
generate pydantic model by protobuf.pb2 file
- Host: GitHub
- URL: https://github.com/Ed-XCF/protobuf2pydantic
- Owner: Ed-XCF
- License: mit
- Created: 2021-01-03T15:14:22.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-18T06:29:21.000Z (over 1 year ago)
- Last Synced: 2024-10-03T11:19:37.946Z (about 1 year ago)
- Topics: grpc-python, pydantic
- Language: Python
- Homepage:
- Size: 44.9 KB
- Stars: 60
- Watchers: 2
- Forks: 13
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# protobuf2pydantic

[](https://www.travis-ci.org/Ed-XCF/protobuf2pydantic)
[](https://codecov.io/gh/Ed-XCF/protobuf2pydantic)

[](https://lgtm.com/projects/g/Ed-XCF/protobuf2pydantic/context:python)
### Generate a file which include pydantic models by using protobuf.pb2 file
## Installation
```shell
pip3 install protobuf2pydantic
```
## Getting Started
### in CLI
```shell
pb2py ../test_pb2.py > wow.py
```
### in Python
```python
from protobuf2pydantic import msg2py
from pydantic import validator
import transaction_pb2
class AmountResponse(msg2py(transaction_pb2.AmountResponse)):
@validator("amount")
def non_negative(cls, v):
assert v >= 0
return v
```
### * Required proto file syntax = "proto3";