Skip to main content

Yet another tool that compiles .proto strings and import the outcome Python modules.

Project description

test version wheel python version python implementation

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


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)

Uploaded Source

Built Distribution

proto_topy-0.1.0-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page