Provides server-backed sessions for Sanic using Redis, Memcache and more.
Project description
sanic_session
sanic_session is an extension for sanic that integrates server-backed sessions with a Flask-like API.
sanic_session provides a number of session interfaces for you to store a client's session data. The interfaces available right now are:
- Redis
- Memcache
- In-Memory (suitable for testing and development environments)
Installation
Install with pip
:
pip install sanic_session
Documentation
Documentation is available at PythonHosted.
Example
A simple example uses the in-memory session interface.
from sanic import Sanic
from sanic.response import text
from sanic_session import Session, InMemorySessionInterface
app = Sanic()
session = Session(app, interface=InMemorySessionInterface())
@app.route("/")
async def index(request):
# interact with the session like a normal dict
if not request['session'].get('foo'):
request['session']['foo'] = 0
request['session']['foo'] += 1
return text(request['session']['foo'])
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, debug=True)
Examples of using redis and memcache backed sessions can be found in the documentation, under Using the Interfaces.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sanic_session-0.3.1.tar.gz
(6.8 kB
view hashes)
Built Distribution
Close
Hashes for sanic_session-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21dca6f1b529db08bf7bae1fe03aaf1aa746a1b453cb60634e633a8dbc14f651 |
|
MD5 | a1a8d61b56eebe548587fc577d466494 |
|
BLAKE2b-256 | 25235df60d3d1d21e4bf709139eae42454cf40fe631614af4efafb43022c08e4 |