Skip to content

Latest commit

 

History

History

bookstore-grpc-transcoding

Google Cloud Endpoints gRPC with Transcoding Bookstore in Python

Open in Cloud Shell

This example demonstrates how to implement a gRPC server with Google Cloud Endpoints and HTTP/JSON Transcoding.

Installing the dependencies using virtualenv:

virtualenv bookstore-env
source bookstore-env/bin/activate

Install all the Python dependencies:

pip install -r requirements.txt

Install the gRPC libraries and tools

Running the Server Locally

To run the server:

python bookstore_server.py

The -h command line flag shows the various settings available.

Running the Client Locally

To run the client:

python bookstore_client.py

As with the server, the -h command line flag shows the various settings available.

Generating a JWT token from a service account file

To run the script:

python jwt_token_gen.py --file=account_file --audiences=audiences --issuer=issuer

The output can be used as "--auth_token" for bookstore_client.py

Regenerating the Protocol Buffer and gRPC API stubs

The bookstore gRPC API is defined by bookstore.proto The API client stubs and server interfaces are generated by tools.

To make it easier to get something up and running, we've included the generated code in the sample distribution. To modify the sample or create your own gRPC API definition, you'll need to update the generated code. To do this, once the gRPC libraries and tools are installed, run:

GOOGLEAPIS=/path/to/googleapis
git clone https://github.com/googleapis/googleapis $GOOGLEAPIS

python -m grpc.tools.protoc \
    --include_imports \
    --include_source_info \
    --proto_path=. \
    --proto_path=$GOOGLEAPIS \
    --python_out=. \
    --grpc_python_out=. \
    --descriptor_set_out=api_descriptor.pb \
    bookstore.proto