Skip to main content

Session extensions for Tornado,Support memory, file, redis or memcached to save session data.

Project description

Torndsession Session

Torndsession is a session extension for Tornado web framework. Torndsession support application memory, file, redis or memcached to save session data for request, and it’s easy to extend for developer.

Hello, Session

Here is a simple “Hello, Session” example web app for Tornado with Torndsession.:

import tornado.web
import tornado.httpserver
import tornado.ioloop
import torndsession

class Application(tornado.web.Application):
    def __init__(self):
        handlers = [
            (r"/", MainHandler),
        settings = dict(
        # sid_name, lifetime added in
        # sid_name: the name of session id in cookies.
        # lifetime: session default expires seconds.
        session_settings = dict(
            driver_settings={'host': self},
        tornado.web.Application.__init__(self, handlers, **settings)

class MainHandler(torndsession.sessionhandler.SessionBaseHandler):
    def get(self):
        self.write("Hello, Session.<br/>")
        if 'data' in self.session:
            data = self.session['data']
            data = 0
        self.write('data=%s' % data)
        self.session["data"] = data + 1

def main():
    http_server = tornado.httpserver.HTTPServer(Application())

if __name__ == "__main__":

In this example, Request handler obtain memory session feature, it just inherit from SessionBaseHandler. more session example see torndsession demos.


Automatic installation:

pip install torndsession

Torndsession is listed in PyPI and can be installed with pip or easy_install. Note that this installation can not install demos applicatinos which be included in source code.

The another way is use git+ install torndsession from github.

pip install git+

Manual installation:

In this way, you need download the source from PyPI.:

tar xvzf torndsession.tar.gz
cd torndsession
python build
sudo python install

The Torndsession source code is hosted on GitHub.


Torndsession 1.1.5:

  • fixed bug in 1.1.4

  • default session id value generator changed. see #ISSUE 12#.

  • added two custom key in settings.

    • sid_name: session’s cookie name.

    • session_lifetime: default expired seconds for session.

Torndsession 1.1.4:

  • fixed bug

Torndsession 1.1.3 fixed some bug and supported python 3.x.



Torndsession is licensed under MIT.

Project details

Download files

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

Source Distribution (16.9 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page