Skip to content

Instantly share code, notes, and snippets.

@swrichards
Forked from beanyoung/flask_thrift_server.py
Created July 15, 2014 10:25
Show Gist options
  • Save swrichards/adce3e48c0d596574323 to your computer and use it in GitHub Desktop.
Save swrichards/adce3e48c0d596574323 to your computer and use it in GitHub Desktop.
from flask import Flask, request, make_response
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
from thrift.transport import TTransport
from FooService import FooService
from foo_service_handler import FooServiceHandler
foo_handler = FooServiceHandler()
foo_processor = FooService.Processor(foo_handler)
foo_pfactory = TBinaryProtocol.TBinaryProtocolFactory()
foo_server = TServer.TServer(
foo_processor,
None, None, None,
foo_pfactory,
foo_pfactory)
app = Flask(__name__)
app.config.from_object('config')
@app.route('/', methods=['POST'])
def profile_service_api():
itrans = TTransport.TMemoryBuffer(request.data)
otrans = TTransport.TMemoryBuffer()
iprot = foo_server.inputProtocolFactory.getProtocol(itrans)
oprot = foo_server.outputProtocolFactory.getProtocol(otrans)
foo_server.processor.process(iprot, oprot)
return make_response(otrans.getvalue())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment