Skip to main content

Session extensions for Tornado

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(
            debug=True,
        )
        # sid_name, lifetime added in 1.1.5.0
        # sid_name: the name of session id in cookies.
        # lifetime: session default expires seconds.
        session_settings = dict(
            driver='memory',
            driver_settings={'host': self},
            force_persistence=True,
            sid_name='torndsessionID',
            session_lifetime=1800
        ),
        settings.update(session=session_settings)
        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']
        else:
            data = 0
        self.write('data=%s' % data)
        self.session["data"] = data + 1


def main():
    http_server = tornado.httpserver.HTTPServer(Application())
    http_server.listen(8000)
    tornado.ioloop.IOLoop.instance().start()


if __name__ == "__main__":
    main()

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

Installation

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+https://github.com/mitchellchu/torndsession

Manual installation:

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

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

The Torndsession source code is hosted on GitHub.

Updated

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.

Requires

LICENSE

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

tornaSession-1.1.5.2.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

tornaSession-1.1.5.2-py2-none-any.whl (13.1 kB view details)

Uploaded Python 2

File details

Details for the file tornaSession-1.1.5.2.tar.gz.

File metadata

  • Download URL: tornaSession-1.1.5.2.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.8

File hashes

Hashes for tornaSession-1.1.5.2.tar.gz
Algorithm Hash digest
SHA256 4c70e70891ba77de30dff6beb43fcd74341c09063a77fd616aef3c96e7dbf508
MD5 0cffab4ee427c01b37c1b12807ebcd85
BLAKE2b-256 e9872f9f891ecc8b8658e074d7b59e5cb5cccc4be2208f6b354cfb76748df357

See more details on using hashes here.

File details

Details for the file tornaSession-1.1.5.2-py2-none-any.whl.

File metadata

  • Download URL: tornaSession-1.1.5.2-py2-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.8

File hashes

Hashes for tornaSession-1.1.5.2-py2-none-any.whl
Algorithm Hash digest
SHA256 fdb0240cd7ca6426fae64a45c8250b6c8be02ab00bb156e1f4030844d8234201
MD5 9dbbe7cd106d1512ad29e2effe69edaf
BLAKE2b-256 7542b9a0423aa7e6b3e9680612ccbd7aec6cffab0aa8b9e07f0117629dc55d81

See more details on using hashes here.

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