Skip to main content

generate __init__.py files for protobuf projects

Project description

protobuf-init

To install:

pip install protobuf-init

This package will create __init__.py files when compiling *.proto files. Optionally, it will create relative imports from generated *_pb.py, *_pb_grpc.py, and *_grpc.py files from protobuf, grpcio, and grpclib packages, respectively.

Using the protos folder of this project as an example, the following command will generate the contents of the example package, also in this project (assuming grpcio-tools is installed):

export PROTO_PATH=./protos
export GEN_PATH=.
python -m grpc_tools.protoc \
    --python_out=$GEN_PATH \
    --mypy_out=$GEN_PATH \
    --init_python_out=$GEN_PATH \
    --init_python_opt=imports=protobuf+grpcio+grpclib \
    --grpc_python_out=$GEN_PATH \
    --grpclib_python_out=$GEN_PATH \
    --proto_path=$PROTO_PATH 
    $(find $PROTO_PATH -name '*.proto')

The --init_python_out=$GEN_PATH flag indicates to call the plugin to create the init files.

The --init_python_opt=imports=protobuf+grpcio+grpclib indicates which relative imports to include in the init files. Allowed options are protobuf, grpcio, grpclib, separated by +. (Note that both grpcio and grpclib generate <ServiceName>Stub objects which would collide in the init file.)

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

protobuf-init-0.3.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

protobuf_init-0.3.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file protobuf-init-0.3.0.tar.gz.

File metadata

  • Download URL: protobuf-init-0.3.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.15 CPython/3.8.2 Darwin/20.1.0

File hashes

Hashes for protobuf-init-0.3.0.tar.gz
Algorithm Hash digest
SHA256 742c6e5fde383fb5029147261edd66c41ce6d7939d36403ab76160b8f6ef5a34
MD5 25c25e882cd1826ab05d34dc6102e6e5
BLAKE2b-256 fdab970da5fd09b1002325db3c72acee25d22eefec47bec51f7434bac2b39758

See more details on using hashes here.

File details

Details for the file protobuf_init-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: protobuf_init-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.15 CPython/3.8.2 Darwin/20.1.0

File hashes

Hashes for protobuf_init-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c8aab0a0d070f8c82a4458958297141894e4fe60071118fe5b3b21e79a0cb13
MD5 9e157e7e473456b769771243378f7f2f
BLAKE2b-256 a9717dca8a064388366a996c8aad32e0d670257a16c34deb1381857dd049a0e8

See more details on using hashes here.

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