using gae-sessions with tipfy

49 views
Skip to first unread message

Calvin

unread,
Apr 5, 2011, 3:08:41 PM4/5/11
to ti...@googlegroups.com
I got accustomed to using gae-sessions (https://github.com/dound/gae-sessions) while I was building an App Engine app with webapp, so I wanted to continue using it when I switched to tipfy. Turns out to be pretty easy.

add this to your config.py:
import datetime
config['gaesessions'] = {'cookie_key': 'nunyabizniz', # use os.urandom(32).encode('hex') to generate a key
                         'lifetime': datetime.timedelta(hours=2), # however long you want your session to last
                         'cookie_only_threshold': 0} # increase this number if you want session data stored in the cookie (improves speed)

add this to your main.py 
from gaesessions import SessionMiddleware
 
def enable_gaesessions(app):
    if debug:
        app._debugged_wsgi_app = SessionMiddleware(app._debugged_wsgi_app, **config['gaesessions'])
    else:
        app.wsgi_app = SessionMiddleware(app.wsgi_app, **config['gaesessions']) 

# Instantiate the application.
app = App(rules=rules, config=config, debug=debug)
enable_gaesessions(app)
enable_appstats(app)
...

I've only tested this briefly since moving to 1.0b1, but it was working in 0.7, so should continue to work.  Let me know if there's a smarter way to do this.

Noah McIlraith

unread,
Apr 8, 2011, 4:53:53 AM4/8/11
to ti...@googlegroups.com
Out of interest, what is wrong with Tipfy's sessions? and what benefits does using gae-sessions have over tipfy's?

Calvin

unread,
Apr 8, 2011, 1:15:41 PM4/8/11
to ti...@googlegroups.com
I'm a "stick with the dame that brung ya" kind of guy.

Honestly, I haven't even tried out Tipfy's sessions.  My app started as all webapp + gae-sessions, then my app was half tipfy, half webapp, and I was sharing gae-sessions sessions between the halves.  Then I ripped out the webapp half, but kept gae-sessions.

Gae-sessions is supposed to be very fast, but I haven't done any benchmarking.


Calvin

unread,
May 7, 2011, 8:16:17 PM5/7/11
to ti...@googlegroups.com
Update: The previous enable_gaesessions only worked in debug.  This works in production with 1.0b1.

def enable_gaesessions(app):
    if debug:
        app._debugged_wsgi_app = SessionMiddleware(app._debugged_wsgi_app, **config['gaesessions'])
    else:
        app.dispatch = SessionMiddleware(app.dispatch, **config['gaesessions'])

Reply all
Reply to author
Forward
0 new messages