WSGISession provides an easy way to deal with sessions in any WSGI compilant application. This middleware is useful always you want to store user sessions of a user, understanding that this user will store the session id in a cookie. It’s up to you how to save and retrieve the session object.
In order to do so, we offer the middleware and the session object, but you need to provide the session factory object, whose role is to save and retrieve sessions from wherever they are. Here’s an example:
#!/usr/bin/env python
from wsgiref.simple_server import make_server from wsgisession import SessionMiddleware
- class ExampleFactory(object):
- def load(self, id=None):
session = Session() # whatever needed to retireve session object session.data = {‘dummy’: ‘key’} session.id = ‘123’ return session
- def save(self, session):
# save the session.data, possibly generating session.id return session.id
- def wrapped_app(environ, start_response):
session = environ.get(‘wsgisession’) session[‘counter’] = session.get(‘counter’, 0) + 1 start_response(‘200 OK’, [(‘Content-Type’, ‘text/html’)]) return ‘Visited %s timesn’ % session[‘counter’]
factory = ExampleFactory() app = SessionMiddleware(wrapped_app, factory)
- if __name__ == ‘__main__’:
httpd = make_server(‘localhost’, 8080, app) httpd.serve_forever()
Metadata
Release files for WSGISession 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| WSGISession-0.1.0.tar.gz | 3.0 kB | Details |
Release files / WSGISession-0.1.0.tar.gz
| Download URL | WSGISession-0.1.0.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f41df3abc2fb2d9ffe6dfcd48e264fad63a40041c94839802f5bc87ca2f22526
|
|
BLAKE2b-256 checksum How to use checksums |
ae13821c4e7c35f5f9c79c2d5398758445941ae22d6322a72a2cae3d6ec64f1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |