Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Adds thrift client support to your Flask application

Project Description


This extension provide a simple intergration with Thrift RPC server.

from flask import Flask
from flask_thriftclient import ThriftClient

from MyGeneratedThriftCode import MyService

app = Flask(__name__)
app.config["THRIFTCLIENT_TRANSPORT"] = "tcp://"

thriftclient = ThriftClient(MyService.Client, app)

def home():
    data = thriftclient.client.mymethod()
    return data


Thrift endpoints are defined in the configuration variable THRIFTCLIENT_TRANSPORT as an URL. The default transport is tcp://localhost:9090

Available url schemes are:

tcp: use TCP socket as transport, you have to define the server address and port. If the port isn’t defined, 9090 will be used


http: use HTTP protocol as transport. Examples:

unix: use unix sockets as transport, as this scheme follow URI format, it MUST have either no or three “/” before the socket path

  • unix:///tmp/mysocket #absolute path
  • unix:/tmp/mysocket #absolute path
  • unix:./mysocket #relative path


You may set SSL version of transport communications by using ‘s’ version of url scheme:

tcp <=> tcps http <=> https unix <=> unixs


Two options are related to SSL transport:

THRIFTCLIENT_SSL_VALIDATE: True if the certificate has to be validated (default True)

THRIFTCLIENT_SSL_CA_CERTS: path to the SSL certificate (default None)

Note that you MUST set one of theses options:



app.config["THRIFTCLIENT_SSL_CA_CERTS"] = "./cacert.pem"


You may define which procotol must be use by setting the parametter THRIFTCLIENT_PROTOCOL. The default protocol is Binary.

Available parametters are:

ThriftClient.BINARY or “BINARY” : use the binary protocol

ThriftClient.COMPACT or “COMPACT” : use the compact protocol

ThriftClient.JSON or “JSON” : use the JSON protocol. note that this protocol is only available for thrift >= 0.9.1


By default the application will open then close the transport for each request This can be overriden by setting THRIFTCLIENT_ALWAYS_CONNECT to False

when THRIFTCLIENT_ALWAYS_CONNECT is set to False there is 3 ways to handle your connections:

  • you can call transport.close and manually
  • you can use the autoconnect decorator
  • you can use the connect “with” context
app = Flask(__name__)
app.config["THRIFTCLIENT_TRANSPORT"] = "tcp://"

thriftclient = ThriftClient(MyService.Client, app)

def with_autoconnect():
    data = thriftclient.client.mymethod()
    return data

def with_context():
    with thriftclient.connect():
        data = thriftclient.client.mymethod()
        return data

def with_manual_connection():
    data = thriftclient.client.mymethod()
    return data


Other options are:

THRIFTCLIENT_BUFFERED: use buffered transport (default False)

THRIFTCLIENT_ZLIB: use zlib compressed transport (default False)

Release History

Release History

This version
History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
Flask-ThriftClient-0.2.0.tar.gz (5.7 kB) Copy SHA256 Checksum SHA256 Source Mar 3, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting