Giter Site home page Giter Site logo

grpc-gateway-python-example's Introduction

Sample project to showcase Python gRPC <-> HTTP REST transcoding with grpc-gateway

This project implements a simple Python gRPC server for a bookstore. On top of that we have a proxy running which can transcode and expose all services defined in the .proto file as REST endpoints.

All REST endpoint details (path, parameters, descriptions etc.) are defined within the .proto file using common google API annotations.

Project Structure

proxy

This is a Go http proxy which can transcode HTTP/HTTPS REST into gRPC calls for you. It uses grpc-gateway behind the scenes.

The Go server also serves a Swagger API Web UI where your endpoints are documented. Access it via localhost:8081.

You will need to have Go installed on your system via the official website.

How to run the proxy:

go run cmd/app/main.go

Once running, you will be able to access your gRPC api with the proxy using simple HTT requests. For example: curl localhost:8081/api/v1/shelves

server

This is the actual python server implementation of the gRPC server. First install all dependencies with: pip3 install -r requirements.txt

How to run the server:

python3 bookstore_server.py

How to run a simple python grpc client:

There is also a simple python grpc client in order to test your implementation. Run it with: python3 bookstore_client.py and you'll get a grpc response back.

third_party

Contains a few third party proto files which are used as imports to define the API endpoint details. You can just copy these over, or alternatively checkout the googleapis repo in its entirety as a submodule. Copying these over like this just keeps it simple and small. We only need these few files.

Proto files generation

The proto files are already generated and added to this repo for convenience. If you make changes to them you'll have to regenerate them. Generating the proto files is done in the Makefile: Just run: make from the root of the repo. (Keep in mind that you might need to install some dependencies like protoc and maybe some others).

grpc-gateway-python-example's People

Contributors

angelkjos avatar

Stargazers

Afure Oyibo avatar Arthur Böök avatar  avatar  avatar banshan avatar Devis Ateka avatar Daeha Kim avatar  avatar carmanzhang avatar Jiri Puc avatar Fredrik Averpil avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.