Simple Cookie-based Session for Sanic
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
examples
sanic_cookiesession
tests
.gitignore
.hgignore
.hgtags
AUTHORS
LICENSE
MANIFEST.in
Makefile
README.rst
requirements-dev.txt
requirements.txt
setup.cfg
setup.py
tox.ini

README.rst

Sanic-CookieSession - Simple Cookie-based Session for Sanic

Sanic-CookieSession implements a client side only, cookie-based session to be used with Sanic. Similar to the built-in session in Flask.

Warning

The session cookie is signed cryptographically to prevent modification, but the content is not encrypted, NEVER store information that need to be kept secret.

Quick Start

Installation

pip install Sanic-CookieSession

How to use it

from sanic import Sanic, response
import sanic_cookiesession

app = Sanic(__name__)
app.config['SESSION_COOKIE_SECRET_KEY'] = 'abcd'

sanic_cookiesession.setup(app)

@app.route('/')
def index(request):
    session = request['session']
    session.setdefault('c', 0)
    session['c'] += 1
    return response.text(session['c'])

if __name__ == '__main__':
    app.run(debug=True)

That's it.

For more details, please see documentation.

License

BSD New, see LICENSE for details.

Links