Ed-XCF / protobuf2pydantic

generate pydantic model by protobuf.pb2 file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

protobuf2pydantic

GitHub Build Status codecov PyPI Language grade: Python

Generate a file which include pydantic models by using protobuf.pb2 file

Installation

pip3 install protobuf2pydantic

Getting Started

in CLI

pb2py ../test_pb2.py > wow.py

in 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";

About

generate pydantic model by protobuf.pb2 file

License:MIT License


Languages

Language:Python 96.6%Language:Makefile 3.4%