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 details)
Built Distribution
File details
Details for the file proto-topy-0.1.0.tar.gz
.
File metadata
- Download URL: proto-topy-0.1.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa1f1aef3981495c505f8faef7933835dddbc193f3d93b1eae92fc8aee7cccb4 |
|
MD5 | 6b41e71a89cb3e729271036eaf1167fe |
|
BLAKE2b-256 | 2a17daecbed08514cf6694c952035eaae145d496edfdfd1fb018cf30994b685c |
File details
Details for the file proto_topy-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: proto_topy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11d20e0c3eaaa7b47185ae4929a8b75cfb9f737937331807775a04ffe1225400 |
|
MD5 | 1f42f3310e2d415473de9459772c9f13 |
|
BLAKE2b-256 | ea6f426edf874d854e6ad8080e568797201b83818879e1749cc4c5229b8c1d01 |