Python Library to generate protobuffers code from python using type hints
Project description
Protomodel
Python Library to generate proto buffer code from python using type hints
Example
Generate a file hello.py and add the following code:
from protomodel import message, service, rpc
@message
class HelloRequest:
name: str
@message
class HelloReply:
message: str
@service
class Greeter:
@rpc
def say_hello(hello_request: HelloRequest) -> HelloReply:
pass
Generate file
Run the following command to generate a proto buffer file
python -m protomodel generate --python_file=hello.py --proto_name=hello.proto
And then you will get the following result:
syntax = "proto3";
package app.proto;
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
Adding another types
@message
class Item:
id: int
name: str
description: str
price: float
enabled: bool
@message
class ItemsList:
items: list[Item]
Result:
message Item {
int32 id = 1;
string name = 2;
string description = 3;
double price = 4;
bool enabled = 5;
}
message ItemsList {
repeated Item items = 1;
}
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
protomodel-0.0.8.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for protomodel-0.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c331856d48c7b0f3046a0ab640e1b9f17fecc7928b3f1cdbb092f603efeb16c5 |
|
MD5 | acc37ec9983e924f146ba2d94098aff8 |
|
BLAKE2b-256 | cb8517a3a58e5ab678559cfe613cd4d76dcea84fd66aed43d35c77d06028eac9 |