Skip to main content

protobuf-gen

https://img.shields.io/pypi/v/protobuf-gen.svg https://img.shields.io/travis/andreycizov/python-protobuf-gen.svg Documentation Status Updates https://codecov.io/gh/andreycizov/python-protobuf-gen/coverage.svg?branch=master

Motivation

This is a library to generate type-hinted protocol buffer bindings. This tool solves two main issues with the original Google cproto compiler python output:

  • cproto does not support exporting the code with the package roots that are different from what had been supplied by the original .proto file authors, therefore expecting the protocol users to sed through the code (see issues 881 and 1491).

  • It builds the interfaces at run time, therefore disallowing one from using the static type checkers and disabling the auto-complete in your favourite IDE.

Example

This example is usable for building a fully-functional etcd3 client in python. Otherwise see tests.

Let’s start by cloning the repositories containing the necessary .proto files to be compiled. Etcd3 references files from several protobuf libraries, so we are going to need all of them.

mkdir pb-includes

# etcd references it's own .proto files against the root of their own repository, so the doubling here is intended
git clone https://github.com/coreos/etcd.git ./pb-includes/etcd/etcd

git clone https://github.com/grpc-ecosystem/grpc-gateway.git ./pb-includes/grpc-gateway
git clone https://github.com/gogo/protobuf.git ./pb-includes/protobuf

Now, let’s actually generate the files.

from protobuf_gen import remap, wrap

# all of the _pb2 modules will now be importable through `etcd3py.pb_mods.*`
# for example a module "google/api/http.proto" will be available as "etcd3py.pb_mods.google.api.http_pb2"
remap(
    # the working directory is given as the parent directory of the package folder (etcd3py in this case).
    '.',
    'etcd3py.pb_mods,
    # .proto include directories
    [
        './pb-includes/grpc-gateway/third_party/googleapis',
        './pb-includes/etcd',
        './pb-includes/protobuf',
    ],
    # .proto files to be included in the distribution
    [
        'etcd/etcdserver/etcdserverpb/rpc.proto',
        'etcd/mvcc/mvccpb/kv.proto',
        'etcd/auth/authpb/auth.proto',

        'google/api/annotations.proto',
        'gogoproto/gogo.proto',
        'google/api/http.proto',
    ]
)

Author

Andrey Cizov (acizov@gmail.com), 2018

Metadata

Release files for protobuf-gen 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for protobuf-gen 0.0.4
File Size Uploaded Provenance Actions
protobuf_gen-0.0.4.tar.gz 13.6 kB Without provenance Details for protobuf_gen-0.0.4.tar.gz

Release files / protobuf_gen-0.0.4.tar.gz

Download URL protobuf_gen-0.0.4.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b262634b883f146c9cf50bf6e3f9684eb7fc705817e4c3a3a7efb31b271f177a
BLAKE2b-256 checksum
How to use checksums
17fc06b0db2cd469663d4006466c740788d4a6b33bead9138463af543ef34cad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for protobuf-gen 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page