This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!
Project Description

Introduction

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://127.0.0.1:9090"

thriftclient = ThriftClient(MyService.Client, app)

@app.route("/")
def home():
    data = thriftclient.client.mymethod()
    return data

Transport

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

Example:

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

SSL

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

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

examples:

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_VALIDATE"] = False
app.config["THRIFTCLIENT_TRANSPORT"] = "https://127.0.0.1/"

#or

app.config["THRIFTCLIENT_SSL_CA_CERTS"] = "./cacert.pem"
app.config["THRIFTCLIENT_TRANSPORT"] = "https://127.0.0.1/"

Protocol

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

Connection

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 transport.open manually
  • you can use the autoconnect decorator
  • you can use the connect “with” context
app = Flask(__name__)
app.config["THRIFTCLIENT_TRANSPORT"] = "tcp://127.0.0.1:9090"
app.config["THRIFTCLIENT_ALWAYS_CONNECT"] = False

thriftclient = ThriftClient(MyService.Client, app)

@app.route("/with_autoconnect")
@thriftclient.autoconnect
def with_autoconnect():
    data = thriftclient.client.mymethod()
    return data

@app.route("/with_context")
def with_context():
    with thriftclient.connect():
        data = thriftclient.client.mymethod()
        return data

@app.route("/with_manual_connection")
def with_manual_connection():
    thriftclient.transport.open()
    data = thriftclient.client.mymethod()
    thriftclient.transport.close()
    return data

Options

Other options are:

THRIFTCLIENT_BUFFERED: use buffered transport (default False)

THRIFTCLIENT_ZLIB: use zlib compressed transport (default False)

Release History

Release History

0.2.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

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