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.1.1.tar.gz (4.1 kB view hashes)

Uploaded source

Built Distribution

protobuf_init-0.1.1-py3-none-any.whl (4.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page