Git Product home page Git Product logo

flask-with-protocol-buffer-serializer's Introduction

Flask-with-Protocol-Buffer-Serializer

Flask sample project to demonstrate working with protocol buffers in request and response.

Runs currently on python 2. To run it on Python 3, just change add parentheses of print statements in each file.

Study more about Protocol buffer here.

To get this example running, do these steps.

  1. First create a .proto file with the schema of your request/response classes. An example is given in the file addressbook.proto
  2. Now, when you have created the .proto file, you have to generate python classes/descriptors for each and everything in your .proto file. To help automate this, Google provides protoc compiler and can be downloaded with help of this blog as the documentation is not quite good.
  3. After installing the compiler, run the command protoc -I=. --python_out=. ./addressbook.proto. A file addressbook_pb2.py will be created.
  4. Now, you can use this file to serialise/deserialise your protobuf files. You can learn more about these files here.
  5. I have provided 2 files make_proto_file.py to generate a sample protobuf file (saved as a binary file) and read_display_proto_file.py to display the contents of the binary protobuf file on stdout.
  6. To run any of these files, provide a system argument as the name of binary file to be created. As example - python make_proto_file.py protofile1.pb.
  7. Now, you can run the Flask app by python flask_test.py.
  8. Use curl with the following command to test - curl -X POST -H "Accept: application/x-protobuf" -H "Content-type: application/x-protobuf" http://127.0.0.1:5000/load --data-binary @protofile1.pb > outputfile.pb. The contents of the file will be printed as a json object after deserialisation of the protobuf file.
  9. At last, you can check the output of outputfile.pb. In this case, it will be the same as we are uploading the same file, and returning the same.

Issues, contributions and additional examples are welcome.

flask-with-protocol-buffer-serializer's People

Contributors

dekan avatar keshav2904 avatar shreybatra avatar ssoto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

flask-with-protocol-buffer-serializer's Issues

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.