Skip to content

Instantly share code, notes, and snippets.

@wilspi
Created January 22, 2018 12:43
Show Gist options
  • Save wilspi/806efd1f4f3579c7a00eb9aef2eda7f9 to your computer and use it in GitHub Desktop.
Save wilspi/806efd1f4f3579c7a00eb9aef2eda7f9 to your computer and use it in GitHub Desktop.
Generates client and server GRPC python code for all protos, given protos' directory. Read more here: https://grpc.io/docs/tutorials/basic/python.html#generating-client-and-server-code
#!/bin/bash
# Proto files directory
PROTOS_PATH="src/protos/"
# Directory in which auto generated code will be saved
AUTOGEN_GRPC_PATH="src/autogen_grp/"
# Generate python grpc code for each proto
# Requires grpcio-tools: pip install grpcio-tools
for file in "$PROTOS_PATH"*
do
if [[ $file =~ \.proto$ ]]
then
python -m grpc_tools.protoc -I $PROTOS_PATH --python_out=$AUTOGEN_GRPC_PATH --grpc_python_out=$AUTOGEN_GRPC_PATH "$file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment