Yet another tool that compiles .proto strings and import the outcome Python modules.
Project description
A tool that
- takes a
str
containing protobuf messages definitions - returns a
types.ModuleType
instance
It is useful for Python programs needing to parse protobuf messages without having to host .proto
files in their code base.
Installation
pip install proto-topy
Usage example
import sys, os
from pathlib import Path
from distutils.spawn import find_executable
from proto_topy.entities import ProtoModule
from google.protobuf.timestamp_pb2 import Timestamp
protoc_path = Path(find_executable("protoc") or os.environ.get('PROTOC'))
source = """
syntax = "proto3";
import "google/protobuf/timestamp.proto";
message Test5 {
google.protobuf.Timestamp created = 1;
}
"""
proto = ProtoModule(file_path=Path("test5.proto"), source=source).compiled(protoc_path)
sys.modules["test5"] = proto.py
assert isinstance(proto.py.Test5().created, Timestamp)
More examples in test_proto_topy.py.
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-topy-0.1.0.tar.gz
(12.5 kB
view hashes)
Built Distribution
Close
Hashes for proto_topy-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11d20e0c3eaaa7b47185ae4929a8b75cfb9f737937331807775a04ffe1225400 |
|
MD5 | 1f42f3310e2d415473de9459772c9f13 |
|
BLAKE2b-256 | ea6f426edf874d854e6ad8080e568797201b83818879e1749cc4c5229b8c1d01 |